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/12/05 13:30:54 UTC
[01/52] Initial EdmAnnotation contribution
Updated Branches:
refs/heads/master d51297ff9 -> 12ea18aed
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ae7c1f52/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/processor/json/JsonConsumerTest.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/processor/json/JsonConsumerTest.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/processor/json/JsonConsumerTest.java
new file mode 100644
index 0000000..c588b30
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/processor/json/JsonConsumerTest.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright 2013 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * 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.core.annotation.processor.json;
+
+import org.apache.olingo.odata2.core.annotation.processor.json.JsonConsumer;
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.io.UnsupportedEncodingException;
+import java.util.Map;
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ *
+ */
+public class JsonConsumerTest {
+
+ public static final String SIMPLE_TEAM = "{\"d\":{"
+ + "\"__metadata\":{\"id\":\"https://localhost/Test.svc/Teams('1')\","
+ + "\"uri\":\"https://localhost/Test.svc/Teams('1')\","
+ + "\"type\":\"Test.Team\""
+ + "},"
+ + "\"Id\":\"1\","
+ + "\"Name\":\"Team 1\","
+ + "\"isScrumTeam\":false}}";
+
+ public static final String SIMPLER_TEAM = "{"
+ + "\"d\":{"
+ + "\"Id\":\"1\",\"Name\":\"Team 1\",\"isScrumTeam\":false"
+ + "}}";
+
+ @Test
+ public void simplerRead() throws Exception {
+ InputStream content = encapsulate(SIMPLER_TEAM);
+ JsonConsumer jc = new JsonConsumer(content);
+ Map<String, String> name2Values = jc.read();
+
+// System.out.println("" + name2Values);
+ Assert.assertEquals(3, name2Values.size());
+
+ Assert.assertEquals("1", name2Values.get("Id"));
+ Assert.assertEquals("Team 1", name2Values.get("Name"));
+ Assert.assertEquals("false", name2Values.get("isScrumTeam"));
+ }
+
+ @Test
+ public void simpleRead() throws Exception {
+ InputStream content = encapsulate(SIMPLE_TEAM);
+ JsonConsumer jc = new JsonConsumer(content);
+ Map<String, String> name2Values = jc.read();
+
+// System.out.println("" + name2Values);
+ Assert.assertEquals(6, name2Values.size());
+
+ Assert.assertEquals("1", name2Values.get("Id"));
+ Assert.assertEquals("Team 1", name2Values.get("Name"));
+ Assert.assertEquals("false", name2Values.get("isScrumTeam"));
+
+ Assert.assertEquals("https://localhost/Test.svc/Teams('1')", name2Values.get("md_id"));
+ Assert.assertEquals("https://localhost/Test.svc/Teams('1')", name2Values.get("md_uri"));
+ Assert.assertEquals("Test.Team", name2Values.get("md_type"));
+ }
+
+ public static InputStream encapsulate(final String content) {
+ try {
+ return new ByteArrayInputStream(content.getBytes("UTF-8"));
+ } catch (UnsupportedEncodingException e) {
+ // we know that UTF-8 is supported
+ throw new RuntimeException("UTF-8 MUST be supported.", e);
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ae7c1f52/odata2-edm-annotation/edm-annotation-webref/pom.xml
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/pom.xml b/odata2-edm-annotation/edm-annotation-webref/pom.xml
new file mode 100644
index 0000000..89ae0b4
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-webref/pom.xml
@@ -0,0 +1,125 @@
+<?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-edm-annotation-webref-incubating</artifactId>
+ <packaging>war</packaging>
+ <name>${project.artifactId}</name>
+
+ <parent>
+ <groupId>org.apache.olingo</groupId>
+ <artifactId>olingo-odata2-edm-annotation-incubating</artifactId>
+ <version>1.1.0-SNAPSHOT</version>
+ <relativePath>..</relativePath>
+ </parent>
+
+ <build>
+ <finalName>${project.artifactId}</finalName>
+ <resources>
+ <resource>
+ <directory>src/main/version</directory>
+ <filtering>true</filtering>
+ <targetPath>../${project.build.finalName}/gen</targetPath>
+ </resource>
+ <resource>
+ <directory>src/main/resources</directory>
+ <filtering>true</filtering>
+ </resource>
+ <resource>
+ <directory>target/maven-shared-archive-resources</directory>
+ </resource>
+ </resources>
+
+ <plugins>
+ <plugin>
+ <groupId>com.sap.research</groupId>
+ <artifactId>nwcloud-maven-plugin</artifactId>
+ <version>1.0.0.RELEASE</version>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-deploy-plugin</artifactId>
+ <configuration>
+ <skip>true</skip>
+ </configuration>
+ </plugin>
+ </plugins>
+
+ </build>
+
+ <dependencies>
+ <dependency>
+ <!-- required because of auto detection of web facet 2.5 -->
+ <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>${cxf.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.olingo</groupId>
+ <artifactId>olingo-odata2-api-incubating</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.olingo</groupId>
+ <artifactId>olingo-odata2-core-incubating</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.olingo</groupId>
+ <artifactId>olingo-odata2-edm-annotation-api-incubating</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.olingo</groupId>
+ <artifactId>olingo-odata2-edm-annotation-core-incubating</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <version>1.7.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet</artifactId>
+ <version>2.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.core</groupId>
+ <artifactId>jersey-client</artifactId>
+ <version>2.0</version>
+ </dependency>
+ </dependencies>
+
+ <profiles>
+ <profile>
+ <id>dev</id>
+
+ <build>
+ <defaultGoal>cargo:run</defaultGoal>
+
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.cargo</groupId>
+ <artifactId>cargo-maven2-plugin</artifactId>
+ <version>1.4.2</version>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ae7c1f52/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Building.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Building.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Building.java
new file mode 100644
index 0000000..4035b24
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Building.java
@@ -0,0 +1,99 @@
+/*******************************************************************************
+ * 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.ref.annotation.model;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
+import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
+import org.apache.olingo.odata2.api.annotation.edm.NavigationEnd;
+import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
+import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
+
+/**
+ *
+ */
+@EdmEntityType(name="Building", namespace=ModelSharedConstants.NAMESPACE_1)
+@EdmEntitySet(name="Buildings", container="Container1")
+public class Building {
+ @EdmKey
+ @EdmProperty(type = EdmSimpleTypeKind.String)
+ private int id;
+ @EdmProperty
+ private String name;
+ private byte[] image;
+ @EdmNavigationProperty(name="nb_rooms", relationship="BuildingRooms",
+ to = @NavigationEnd(role = "r_Room", type="Room", multiplicity = EdmMultiplicity.MANY))
+ private List<Room> rooms = new ArrayList<Room>();
+
+ public Building() { }
+
+ public Building(final int id, final String name) {
+ this.id = id;
+ setName(name);
+ }
+
+ public String getId() {
+ return Integer.toString(id);
+ }
+
+ public void setName(final String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setImage(final byte[] byteArray) {
+ image = byteArray;
+ }
+
+ public byte[] getImage() {
+ if (image == null) {
+ return null;
+ } else {
+ return image.clone();
+ }
+ }
+
+ public List<Room> getRooms() {
+ return rooms;
+ }
+
+ @Override
+ public int hashCode() {
+ return id;
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ return this == obj
+ || obj != null && getClass() == obj.getClass() && id == ((Building) obj).id;
+ }
+
+ @Override
+ public String toString() {
+ return "{\"Id\":\"" + id + "\",\"Name\":\"" + name + "\",\"Image\":\"" + Arrays.toString(image) + "\"}";
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ae7c1f52/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/City.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/City.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/City.java
new file mode 100644
index 0000000..40e030f
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/City.java
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ ******************************************************************************/
+package org.apache.olingo.odata2.ref.annotation.model;
+
+import org.apache.olingo.odata2.api.annotation.edm.EdmComplexEntity;
+import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
+
+/**
+ *
+ */
+@EdmComplexEntity(name="c_City", namespace = ModelSharedConstants.NAMESPACE_1)
+public class City {
+
+ @EdmProperty
+ private String postalCode;
+ @EdmProperty
+ private String cityName;
+
+ public City(final String postalCode, final String name) {
+ this.postalCode = postalCode;
+ cityName = name;
+ }
+
+ public void setPostalCode(final String postalCode) {
+ this.postalCode = postalCode;
+ }
+
+ public String getPostalCode() {
+ return postalCode;
+ }
+
+ public void setCityName(final String cityName) {
+ this.cityName = cityName;
+ }
+
+ public String getCityName() {
+ return cityName;
+ }
+
+ @Override
+ public String toString() {
+ return String.format("%s, %s", cityName, postalCode);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ae7c1f52/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/DataContainer.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/DataContainer.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/DataContainer.java
new file mode 100644
index 0000000..d9974e1
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/DataContainer.java
@@ -0,0 +1,290 @@
+/*******************************************************************************
+ * 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.ref.annotation.model;
+
+import org.apache.olingo.odata2.ref.annotation.model.Building;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.List;
+import java.util.TimeZone;
+
+/**
+ * Container and initialization code for the data objects of the reference scenario.
+ *
+ */
+public class DataContainer {
+
+ private static final String IMAGE_JPEG = "image/jpeg";
+
+ private List<Employee> employees = new ArrayList<Employee>();
+ private List<Team> teams = new ArrayList<Team>();
+ private List<Room> rooms = new ArrayList<Room>();
+ private List<Manager> managers = new ArrayList<Manager>();
+ private List<Building> buildings = new ArrayList<Building>();
+ private List<Photo> photos = new ArrayList<Photo>();
+ private int employeeId = 0;
+ private int teamId = 0;
+ private int roomId = 0;
+ private int buildingId = 0;
+ private int photoId = 0;
+
+ public void init() {
+ // ------------- Teams ---------------
+ Team team1 = createTeam();
+ team1.setScrumTeam(false);
+ teams.add(team1);
+
+ Team team2 = createTeam();
+ team2.setScrumTeam(true);
+ teams.add(team2);
+
+ Team team3 = createTeam();
+ team3.setScrumTeam(false);
+ teams.add(team3);
+
+ // ------------- Buildings ---------------
+ Building building1 = createBuilding();
+ buildings.add(building1);
+
+ Building building2 = createBuilding();
+ buildings.add(building2);
+
+ Building building3 = createBuilding();
+ buildings.add(building3);
+
+ // ------------- Rooms ---------------
+ Room room1 = createRoom();
+ room1.setSeats(1);
+ room1.setBuilding(building1);
+ building1.getRooms().add(room1);
+ room1.setVersion(1);
+ rooms.add(room1);
+
+ Room room2 = createRoom();
+ room2.setSeats(5);
+ room2.setBuilding(building2);
+ building2.getRooms().add(room2);
+ room2.setVersion(2);
+ rooms.add(room2);
+
+ Room room3 = createRoom();
+ room3.setSeats(2);
+ room3.setBuilding(building2);
+ building2.getRooms().add(room3);
+ room3.setVersion(3);
+ rooms.add(room3);
+
+ for (int i = 4; i <= 103; i++) {
+ Room roomN = createRoom();
+ roomN.setSeats(4 + (i - 3) % 5);
+ roomN.setBuilding(building3);
+ building3.getRooms().add(roomN);
+ roomN.setVersion(1);
+ rooms.add(roomN);
+ }
+
+ // ------------- Employees and Managers ------------
+ Manager emp1 = createManager();
+ emp1.setEmployeeName("Walter Winter");
+ emp1.setAge(52);
+ emp1.setTeam(team1);
+ team1.getEmployees().add(emp1);
+ emp1.setRoom(room1);
+ room1.getEmployees().add(emp1);
+ emp1.setManager(emp1);
+ emp1.getEmployees().add(emp1);
+ emp1.setLocation(new Location("Germany", "69124", "Heidelberg"));
+ emp1.setEntryDate(generateDate(1999, 1, 1));
+ emp1.setImageUri("Employees('1')/$value");
+ emp1.setImage("/male_1_WinterW.jpg");
+ emp1.setImageType(IMAGE_JPEG);
+ employees.add(emp1);
+ managers.add(emp1);
+
+ Employee emp2 = createEmployee();
+ emp2.setEmployeeName("Frederic Fall");
+ emp2.setAge(32);
+ emp2.setTeam(team1);
+ team1.getEmployees().add(emp2);
+ emp2.setRoom(room2);
+ room2.getEmployees().add(emp2);
+ emp2.setManager(emp1);
+ emp1.getEmployees().add(emp2);
+ emp2.setLocation(new Location("Germany", "69190", "Walldorf"));
+ emp2.setEntryDate(generateDate(2003, 7, 1));
+ emp2.setImageUri("Employees('2')/$value");
+ emp2.setImage("/male_2_FallF.jpg");
+ emp2.setImageType(IMAGE_JPEG);
+ employees.add(emp2);
+
+ Manager emp3 = createManager();
+ emp3.setEmployeeName("Jonathan Smith");
+ emp3.setAge(56);
+ emp3.setTeam(team1);
+ team1.getEmployees().add(emp3);
+ emp3.setRoom(room2);
+ room2.getEmployees().add(emp3);
+ emp3.setManager(emp1);
+ emp1.getEmployees().add(emp3);
+ emp3.setLocation(emp2.getLocation());
+ emp3.setEntryDate(null);
+ emp3.setImageUri("Employees('3')/$value");
+ emp3.setImage("/male_3_SmithJo.jpg");
+ emp3.setImageType(IMAGE_JPEG);
+ employees.add(emp3);
+ managers.add(emp3);
+
+ Employee emp4 = createEmployee();
+ emp4.setEmployeeName("Peter Burke");
+ emp4.setAge(39);
+ emp4.setTeam(team2);
+ team2.getEmployees().add(emp4);
+ emp4.setRoom(room2);
+ room2.getEmployees().add(emp4);
+ emp4.setManager(emp3);
+ emp3.getEmployees().add(emp4);
+ emp4.setLocation(emp2.getLocation());
+ emp4.setEntryDate(generateDate(2004, 9, 12));
+ emp4.setImageUri("Employees('4')/$value");
+ emp4.setImage("/male_4_BurkeP.jpg");
+ emp4.setImageType(IMAGE_JPEG);
+ employees.add(emp4);
+
+ Employee emp5 = createEmployee();
+ emp5.setEmployeeName("John Field");
+ emp5.setAge(42);
+ emp5.setTeam(team2);
+ team2.getEmployees().add(emp5);
+ emp5.setRoom(room3);
+ room3.getEmployees().add(emp5);
+ emp5.setManager(emp3);
+ emp3.getEmployees().add(emp5);
+ emp5.setLocation(emp2.getLocation());
+ emp5.setEntryDate(generateDate(2001, 2, 1));
+ emp5.setImageUri("Employees('5')/$value");
+ emp5.setImage("/male_5_FieldJ.jpg");
+ emp5.setImageType(IMAGE_JPEG);
+ employees.add(emp5);
+
+ Employee emp6 = createEmployee();
+ emp6.setEmployeeName("Susan Bay");
+ emp6.setAge(29);
+ emp6.setTeam(team3);
+ team3.getEmployees().add(emp6);
+ emp6.setRoom(room2);
+ room2.getEmployees().add(emp6);
+ emp6.setManager(emp1);
+ emp1.getEmployees().add(emp6);
+ emp6.setLocation(emp2.getLocation());
+ emp6.setEntryDate(generateDate(2010, 12, 1));
+ emp6.setImageUri("Employees('6')/$value");
+ emp6.setImage("/female_6_BaySu.jpg");
+ emp6.setImageType(IMAGE_JPEG);
+ employees.add(emp6);
+
+ // ------------- Photos ---------------
+ Photo photo1 = createPhoto("image/png");
+ photo1.setContent("Образ");
+ photos.add(photo1);
+
+ Photo photo2 = createPhoto("image/bmp");
+ photos.add(photo2);
+
+ Photo photo3 = createPhoto(IMAGE_JPEG);
+ photos.add(photo3);
+
+ Photo photo4 = createPhoto("foo");
+ photo4.setContent("Продукт");
+ photos.add(photo4);
+ }
+
+ private Calendar generateDate(final int year, final int month, final int day) {
+ Calendar date = Calendar.getInstance();
+
+ date.clear();
+ date.setTimeZone(TimeZone.getTimeZone("GMT"));
+ date.set(year, month - 1, day); // month is zero-based!
+ return date;
+ }
+
+ public Employee createEmployee() {
+ return new Employee(++employeeId, "Employee " + employeeId);
+ }
+
+ public Team createTeam() {
+ return new Team(++teamId, "Team " + teamId);
+ }
+
+ public Room createRoom() {
+ return new Room(++roomId, "Room " + roomId);
+ }
+
+ public Manager createManager() {
+ return new Manager(++employeeId, "Employee " + employeeId);
+ }
+
+ public Building createBuilding() {
+ return new Building(++buildingId, "Building " + buildingId);
+ }
+
+ public Photo createPhoto(final String type) {
+ return new Photo(++photoId, "Photo " + photoId, type);
+ }
+
+ public List<Employee> getEmployees() {
+ return employees;
+ }
+
+ public List<Team> getTeams() {
+ return teams;
+ }
+
+ public List<Room> getRooms() {
+ return rooms;
+ }
+
+ public List<Manager> getManagers() {
+ return managers;
+ }
+
+ public List<Building> getBuildings() {
+ return buildings;
+ }
+
+ public List<Photo> getPhotos() {
+ return photos;
+ }
+
+ public void reset() {
+ employees.clear();
+ teams.clear();
+ rooms.clear();
+ managers.clear();
+ buildings.clear();
+ photos.clear();
+
+ employeeId = 0;
+ teamId = 0;
+ roomId = 0;
+ buildingId = 0;
+ photoId = 0;
+
+ init();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ae7c1f52/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Employee.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Employee.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Employee.java
new file mode 100644
index 0000000..0ef9e3b
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Employee.java
@@ -0,0 +1,189 @@
+/*******************************************************************************
+ * 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.ref.annotation.model;
+
+import java.text.DateFormat;
+import java.util.Calendar;
+import org.apache.olingo.odata2.api.annotation.edm.EdmComplexProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
+import org.apache.olingo.odata2.api.annotation.edm.NavigationEnd;
+import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
+import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
+
+/**
+ *
+ */
+@EdmEntityType(name="Employee", namespace=ModelSharedConstants.NAMESPACE_1)
+@EdmEntitySet(name="Employees", container=ModelSharedConstants.CONTAINER_1)
+public class Employee {
+ private static int counter = 1;
+ @EdmProperty(name="EmployeeId", type = EdmSimpleTypeKind.Int32)
+ @EdmKey
+ private int employeeId;
+ @EdmProperty(name="EmployeeName")
+ private String employeeName;
+ @EdmProperty
+ private int age;
+ @EdmNavigationProperty(name="ne_Manager", relationship="ManagerEmployees",
+ from = @NavigationEnd(role="r_Employees", multiplicity = EdmMultiplicity.MANY))//,
+// to = @NavigationEnd(type = "Manager"))
+ private Manager manager;
+ private Team team;
+ private Room room;
+ private String imageType;
+ private byte[] image;
+ private String imageUrl;
+ private Calendar entryDate;
+ @EdmComplexProperty(name="Location")
+ private Location location;
+
+ public Employee(final int employeeId, final String name) {
+ this.employeeId = employeeId;
+ setEmployeeName(name);
+ }
+
+ public String getId() {
+ return Integer.toString(employeeId);
+ }
+
+ public void setEmployeeName(final String employeeName) {
+ this.employeeName = employeeName;
+ }
+
+ public String getEmployeeName() {
+ return employeeName;
+ }
+
+ public void setAge(final int age) {
+ this.age = age;
+ }
+
+ public int getAge() {
+ return age;
+ }
+
+ public void setManager(final Manager manager) {
+ this.manager = manager;
+ }
+
+ public Manager getManager() {
+ return manager;
+ }
+
+ public void setTeam(final Team team) {
+ this.team = team;
+ }
+
+ public Team getTeam() {
+ return team;
+ }
+
+ public void setRoom(final Room room) {
+ this.room = room;
+ }
+
+ public Room getRoom() {
+ return room;
+ }
+
+ public void setImageUri(final String imageUri) {
+ imageUrl = imageUri;
+ }
+
+ public String getImageUri() {
+ return imageUrl;
+ }
+
+ public void setLocation(final Location location) {
+ this.location = location;
+ }
+
+ public Location getLocation() {
+ return location;
+ }
+
+ public void setEntryDate(final Calendar date) {
+ entryDate = date;
+ }
+
+ public Calendar getEntryDate() {
+ return entryDate;
+ }
+
+ public void setImageType(final String imageType) {
+ this.imageType = imageType;
+ }
+
+ public String getImageType() {
+ return imageType;
+ }
+
+ public void setImage(final byte[] image) {
+ this.image = image;
+ }
+
+ public void setImage(final String imageUrl) {
+ image = loadImage(imageUrl);
+ }
+
+ private static byte[] loadImage(final String imageUrl) {
+ return ResourceHelper.loadAsByte(imageUrl);
+ }
+
+ public byte[] getImage() {
+ if (image == null) {
+ return null;
+ }
+ return image.clone();
+ }
+
+ @Override
+ public int hashCode() {
+ return employeeId;
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ return this == obj
+ || obj != null && getClass() == obj.getClass() && employeeId == ((Employee) obj).employeeId;
+ }
+
+ @Override
+ public String toString() {
+ return "{\"EmployeeId\":\"" + employeeId + "\","
+ + "\"EmployeeName\":\"" + employeeName + "\","
+ + "\"ManagerId\":" + (manager == null ? "null" : "\"" + manager.getId() + "\"") + ","
+ + "\"RoomId\":" + (room == null ? "null" : "\"" + room.getId() + "\"") + ","
+ + "\"TeamId\":" + (team == null ? "null" : "\"" + team.getId() + "\"") + ","
+ + "\"Location\":"
+ + (location == null ? "null" :
+ "{\"City\":" + (location.getCity() == null ? "null" :
+ "{\"PostalCode\":\"" + location.getCity().getPostalCode() + "\","
+ + "\"CityName\":\"" + location.getCity().getCityName() + "\"}") + ","
+ + "\"Country\":\"" + location.getCountry() + "\"}") + ","
+ + "\"Age\":" + age + ","
+ + "\"EntryDate\":"
+ + (entryDate == null ? "null" : "\"" + DateFormat.getInstance().format(entryDate.getTime()) + "\"") + ","
+ + "\"ImageUrl\":\"" + imageUrl + "\"}";
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ae7c1f52/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Location.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Location.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Location.java
new file mode 100644
index 0000000..f63e8a4
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Location.java
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ ******************************************************************************/
+package org.apache.olingo.odata2.ref.annotation.model;
+
+import org.apache.olingo.odata2.api.annotation.edm.EdmComplexEntity;
+import org.apache.olingo.odata2.api.annotation.edm.EdmComplexProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
+
+/**
+ *
+ */
+@EdmComplexEntity(name = "c_Location", namespace = ModelSharedConstants.NAMESPACE_1)
+public class Location {
+ @EdmProperty
+ private String country;
+ @EdmComplexProperty
+ private City city;
+
+ public Location(final String country, final String postalCode, final String cityName) {
+ this.country = country;
+ city = new City(postalCode, cityName);
+ }
+
+ public void setCountry(final String country) {
+ this.country = country;
+ }
+
+ public String getCountry() {
+ return country;
+ }
+
+ public void setCity(final City city) {
+ this.city = city;
+ }
+
+ public City getCity() {
+ return city;
+ }
+
+ @Override
+ public String toString() {
+ return String.format("%s, %s", country, city.toString());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ae7c1f52/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Manager.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Manager.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Manager.java
new file mode 100644
index 0000000..521c43d
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Manager.java
@@ -0,0 +1,46 @@
+/*******************************************************************************
+ * 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.ref.annotation.model;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
+import org.apache.olingo.odata2.api.annotation.edm.NavigationEnd;
+
+/**
+ *
+ */
+@EdmEntityType(name = "Manager", namespace = ModelSharedConstants.NAMESPACE_1)
+@EdmEntitySet(name = "Managers", container = ModelSharedConstants.CONTAINER_1)
+public class Manager extends Employee {
+
+ @EdmNavigationProperty(name = "nm_Employees", relationship = "ManagerEmployees",
+ to = @NavigationEnd(role = "r_Employees", type = "Employee"))
+ private List<Employee> employees = new ArrayList<Employee>();
+
+ public Manager(final int id, final String name) {
+ super(id, name);
+ }
+
+ public List<Employee> getEmployees() {
+ return employees;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ae7c1f52/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ModelException.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ModelException.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ModelException.java
new file mode 100644
index 0000000..3b6d033
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ModelException.java
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * 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.ref.annotation.model;
+
+/**
+ *
+ */
+public class ModelException extends RuntimeException {
+
+ private static final long serialVersionUID = 1L;
+
+ public ModelException(final Exception e) {
+ super(e);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ae7c1f52/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ModelSharedConstants.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ModelSharedConstants.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ModelSharedConstants.java
new file mode 100644
index 0000000..ab17fbb
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ModelSharedConstants.java
@@ -0,0 +1,25 @@
+/*******************************************************************************
+ * 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.ref.annotation.model;
+
+public interface ModelSharedConstants {
+
+ String NAMESPACE_1 = "RefScenario";
+ String CONTAINER_1 = "Container1";
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ae7c1f52/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Photo.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Photo.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Photo.java
new file mode 100644
index 0000000..92d1ac6
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Photo.java
@@ -0,0 +1,131 @@
+/*******************************************************************************
+ * 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.ref.annotation.model;
+
+import java.util.Arrays;
+
+/**
+ *
+ */
+public class Photo {
+ private static final String RESOURCE = "/male_1_WinterW.jpg";
+ private static byte[] defaultImage = ResourceHelper.loadAsByte(RESOURCE);
+
+ private final int id;
+ private String name;
+ private String type = "image/jpeg";
+ private String imageUrl = "http://localhost" + RESOURCE;
+ private byte[] image = defaultImage;
+ private String imageType = type;
+ private byte[] binaryData;
+ private String content;
+
+ public Photo(final int id, final String name, final String type) {
+ this.id = id;
+ setName(name);
+ setType(type);
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(final String name) {
+ this.name = name;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(final String type) {
+ this.type = type;
+ }
+
+ public String getImageUri() {
+ return imageUrl;
+ }
+
+ public void setImageUri(final String uri) {
+ imageUrl = uri;
+ }
+
+ public byte[] getImage() {
+ return image.clone();
+ }
+
+ public void setImage(final byte[] image) {
+ this.image = image;
+ }
+
+ public String getImageType() {
+ return imageType;
+ }
+
+ public void setImageType(final String imageType) {
+ this.imageType = imageType;
+ }
+
+ public byte[] getBinaryData() {
+ if (binaryData == null) {
+ return null;
+ } else {
+ return binaryData.clone();
+ }
+ }
+
+ public void setBinaryData(final byte[] binaryData) {
+ this.binaryData = binaryData;
+ }
+
+ public void setContent(final String content) {
+ this.content = content;
+ }
+
+ public String getContent() {
+ return content;
+ }
+
+ @Override
+ public int hashCode() {
+ return id;
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ return this == obj
+ || obj != null && getClass() == obj.getClass() && id == ((Photo) obj).id;
+ }
+
+ @Override
+ public String toString() {
+ return "{\"Id\":" + id + ","
+ + "\"Name\":\"" + name + "\","
+ + "\"Type\":\"" + type + "\","
+ + "\"ImageUrl\":\"" + imageUrl + "\","
+ + "\"Image\":\"" + Arrays.toString(image) + "\","
+ + "\"ImageType\":\"" + imageType + "\","
+ + "\"Content:\"" + content + "\","
+ + "\"BinaryData\":\"" + Arrays.toString(binaryData) + "\"}";
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ae7c1f52/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/RefBase.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/RefBase.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/RefBase.java
new file mode 100644
index 0000000..82d9812
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/RefBase.java
@@ -0,0 +1,57 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ ******************************************************************************/
+package org.apache.olingo.odata2.ref.annotation.model;
+
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
+import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
+
+/**
+ *
+ */
+@EdmEntityType(name="Base", namespace=ModelSharedConstants.NAMESPACE_1)
+public abstract class RefBase {
+ @EdmProperty(name="Name")
+ protected String name;
+ @EdmProperty(name="Id", type = EdmSimpleTypeKind.String)
+ @EdmKey
+ protected int id;
+
+ public RefBase(int id, String name) {
+ this.name = name;
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getId() {
+ return Integer.toString(id);
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ae7c1f52/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ResourceHelper.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ResourceHelper.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ResourceHelper.java
new file mode 100644
index 0000000..adc5f11
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ResourceHelper.java
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ ******************************************************************************/
+package org.apache.olingo.odata2.ref.annotation.model;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ *
+ * @author d046871
+ */
+class ResourceHelper {
+
+ public static byte[] loadAsByte(String resource) {
+ return load(resource, new byte[0]);
+ }
+
+ public static byte[] load(String resource, byte[] defaultResult) {
+ InputStream instream = null;
+ try {
+ instream = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource);
+ if (instream == null) {
+ return defaultResult;
+ }
+ ByteArrayOutputStream stream = new ByteArrayOutputStream();
+ int b = 0;
+ while ((b = instream.read()) != -1) {
+ stream.write(b);
+ }
+
+ return stream.toByteArray();
+ } catch (IOException e) {
+ throw new ModelException(e);
+ } finally {
+ if(instream != null) {
+ try {
+ instream.close();
+ } catch (IOException ex) { }
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ae7c1f52/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Room.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Room.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Room.java
new file mode 100644
index 0000000..2feb5cd
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Room.java
@@ -0,0 +1,97 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ ******************************************************************************/
+package org.apache.olingo.odata2.ref.annotation.model;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
+import org.apache.olingo.odata2.api.annotation.edm.NavigationEnd;
+import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
+
+/**
+ *
+ */
+@EdmEntityType(name = "Room", namespace = ModelSharedConstants.NAMESPACE_1)
+@EdmEntitySet(name = "Rooms", container = ModelSharedConstants.CONTAINER_1)
+public class Room extends RefBase {
+
+ @EdmProperty
+ private Integer seats;
+ @EdmProperty
+ private Integer version;
+ @EdmNavigationProperty(name="nr_Building", relationship="BuildingRooms",
+ from = @NavigationEnd(role="r_Room", multiplicity = EdmMultiplicity.MANY))
+ private Building building;
+ @EdmNavigationProperty(name="nr_Employees", relationship="RoomEmployees",
+ from = @NavigationEnd(role = "r_Room", type = "Room", multiplicity = EdmMultiplicity.ONE),
+ to = @NavigationEnd(role = "r_Employees", type = "Employee", multiplicity = EdmMultiplicity.MANY))
+ private List<Employee> employees = new ArrayList<Employee>();
+
+ public Room(final int id, final String name) {
+ super(id, name);
+ }
+
+ public void setSeats(final int seats) {
+ this.seats = seats;
+ }
+
+ public int getSeats() {
+ return seats;
+ }
+
+ public void setVersion(final int version) {
+ this.version = version;
+ }
+
+ public int getVersion() {
+ return version;
+ }
+
+ public void setBuilding(final Building building) {
+ this.building = building;
+ }
+
+ public Building getBuilding() {
+ return building;
+ }
+
+ public List<Employee> getEmployees() {
+ return employees;
+ }
+
+ @Override
+ public int hashCode() {
+ return id;
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ return this == obj
+ || obj != null && getClass() == obj.getClass() && id == ((Room) obj).id;
+ }
+
+ @Override
+ public String toString() {
+ return "{\"Id\":\"" + id + "\",\"Name\":\"" + name + "\",\"Seats\":" + seats + ",\"Version\":" + version + "}";
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ae7c1f52/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Team.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Team.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Team.java
new file mode 100644
index 0000000..b805b77
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Team.java
@@ -0,0 +1,83 @@
+/*******************************************************************************
+ * 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.ref.annotation.model;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
+import org.apache.olingo.odata2.api.annotation.edm.NavigationEnd;
+import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
+import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
+
+/**
+*
+*/
+@EdmEntityType(name="Team", namespace = ModelSharedConstants.NAMESPACE_1)
+@EdmEntitySet(name="Teams", container = ModelSharedConstants.CONTAINER_1)
+public class Team extends RefBase {
+ @EdmProperty(type = EdmSimpleTypeKind.Boolean)
+ private Boolean isScrumTeam;
+ @EdmNavigationProperty(name = "ne_Teams", relationship="TeamEmployees",
+ from = @NavigationEnd(role = "r_Team", type = "Team"),
+ to = @NavigationEnd(role = "r_Employees", type = "Employee", multiplicity = EdmMultiplicity.MANY))
+ private List<Employee> employees = new ArrayList<Employee>();
+
+ public Team() {
+ super(-1, null);
+ }
+
+ public Team(final int id, final String name) {
+ super(id, name);
+ }
+
+ public Boolean isScrumTeam() {
+ return isScrumTeam;
+ }
+
+ public void setScrumTeam(final Boolean isScrumTeam) {
+ this.isScrumTeam = isScrumTeam;
+ }
+
+ public void addEmployee(Employee e) {
+ this.employees.add(e);
+ }
+
+ public List<Employee> getEmployees() {
+ return employees;
+ }
+
+ @Override
+ public int hashCode() {
+ return id;
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ return this == obj
+ || obj != null && getClass() == obj.getClass() && id == ((Team) obj).id;
+ }
+
+ @Override
+ public String toString() {
+ return "{\"Id\":\"" + id + "\",\"Name\":\"" + name + "\",\"IsScrumTeam\":" + isScrumTeam + "}";
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ae7c1f52/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ds/BuildingDs.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ds/BuildingDs.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ds/BuildingDs.java
new file mode 100644
index 0000000..282bb4f
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ds/BuildingDs.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2013 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * 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.ref.annotation.model.ds;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.olingo.odata2.api.annotation.edm.ds.EntityCreate;
+import org.apache.olingo.odata2.api.annotation.edm.ds.EntityDataSource;
+import org.apache.olingo.odata2.api.annotation.edm.ds.EntityDelete;
+import org.apache.olingo.odata2.api.annotation.edm.ds.EntityRead;
+import org.apache.olingo.odata2.api.annotation.edm.ds.EntitySetRead;
+import org.apache.olingo.odata2.api.annotation.edm.ds.EntityUpdate;
+import org.apache.olingo.odata2.ref.annotation.model.Building;
+
+/**
+ *
+ */
+@EntityDataSource(name="BuildingDataSource", entityType = Building.class)
+public class BuildingDs {
+
+ private static int idCounter = 1;
+ private final static Map<Integer, Building> id2Building = new HashMap<Integer, Building>();
+
+ @EntityRead
+ public Building read(String id) {
+ return id2Building.get(Integer.valueOf(id));
+ }
+
+ @EntitySetRead
+ public Collection<Building> read() {
+ return id2Building.values();
+ }
+
+ @EntityCreate
+ @EntityUpdate
+ public Building createOrUpdate(Building building) {
+ Building b = id2Building.get(Integer.valueOf(building.getId()));
+ if(b != null) {
+ b.setName(building.getName());
+ } else {
+ final int id = idCounter++;
+ b = new Building(id, building.getName());
+ id2Building.put(Integer.valueOf(id), b);
+ }
+ return b;
+ }
+
+ @EntityDelete
+ public Building delete(String id) {
+ return id2Building.remove(Integer.valueOf(id));
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ae7c1f52/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ds/TeamDs.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ds/TeamDs.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ds/TeamDs.java
new file mode 100644
index 0000000..9426c7b
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ds/TeamDs.java
@@ -0,0 +1,66 @@
+/*
+ * Copyright 2013 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * 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.ref.annotation.model.ds;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.olingo.odata2.api.annotation.edm.ds.EntityRead;
+import org.apache.olingo.odata2.api.annotation.edm.ds.EntityDataSource;
+import org.apache.olingo.odata2.api.annotation.edm.ds.EntityCreate;
+import org.apache.olingo.odata2.api.annotation.edm.ds.EntitySetRead;
+import org.apache.olingo.odata2.api.annotation.edm.ds.EntityUpdate;
+import org.apache.olingo.odata2.ref.annotation.model.Team;
+
+/**
+ *
+ */
+@EntityDataSource(name="TeamDataSource", entityType = Team.class)
+public class TeamDs {
+
+ private static int idCounter = 1;
+ private static final Map<Integer, Team> id2Team = new HashMap<Integer, Team>();
+
+ @EntityRead
+ public Team readTeam(String id) {
+ return id2Team.get(Integer.valueOf(id));
+ }
+
+ @EntitySetRead
+ public Collection<Team> readAllTeams() {
+ return id2Team.values();
+ }
+
+ @EntityCreate
+ public Team writeTeam(Team team) {
+ final int id = idCounter++;
+ team.setId(id);
+ id2Team.put(Integer.valueOf(id), team);
+
+ return team;
+ }
+
+ @EntityUpdate
+ public Team update(Team team) {
+ Team t = id2Team.get(Integer.valueOf(team.getId()));
+ if(t != null) {
+ t.setName(team.getName());
+ t.setScrumTeam(team.isScrumTeam());
+ }
+ return team;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ae7c1f52/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/processor/ScenarioErrorCallback.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/processor/ScenarioErrorCallback.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/processor/ScenarioErrorCallback.java
new file mode 100644
index 0000000..45a4f81
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/processor/ScenarioErrorCallback.java
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * 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.ref.annotation.processor;
+
+import org.apache.olingo.odata2.api.commons.HttpStatusCodes;
+import org.apache.olingo.odata2.api.ep.EntityProvider;
+import org.apache.olingo.odata2.api.exception.ODataApplicationException;
+import org.apache.olingo.odata2.api.processor.ODataErrorCallback;
+import org.apache.olingo.odata2.api.processor.ODataErrorContext;
+import org.apache.olingo.odata2.api.processor.ODataResponse;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Callback for handling errors by logging internal server errors additionally.
+ *
+ */
+public class ScenarioErrorCallback implements ODataErrorCallback {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ScenarioErrorCallback.class);
+
+ @Override
+ public ODataResponse handleError(final ODataErrorContext context) throws ODataApplicationException {
+ if (context.getHttpStatus() == HttpStatusCodes.INTERNAL_SERVER_ERROR) {
+ LOG.error("Internal Server Error", context.getException());
+ }
+
+ return EntityProvider.writeErrorDocument(context);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ae7c1f52/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/processor/ScenarioServiceFactory.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/processor/ScenarioServiceFactory.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/processor/ScenarioServiceFactory.java
new file mode 100644
index 0000000..7ff3ee4
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/processor/ScenarioServiceFactory.java
@@ -0,0 +1,97 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ ******************************************************************************/
+package org.apache.olingo.odata2.ref.annotation.processor;
+
+import org.apache.olingo.odata2.api.ODataCallback;
+import org.apache.olingo.odata2.api.ODataDebugCallback;
+import org.apache.olingo.odata2.api.ODataService;
+import org.apache.olingo.odata2.api.ODataServiceFactory;
+import org.apache.olingo.odata2.api.exception.ODataException;
+import org.apache.olingo.odata2.api.processor.ODataContext;
+import org.apache.olingo.odata2.core.annotation.edm.AnnotationEdmProvider;
+import org.apache.olingo.odata2.core.annotation.processor.AnnotationProcessor;
+import org.apache.olingo.odata2.ref.annotation.model.Building;
+import org.apache.olingo.odata2.ref.annotation.model.Team;
+import org.apache.olingo.odata2.ref.annotation.model.ds.BuildingDs;
+import org.apache.olingo.odata2.ref.annotation.model.ds.TeamDs;
+
+/**
+ *
+ */
+public class ScenarioServiceFactory extends ODataServiceFactory {
+
+ private static boolean isInitialized = false;
+
+ @Override
+ public ODataService createService(final ODataContext context) throws ODataException {
+ if(!isInitialized) {
+ initializeSampleData();
+ isInitialized = true;
+ }
+
+ return createODataSingleProcessorService(
+ new AnnotationEdmProvider("org.apache.olingo.odata2.ref.annotation.model"),
+ new AnnotationProcessor(context, "org.apache.olingo.odata2.ref.annotation.model"));
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public <T extends ODataCallback> T getCallback(final Class<? extends ODataCallback> callbackInterface) {
+ return (T) (callbackInterface.isAssignableFrom(ScenarioErrorCallback.class)
+ ? new ScenarioErrorCallback() : callbackInterface.isAssignableFrom(ODataDebugCallback.class)
+ ? new ScenarioDebugCallback() : super.getCallback(callbackInterface));
+ }
+
+
+ private final class ScenarioDebugCallback implements ODataDebugCallback {
+
+ @Override
+ public boolean isDebugEnabled() {
+ return true;
+ }
+ }
+
+
+ private void initializeSampleData() {
+ TeamDs teamDs = new TeamDs();
+ teamDs.writeTeam(createTeam("Team Alpha", true));
+ teamDs.writeTeam(createTeam("Team Beta", false));
+ teamDs.writeTeam(createTeam("Team Gamma", false));
+ teamDs.writeTeam(createTeam("Team Omega", true));
+ teamDs.writeTeam(createTeam("Team Zeta", true));
+
+ BuildingDs buildingsDs = new BuildingDs();
+ buildingsDs.createOrUpdate(createBuilding("Red Building"));
+ buildingsDs.createOrUpdate(createBuilding("Green Building"));
+ buildingsDs.createOrUpdate(createBuilding("Blue Building"));
+ }
+
+ private Team createTeam(String teamName, boolean isScrumTeam) {
+ Team team = new Team();
+ team.setName(teamName);
+ team.setScrumTeam(isScrumTeam);
+ return team;
+ }
+
+ private Building createBuilding(String buildingName) {
+ Building b = new Building();
+ b.setName(buildingName);
+ return b;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ae7c1f52/odata2-edm-annotation/edm-annotation-webref/src/main/resources/log4j.xml
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/resources/log4j.xml b/odata2-edm-annotation/edm-annotation-webref/src/main/resources/log4j.xml
new file mode 100644
index 0000000..90a4706
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/resources/log4j.xml
@@ -0,0 +1,39 @@
+<?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>
+
+ <logger name="org.apache.olingo.odata2.ref" additivity="false">
+ <level value="trace" />
+ <appender-ref ref="console" />
+ </logger>
+
+ <root>
+ <priority value="error" />
+ <appender-ref ref="console" />
+ </root>
+</log4j:configuration>
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ae7c1f52/odata2-edm-annotation/edm-annotation-webref/src/main/version/version.html
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/version/version.html b/odata2-edm-annotation/edm-annotation-webref/src/main/version/version.html
new file mode 100644
index 0000000..6d76d0b
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/version/version.html
@@ -0,0 +1,27 @@
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+
+-->
+
+<table border="1">
+<tr><td>name</td><td>${name}</td></tr>
+<tr><td>version</td><td>${version}</td></tr>
+<tr><td>timestamp</td><td>${timestamp}</td></tr>
+<tr><td>project.build.finalName</td><td>${project.build.finalName}</td></tr>
+</table>
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ae7c1f52/odata2-edm-annotation/edm-annotation-webref/src/main/webapp/META-INF/context.xml
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/webapp/META-INF/context.xml b/odata2-edm-annotation/edm-annotation-webref/src/main/webapp/META-INF/context.xml
new file mode 100644
index 0000000..1b76b24
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/webapp/META-INF/context.xml
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Context antiJARLocking="true" path="/olingo.odata2.edm.annotation.refweb"/>
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ae7c1f52/odata2-edm-annotation/edm-annotation-webref/src/main/webapp/WEB-INF/web.xml
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/webapp/WEB-INF/web.xml b/odata2-edm-annotation/edm-annotation-webref/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..1795259
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,48 @@
+<?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.ref.annotations.web</display-name>
+ <welcome-file-list>
+ <welcome-file>index.jsp</welcome-file>
+ </welcome-file-list>
+
+ <servlet>
+ <servlet-name>ReferenceScenarioServlet</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.ref.annotation.processor.ScenarioServiceFactory</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>ReferenceScenarioServlet</servlet-name>
+ <url-pattern>/ReferenceScenario.svc/*</url-pattern>
+ </servlet-mapping>
+
+</web-app>
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ae7c1f52/odata2-edm-annotation/edm-annotation-webref/src/main/webapp/index.jsp
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/webapp/index.jsp b/odata2-edm-annotation/edm-annotation-webref/src/main/webapp/index.jsp
new file mode 100644
index 0000000..3ffc551
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/webapp/index.jsp
@@ -0,0 +1,111 @@
+<%@ page language="java" contentType="text/html; UTF-8" pageEncoding="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 html>
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+<title>Apache Olingo - OData2 Library</title>
+<style type="text/css">
+body { font-family: Arial, sans-serif; font-size: 13px; line-height: 18px;
+ color: blue; background-color: #ffffff; }
+a { color: blue; text-decoration: none; }
+a:focus { outline: thin dotted #4076cb; outline-offset: -1px; }
+a:hover, a:active { outline: 0; }
+a:hover { color: #404a7e; text-decoration: underline; }
+h1, h2, h3, h4, h5, h6 { margin: 9px 0; font-family: inherit; font-weight: bold;
+ line-height: 1; color: blue; }
+h1 { font-size: 36px; line-height: 40px; }
+h2 { font-size: 30px; line-height: 40px; }
+h3 { font-size: 24px; line-height: 40px; }
+h4 { font-size: 18px; line-height: 20px; }
+h5 { font-size: 14px; line-height: 20px; }
+h6 { font-size: 12px; line-height: 20px; }
+.logo { float: right; }
+ul { padding: 0; margin: 0 0 9px 25px; }
+ul ul { margin-bottom: 0; }
+li { line-height: 18px; }
+hr { margin: 18px 0;
+ border: 0; border-top: 1px solid #cccccc; border-bottom: 1px solid #ffffff; }
+table { border-collapse: collapse; border-spacing: 10px; }
+th, td { border: 1px solid; padding: 20px; }
+.code { font-family: "Courier New", monospace; font-size: 13px; line-height: 18px; }
+</style>
+</head>
+<body>
+ <h1>Apache Olingo - OData2 Library</h1>
+ <hr />
+ <h2>Reference Scenario</h2>
+ <table>
+ <tr>
+ <td valign="top">
+ <h3>Service Document and Metadata</h3>
+ <ul>
+ <li><a href="ReferenceScenario.svc?_wadl" target="_blank">wadl</a></li>
+ <li><a href="ReferenceScenario.svc/" target="_blank">service
+ document</a></li>
+ <li><a href="ReferenceScenario.svc/$metadata" target="_blank">metadata</a></li>
+ </ul>
+ <h3>EntitySets</h3>
+ <ul>
+ <li><a href="ReferenceScenario.svc/Employees" target="_blank">Employees</a></li>
+ <li><a href="ReferenceScenario.svc/Managers" target="_blank">Managers</a></li>
+ <li><a href="ReferenceScenario.svc/Buildings" target="_blank">Buildings</a></li>
+ <li><a href="ReferenceScenario.svc/Rooms" target="_blank">Rooms</a></li>
+ <li><a href="ReferenceScenario.svc/Container2.Photos"
+ target="_blank">Container2.Photos</a></li>
+ </ul>
+ <h3>Entities</h3>
+ <ul>
+ <li><a href="ReferenceScenario.svc/Employees('1')"
+ target="_blank">Employees('1')</a></li>
+ <li><a href="ReferenceScenario.svc/Managers('1')"
+ target="_blank">Managers('1')</a></li>
+ <li><a href="ReferenceScenario.svc/Buildings('1')"
+ target="_blank">Buildings('1')</a></li>
+ <li><a href="ReferenceScenario.svc/Rooms('1')" target="_blank">Rooms('1')</a></li>
+ <li><a href="ReferenceScenario.svc/Container2.Photos(Id=4,Type='foo')"
+ target="_blank">Container2.Photos(Id=4,Type='foo')</a></li>
+ </ul>
+ </td>
+ <td valign="top">
+
+ </td>
+ <td valign="bottom">
+ <div class="code">
+ <%
+ String version = "gen/version.html";
+ %>
+ <%
+ try {
+ %>
+ <jsp:include page='<%=version%>' />
+ <%
+ } catch (Exception e) {
+ %>
+ <p>IDE Build</p>
+ <%
+ }
+ %>
+ </div>
+ </td>
+ </tr>
+ </table>
+</body>
+</html>
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ae7c1f52/odata2-edm-annotation/pom.xml
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/pom.xml b/odata2-edm-annotation/pom.xml
new file mode 100644
index 0000000..436576f
--- /dev/null
+++ b/odata2-edm-annotation/pom.xml
@@ -0,0 +1,30 @@
+<?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-edm-annotation-incubating</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>edm-annotation-api</module>
+ <module>edm-annotation-core</module>
+ <module>edm-annotation-webref</module>
+ </modules>
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ae7c1f52/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 0bf73f2..3a35a67 100644
--- a/pom.xml
+++ b/pom.xml
@@ -75,6 +75,7 @@
<modules>
<module>odata2-lib</module>
<module>odata2-processor-jpa</module>
+ <module>odata2-edm-annotation</module>
<module>odata2-dist</module>
</modules>
[47/52] Renamed project
Posted by mi...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/data/DataSourceProcessor.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/data/DataSourceProcessor.java b/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/data/DataSourceProcessor.java
deleted file mode 100644
index 2be5663..0000000
--- a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/data/DataSourceProcessor.java
+++ /dev/null
@@ -1,47 +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.api.data;
-
-import org.apache.olingo.odata2.api.processor.ODataSingleProcessor;
-
-/**
- * Abstract class for implementation of the centralized parts of OData processing,
- * allowing to use the simplified {@link DataSource} and {@link ValueAccess} for the
- * actual data handling.
- * <br/>
- * Extend this class and implement a DataSourceProcessor if the default implementation
- * (<code>ListProcessor</code> found in <code>annotation-processor-core module</code>) has to be overwritten.
- */
-public abstract class DataSourceProcessor extends ODataSingleProcessor {
-
- protected final DataSource dataSource;
- protected final ValueAccess valueAccess;
-
- /**
- * Initialize a {@link DataSourceProcessor} in combination with given {@link DataSource} (providing data objects)
- * and {@link ValueAccess} (accessing values of data objects).
- *
- * @param dataSource used for accessing the data objects
- * @param valueAccess for accessing the values provided by the data objects
- */
- public DataSourceProcessor(final DataSource dataSource, final ValueAccess valueAccess) {
- this.dataSource = dataSource;
- this.valueAccess = valueAccess;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/data/ValueAccess.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/data/ValueAccess.java b/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/data/ValueAccess.java
deleted file mode 100644
index 685e1b6..0000000
--- a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/data/ValueAccess.java
+++ /dev/null
@@ -1,69 +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.api.data;
-
-import org.apache.olingo.odata2.api.edm.EdmMapping;
-import org.apache.olingo.odata2.api.edm.EdmProperty;
-import org.apache.olingo.odata2.api.exception.ODataException;
-
-/**
- * This interface is intended to access values in a Java object.
- */
-public interface ValueAccess {
-
- /**
- * Retrieves the value of an EDM property for the given data object.
- * @param data the Java data object
- * @param property the requested {@link EdmProperty}
- * @return the requested property value
- */
- public <T> Object getPropertyValue(final T data, final EdmProperty property) throws ODataException;
-
- /**
- * Sets the value of an EDM property for the given data object.
- * @param data the Java data object
- * @param property the {@link EdmProperty}
- * @param value the new value of the property
- */
- public <T, V> void setPropertyValue(T data, final EdmProperty property, final V value) throws ODataException;
-
- /**
- * Retrieves the Java type of an EDM property for the given data object.
- * @param data the Java data object
- * @param property the requested {@link EdmProperty}
- * @return the requested Java type
- */
- public <T> Class<?> getPropertyType(final T data, final EdmProperty property) throws ODataException;
-
- /**
- * Retrieves the value defined by a mapping object for the given data object.
- * @param data the Java data object
- * @param mapping the requested {@link EdmMapping}
- * @return the requested value
- */
- public <T> Object getMappingValue(final T data, final EdmMapping mapping) throws ODataException;
-
- /**
- * Sets the value defined by a mapping object for the given data object.
- * @param data the Java data object
- * @param mapping the {@link EdmMapping}
- * @param value the new value
- */
- public <T, V> void setMappingValue(T data, final EdmMapping mapping, final V value) throws ODataException;
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-edm-annotation/edm-annotation-core/pom.xml
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/pom.xml b/odata2-edm-annotation/edm-annotation-core/pom.xml
deleted file mode 100644
index 4e408f7..0000000
--- a/odata2-edm-annotation/edm-annotation-core/pom.xml
+++ /dev/null
@@ -1,48 +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>
-
- <artifactId>olingo-odata2-edm-annotation-core-incubating</artifactId>
- <packaging>jar</packaging>
- <name>${project.artifactId}</name>
-
- <parent>
- <groupId>org.apache.olingo</groupId>
- <artifactId>olingo-odata2-edm-annotation-incubating</artifactId>
- <version>1.1.0-SNAPSHOT</version>
- <relativePath>..</relativePath>
- </parent>
-
- <dependencies>
- <dependency>
- <groupId>org.apache.olingo</groupId>
- <artifactId>olingo-odata2-edm-annotation-api-incubating</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.olingo</groupId>
- <artifactId>olingo-odata2-api-incubating</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.olingo</groupId>
- <artifactId>olingo-odata2-api-annotation-incubating</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.olingo</groupId>
- <artifactId>olingo-odata2-core-incubating</artifactId>
- <version>${project.version}</version>
- </dependency>
- </dependencies>
-
-
-</project>
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationInMemoryDs.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationInMemoryDs.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationInMemoryDs.java
deleted file mode 100644
index db03a4c..0000000
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationInMemoryDs.java
+++ /dev/null
@@ -1,351 +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.core.annotation.data;
-
-import java.lang.reflect.Field;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceContent;
-import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceMimeType;
-import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
-import org.apache.olingo.odata2.api.data.DataSource;
-import org.apache.olingo.odata2.api.edm.EdmEntitySet;
-import org.apache.olingo.odata2.api.edm.EdmException;
-import org.apache.olingo.odata2.api.edm.EdmFunctionImport;
-import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
-import org.apache.olingo.odata2.api.exception.ODataApplicationException;
-import org.apache.olingo.odata2.api.exception.ODataNotFoundException;
-import org.apache.olingo.odata2.api.exception.ODataNotImplementedException;
-import org.apache.olingo.odata2.core.annotation.util.AnnotationHelper;
-import org.apache.olingo.odata2.core.annotation.util.ClassHelper;
-import org.apache.olingo.odata2.core.annotation.util.AnnotationHelper.AnnotatedNavInfo;
-import org.apache.olingo.odata2.core.annotation.util.AnnotationHelper.ODataAnnotationException;
-import org.apache.olingo.odata2.core.exception.ODataRuntimeException;
-
-public class AnnotationInMemoryDs implements DataSource {
-
- private static final AnnotationHelper ANNOTATION_HELPER = new AnnotationHelper();
- private final Map<String, DataStore<Object>> dataStores = new HashMap<String, DataStore<Object>>();
- private final boolean persistInMemory;
-
- public AnnotationInMemoryDs(String packageToScan) {
- this(packageToScan, true);
- }
-
- public AnnotationInMemoryDs(String packageToScan, boolean persistInMemory) {
- this.persistInMemory = persistInMemory;
- List<Class<?>> foundClasses = ClassHelper.loadClasses(packageToScan, new ClassHelper.ClassValidator() {
- @Override
- public boolean isClassValid(Class<?> c) {
- return null != c.getAnnotation(org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet.class);
- }
- });
-
- init(foundClasses);
- }
-
- @SuppressWarnings("unchecked")
- private void init(List<Class<?>> foundClasses) {
- for (Class<?> clz : foundClasses) {
-
- DataStore<Object> dhs = (DataStore<Object>) getDataStore(clz);
- org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet entitySet =
- clz.getAnnotation(org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet.class);
- dataStores.put(entitySet.name(), dhs);
- }
- }
-
- public <T> DataStore<T> getDataStore(Class<T> clazz) {
- return DataStore.createInMemory(clazz, persistInMemory);
- }
-
- @Override
- public List<?> readData(EdmEntitySet entitySet) throws ODataNotImplementedException,
- ODataNotFoundException, EdmException, ODataApplicationException {
-
- DataStore<Object> holder = getDataStore(entitySet);
- if (holder != null) {
- return new ArrayList<Object>(holder.read());
- }
-
- throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
- }
-
- @Override
- public Object readData(EdmEntitySet entitySet, Map<String, Object> keys)
- throws ODataNotFoundException, EdmException, ODataApplicationException {
-
- DataStore<Object> store = getDataStore(entitySet);
- if (store != null) {
- Object keyInstance = store.createInstance();
- ANNOTATION_HELPER.setKeyFields(keyInstance, keys);
-
- Object result = store.read(keyInstance);
- if (result != null) {
- return result;
- }
- }
-
- throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
- }
-
- @Override
- public Object readData(EdmFunctionImport function, Map<String, Object> parameters, Map<String, Object> keys)
- throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException {
- throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
- }
-
- @Override
- public Object readRelatedData(EdmEntitySet sourceEntitySet, Object sourceData, EdmEntitySet targetEntitySet,
- Map<String, Object> targetKeys)
- throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException {
-
- DataStore<?> sourceStore = dataStores.get(sourceEntitySet.getName());
- DataStore<?> targetStore = dataStores.get(targetEntitySet.getName());
-
- AnnotatedNavInfo navInfo = ANNOTATION_HELPER.getCommonNavigationInfo(
- sourceStore.getDataTypeClass(), targetStore.getDataTypeClass());
- Field sourceField = navInfo.getFromField();
- if (sourceField == null) {
- throw new ODataRuntimeException("Missing source field for related data (sourceStore='" + sourceStore
- + "', targetStore='" + targetStore + "').");
- }
-
- Object navigationInstance = getValue(sourceField, sourceData);
- List<Object> resultData = new ArrayList<Object>();
- for (Object targetInstance : targetStore.read()) {
- if (navigationInstance instanceof Collection) {
- for (Object object : (Collection<?>) navigationInstance) {
- if (ANNOTATION_HELPER.keyMatch(targetInstance, object)) {
- resultData.add(targetInstance);
- }
- }
- } else if (ANNOTATION_HELPER.keyMatch(targetInstance, navigationInstance)) {
- resultData.add(targetInstance);
- }
- }
-
- if (navInfo.getToMultiplicity() == EdmMultiplicity.MANY) {
- if (targetKeys.isEmpty()) {
- return resultData;
- } else {
- for (Object result : resultData) {
- if (ANNOTATION_HELPER.keyMatch(result, targetKeys)) {
- return result;
- }
- }
- return null;
- }
- } else {
- if (resultData.isEmpty()) {
- return null;
- }
- return resultData.get(0);
- }
- }
-
- @Override
- public BinaryData readBinaryData(EdmEntitySet entitySet, Object mediaLinkEntryData)
- throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException {
-
- Object data = ANNOTATION_HELPER.getValueForField(mediaLinkEntryData, EdmMediaResourceContent.class);
- Object mimeType = ANNOTATION_HELPER.getValueForField(mediaLinkEntryData, EdmMediaResourceMimeType.class);
-
- BinaryData db = new BinaryData((byte[]) data, String.valueOf(mimeType));
- return db;
- }
-
- @Override
- public Object newDataObject(EdmEntitySet entitySet)
- throws ODataNotImplementedException, EdmException, ODataApplicationException {
-
- DataStore<Object> dataStore = getDataStore(entitySet);
- if (dataStore != null) {
- return dataStore.createInstance();
- }
-
- throw new ODataRuntimeException("No DataStore found for entitySet with name: " + entitySet.getName());
- }
-
- @Override
- public void writeBinaryData(EdmEntitySet entitySet, Object mediaEntityInstance, BinaryData binaryData)
- throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException {
-
- try {
- ANNOTATION_HELPER.setValueForAnnotatedField(
- mediaEntityInstance, EdmMediaResourceContent.class, binaryData.getData());
- ANNOTATION_HELPER.setValueForAnnotatedField(
- mediaEntityInstance, EdmMediaResourceMimeType.class, binaryData.getMimeType());
- } catch (ODataAnnotationException e) {
- throw new ODataRuntimeException("Invalid media resource annotation at entity set '" + entitySet.getName()
- + "' with message '" + e.getMessage() + "'.", e);
- }
- }
-
- /**
- * <p>Updates a single data object identified by the specified entity set and key fields of
- * the data object.</p>
- * @param entitySet the {@link EdmEntitySet} the object must correspond to
- * @param data the data object of the new entity
- * @return updated data object instance
- * @throws org.apache.olingo.odata2.api.exception.ODataNotImplementedException
- * @throws org.apache.olingo.odata2.api.edm.EdmException
- * @throws org.apache.olingo.odata2.api.exception.ODataApplicationException
- */
- public Object updateData(EdmEntitySet entitySet, Object data)
- throws ODataNotImplementedException, EdmException, ODataApplicationException {
-
- DataStore<Object> dataStore = getDataStore(entitySet);
- return dataStore.update(data);
- }
-
- @Override
- public void deleteData(EdmEntitySet entitySet, Map<String, Object> keys)
- throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException {
- DataStore<Object> dataStore = getDataStore(entitySet);
- Object keyInstance = dataStore.createInstance();
- ANNOTATION_HELPER.setKeyFields(keyInstance, keys);
- dataStore.delete(keyInstance);
- }
-
- @Override
- public void createData(EdmEntitySet entitySet, Object data)
- throws ODataNotImplementedException, EdmException, ODataApplicationException {
-
- DataStore<Object> dataStore = getDataStore(entitySet);
- dataStore.create(data);
- }
-
- @Override
- public void deleteRelation(EdmEntitySet sourceEntitySet, Object sourceData, EdmEntitySet targetEntitySet,
- Map<String, Object> targetKeys)
- throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException {
- throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
- }
-
- @Override
- public void writeRelation(EdmEntitySet sourceEntitySet, Object sourceEntity, EdmEntitySet targetEntitySet,
- Map<String, Object> targetEntityValues)
- throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException {
- // get common data
- DataStore<Object> sourceStore = dataStores.get(sourceEntitySet.getName());
- DataStore<Object> targetStore = dataStores.get(targetEntitySet.getName());
-
- AnnotatedNavInfo commonNavInfo = ANNOTATION_HELPER.getCommonNavigationInfo(
- sourceStore.getDataTypeClass(), targetStore.getDataTypeClass());
-
- // get and validate source fields
- Field sourceField = commonNavInfo.getFromField();
- if (sourceField == null) {
- throw new ODataRuntimeException("Missing source field for related data (sourceStore='" + sourceStore
- + "', targetStore='" + targetStore + "').");
- }
-
- // get related target entity
- Object targetEntity = targetStore.createInstance();
- ANNOTATION_HELPER.setKeyFields(targetEntity, targetEntityValues);
- targetEntity = targetStore.read(targetEntity);
-
- // set at source
- setValueAtNavigationField(sourceEntity, sourceField, targetEntity);
- // set at target
- Field targetField = commonNavInfo.getToField();
- if(targetField != null) {
- setValueAtNavigationField(targetEntity, targetField, sourceEntity);
- }
- }
-
- /**
- * Set (Multiplicity != *) or add (Multiplicity == *) <code>value</code> at <code>field</code>
- * of <code>instance</code>.
- *
- * @param instance
- * @param field
- * @param value
- * @throws EdmException
- */
- private void setValueAtNavigationField(Object instance, Field field, Object value)
- throws EdmException {
- Class<?> fieldTypeClass = field.getType();
- if (Collection.class.isAssignableFrom(fieldTypeClass)) {
- @SuppressWarnings("unchecked")
- Collection<Object> collection = (Collection<Object>) ANNOTATION_HELPER.getValueForField(
- instance, field.getName(), EdmNavigationProperty.class);
- if(collection == null) {
- collection = new ArrayList<Object>();
- setValue(instance, field, collection);
- }
- collection.add(value);
- } else if(fieldTypeClass.isArray()) {
- throw new ODataRuntimeException("Write relations for internal used arrays is not supported.");
- } else {
- setValue(instance, field, value);
- }
- }
-
- /**
- * Returns corresponding DataStore for EdmEntitySet or if no data store is registered an
- * ODataRuntimeException is thrown.
- * Never returns NULL.
- *
- * @param entitySet for which the corresponding DataStore is returned
- * @return a DataStore object
- * @throws EdmException
- * @throws ODataRuntimeException if no DataStore is found
- */
- private DataStore<Object> getDataStore(EdmEntitySet entitySet) throws EdmException {
- final String name = entitySet.getName();
- DataStore<Object> dataStore = dataStores.get(name);
- if (dataStore == null) {
- throw new ODataRuntimeException("No DataStore found for entity set '" + entitySet + "'.");
- }
- return dataStore;
- }
-
- private Object getValue(Field field, Object instance) {
- try {
- boolean access = field.isAccessible();
- field.setAccessible(true);
- Object value = field.get(instance);
- field.setAccessible(access);
- return value;
- } catch (IllegalArgumentException e) {
- throw new ODataRuntimeException("Error for getting value of field '"
- + field + "' at instance '" + instance + "'.", e);
- } catch (IllegalAccessException e) {
- throw new ODataRuntimeException("Error for getting value of field '"
- + field + "' at instance '" + instance + "'.", e);
- }
- }
-
- private void setValue(Object instance, Field field, Object value) {
- try {
- boolean access = field.isAccessible();
- field.setAccessible(true);
- field.set(instance, value);
- field.setAccessible(access);
- } catch (IllegalArgumentException e) {
- throw new ODataRuntimeException("Error for setting value of field: '"
- + field + "' at instance: '" + instance + "'.", e);
- } catch (IllegalAccessException e) {
- throw new ODataRuntimeException("Error for setting value of field: '"
- + field + "' at instance: '" + instance + "'.", e);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationValueAccess.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationValueAccess.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationValueAccess.java
deleted file mode 100644
index 14183bf..0000000
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationValueAccess.java
+++ /dev/null
@@ -1,106 +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.core.annotation.data;
-
-import org.apache.olingo.odata2.api.data.ValueAccess;
-import org.apache.olingo.odata2.api.edm.EdmMapping;
-import org.apache.olingo.odata2.api.edm.EdmProperty;
-import org.apache.olingo.odata2.api.exception.ODataException;
-import org.apache.olingo.odata2.api.exception.ODataNotImplementedException;
-import org.apache.olingo.odata2.core.annotation.util.AnnotationHelper;
-
-/**
- *
- */
-public class AnnotationValueAccess implements ValueAccess {
- private final AnnotationHelper annotationHelper = new AnnotationHelper();
-
- /**
- * Retrieves the value of an EDM property for the given data object.
- * @param data the Java data object
- * @param property the requested {@link EdmProperty}
- * @return the requested property value
- */
- @Override
- public <T> Object getPropertyValue(final T data, final EdmProperty property) throws ODataException {
- if(data == null) {
- return null;
- } else if (annotationHelper.isEdmAnnotated(data)) {
- return annotationHelper.getValueForProperty(data, property.getName());
- }
- throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
- }
-
- /**
- * Sets the value of an EDM property for the given data object.
- * @param data the Java data object
- * @param property the {@link EdmProperty}
- * @param value the new value of the property
- */
- @Override
- public <T, V> void setPropertyValue(T data, final EdmProperty property, final V value) throws ODataException {
- if (annotationHelper.isEdmAnnotated(data)) {
- annotationHelper.setValueForProperty(data, property.getName(), value);
- } else {
- throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
- }
- }
-
- /**
- * Retrieves the Java type of an EDM property for the given data object.
- * @param data the Java data object
- * @param property the requested {@link EdmProperty}
- * @return the requested Java type
- */
- public <T> Class<?> getPropertyType(final T data, final EdmProperty property) throws ODataException {
- if (annotationHelper.isEdmAnnotated(data)) {
- Class<?> fieldType = annotationHelper.getFieldTypeForProperty(data, property.getName());
- if (fieldType == null) {
- throw new ODataException("No field type found for property " + property);
- }
- return fieldType;
- }
- throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
- }
-
- /**
- * Retrieves the value defined by a mapping object for the given data object.
- * @param data the Java data object
- * @param mapping the requested {@link EdmMapping}
- * @return the requested value
- */
- public <T> Object getMappingValue(final T data, final EdmMapping mapping) throws ODataException {
- if (mapping != null && mapping.getMediaResourceMimeTypeKey() != null) {
- return annotationHelper.getValueForProperty(data, mapping.getMediaResourceMimeTypeKey());
- }
- return null;
- }
-
- /**
- * Sets the value defined by a mapping object for the given data object.
- * @param data the Java data object
- * @param mapping the {@link EdmMapping}
- * @param value the new value
- */
- public <T, V> void setMappingValue(T data, final EdmMapping mapping, final V value) throws ODataException {
- if (mapping != null && mapping.getMediaResourceMimeTypeKey() != null) {
- annotationHelper.setValueForProperty(data, mapping.getMediaResourceMimeTypeKey(), value);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/BeanPropertyAccess.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/BeanPropertyAccess.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/BeanPropertyAccess.java
deleted file mode 100644
index be3baac..0000000
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/BeanPropertyAccess.java
+++ /dev/null
@@ -1,186 +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.core.annotation.data;
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.Arrays;
-
-import org.apache.olingo.odata2.api.data.ValueAccess;
-import org.apache.olingo.odata2.api.edm.EdmException;
-import org.apache.olingo.odata2.api.edm.EdmMapping;
-import org.apache.olingo.odata2.api.edm.EdmProperty;
-import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
-import org.apache.olingo.odata2.api.exception.ODataException;
-import org.apache.olingo.odata2.api.exception.ODataHttpException;
-import org.apache.olingo.odata2.api.exception.ODataNotFoundException;
-
-/**
- * Data access.
- */
-public class BeanPropertyAccess implements ValueAccess {
-
- @Override
- public <T> Object getPropertyValue(final T data, final EdmProperty property) throws ODataException {
- return getValue(data, getGetterMethodName(property));
- }
-
- @Override
- public <T, V> void setPropertyValue(T data, final EdmProperty property, final V value) throws ODataException {
- final String methodName = getSetterMethodName(getGetterMethodName(property));
- if (methodName != null) {
- setValue(data, methodName, value);
- }
- }
-
- @Override
- public <T> Class<?> getPropertyType(final T data, final EdmProperty property) throws ODataException {
- return getType(data, getGetterMethodName(property));
- }
-
- @Override
- public <T> Object getMappingValue(final T data, final EdmMapping mapping) throws ODataException {
- if (mapping != null && mapping.getMimeType() != null) {
- return getValue(data, mapping.getMimeType());
- }
- return null;
- }
-
- @Override
- public <T, V> void setMappingValue(T data, final EdmMapping mapping, final V value) throws ODataException {
- if (mapping != null && mapping.getMimeType() != null) {
- setValue(data, getSetterMethodName(mapping.getMimeType()), value);
- }
- }
-
- private String getGetterMethodName(final EdmProperty property) throws EdmException {
- final String prefix = isBooleanProperty(property) ? "is" : "get";
- final String defaultMethodName = prefix + property.getName();
- return property.getMapping() == null || property.getMapping().getInternalName() == null ?
- defaultMethodName : property.getMapping().getInternalName();
- }
-
- private boolean isBooleanProperty(final EdmProperty property) throws EdmException {
- return property.isSimple()
- && property.getType() == EdmSimpleTypeKind.Boolean.getEdmSimpleTypeInstance();
- }
-
- private String getSetterMethodName(final String getterMethodName) {
- return getterMethodName.contains(".") ?
- null : getterMethodName.replaceFirst("^is", "set").replaceFirst("^get", "set");
- }
-
- private <T> Object getValue(final T data, final String methodName) throws ODataNotFoundException {
- Object dataObject = data;
-
- for (final String method : methodName.split("\\.", -1)) {
- if (dataObject != null) {
- try {
- dataObject = dataObject.getClass().getMethod(method).invoke(dataObject);
- } catch (SecurityException e) {
- throw new ODataNotFoundException(ODataHttpException.COMMON, e);
- } catch (NoSuchMethodException e) {
- throw new ODataNotFoundException(ODataHttpException.COMMON, e);
- } catch (IllegalArgumentException e) {
- throw new ODataNotFoundException(ODataHttpException.COMMON, e);
- } catch (IllegalAccessException e) {
- throw new ODataNotFoundException(ODataHttpException.COMMON, e);
- } catch (InvocationTargetException e) {
- throw new ODataNotFoundException(ODataHttpException.COMMON, e);
- }
- }
- }
-
- return dataObject;
- }
-
- private <T, V> void setValue(final T data, final String methodName, final V value)
- throws ODataNotFoundException {
- try {
- boolean found = false;
- for (final Method method : Arrays.asList(data.getClass().getMethods())) {
- if (method.getName().equals(methodName)) {
- found = true;
- final Class<?> type = method.getParameterTypes()[0];
- if (value == null) {
- if (type.equals(byte.class) || type.equals(short.class) || type.equals(int.class)
- || type.equals(long.class) || type.equals(char.class)) {
- method.invoke(data, 0);
- } else if (type.equals(float.class) || type.equals(double.class)) {
- method.invoke(data, 0.0);
- } else if (type.equals(boolean.class)) {
- method.invoke(data, false);
- } else {
- method.invoke(data, value);
- }
- } else {
- method.invoke(data, value);
- }
- break;
- }
- }
- if (!found) {
- throw new ODataNotFoundException(null);
- }
- } catch (SecurityException e) {
- throw new ODataNotFoundException(null, e);
- } catch (IllegalArgumentException e) {
- throw new ODataNotFoundException(null, e);
- } catch (IllegalAccessException e) {
- throw new ODataNotFoundException(null, e);
- } catch (InvocationTargetException e) {
- throw new ODataNotFoundException(null, e);
- }
- }
-
- private <T> Class<?> getType(final T data, final String methodName) throws ODataNotFoundException {
- if (data == null) {
- throw new ODataNotFoundException(ODataHttpException.COMMON);
- }
-
- Class<?> type = data.getClass();
- for (final String method : methodName.split("\\.", -1)) {
- try {
- type = type.getMethod(method).getReturnType();
- if (type.isPrimitive()) {
- if (type == boolean.class) {
- type = Boolean.class;
- } else if (type == byte.class) {
- type = Byte.class;
- } else if (type == short.class) {
- type = Short.class;
- } else if (type == int.class) {
- type = Integer.class;
- } else if (type == long.class) {
- type = Long.class;
- } else if (type == float.class) {
- type = Float.class;
- } else if (type == double.class) {
- type = Double.class;
- }
- }
- } catch (final SecurityException e) {
- throw new ODataNotFoundException(ODataHttpException.COMMON, e);
- } catch (final NoSuchMethodException e) {
- throw new ODataNotFoundException(ODataHttpException.COMMON, e);
- }
- }
- return type;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/DataStore.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/DataStore.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/DataStore.java
deleted file mode 100644
index 696ab9a..0000000
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/DataStore.java
+++ /dev/null
@@ -1,192 +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.core.annotation.data;
-
-import java.lang.reflect.Field;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-
-import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
-import org.apache.olingo.odata2.api.exception.ODataApplicationException;
-import org.apache.olingo.odata2.core.annotation.util.AnnotationHelper;
-import org.apache.olingo.odata2.core.exception.ODataRuntimeException;
-
-/**
- *
- */
-public class DataStore<T> {
-
- private static final AnnotationHelper ANNOTATION_HELPER = new AnnotationHelper();
- private final List<T> dataStore;
- private final Class<T> dataTypeClass;
-
- private int idCounter = 1;
-
- private static class InMemoryDataStore {
- private static final Map<Class<?>, DataStore<?>> c2ds = new HashMap<Class<?>, DataStore<?>>();
-
- @SuppressWarnings("unchecked")
- static DataStore<?> getInstance(Class<?> clz, boolean createNewInstance) {
- DataStore<?> ds = c2ds.get(clz);
- if (createNewInstance || ds == null) {
- ds = new DataStore<Object>((Class<Object>) clz);
- c2ds.put(clz, ds);
- }
- return ds;
- }
- }
-
- @SuppressWarnings("unchecked")
- public static <T> DataStore<T> createInMemory(Class<T> clazz) {
- return (DataStore<T>) InMemoryDataStore.getInstance(clazz, true);
- }
-
- @SuppressWarnings("unchecked")
- public static <T> DataStore<T> createInMemory(Class<T> clazz, boolean keepExisting) {
- return (DataStore<T>) InMemoryDataStore.getInstance(clazz, !keepExisting);
- }
-
- private DataStore(List<T> wrapStore, Class<T> clz) {
- dataStore = Collections.synchronizedList(wrapStore);
- dataTypeClass = clz;
- }
-
- private DataStore(Class<T> clz) {
- this(new ArrayList<T>(), clz);
- }
-
- public Class<T> getDataTypeClass() {
- return dataTypeClass;
- }
-
- public String getEntityTypeName() {
- return ANNOTATION_HELPER.extractEntityTypeName(dataTypeClass);
- }
-
- public T createInstance() {
- try {
- return dataTypeClass.newInstance();
- } catch (InstantiationException e) {
- throw new ODataRuntimeException("Unable to create instance of class '" + dataTypeClass + "'.", e);
- } catch (IllegalAccessException e) {
- throw new ODataRuntimeException("Unable to create instance of class '" + dataTypeClass + "'.", e);
- }
- }
-
- public T read(T obj) {
- List<Object> objKeys = getKeys(obj);
- for (T stored : dataStore) {
- if (objKeys.equals(getKeys(stored))) {
- return stored;
- }
- }
- return null;
- }
-
- public Collection<T> read() {
- return Collections.unmodifiableCollection(dataStore);
- }
-
- public T create(T object) throws DataStoreException {
- synchronized (dataStore) {
- if (read(object) != null || getKeys(object).contains(null)) {
- createKeys(object);
- return this.create(object);
- }
- dataStore.add(object);
- }
- return object;
- }
-
- public T update(T object) {
- synchronized (dataStore) {
- T stored = read(object);
- dataStore.remove(stored);
- dataStore.add(object);
- }
- return object;
- }
-
- public T delete(T object) {
- synchronized (dataStore) {
- T stored = read(object);
- if (stored != null) {
- dataStore.remove(stored);
- }
- return stored;
- }
- }
-
- private List<Object> getKeys(T object) {
- Map<String, Object> keys = ANNOTATION_HELPER.getValueForAnnotatedFields(object, EdmKey.class);
-
- // XXX: list should be in a defined order -> better to create an 'Key' object which is comparable
- List<Object> keyList = new ArrayList<Object>(keys.values());
- return keyList;
- }
-
- private T createKeys(T object) throws DataStoreException {
- List<Field> fields = ANNOTATION_HELPER.getAnnotatedFields(object, EdmKey.class);
- if (fields.isEmpty()) {
- throw new DataStoreException("No EdmKey annotated fields found for class " + object.getClass());
- }
- Map<String, Object> fieldName2KeyValue = new HashMap<String, Object>();
-
- for (Field field : fields) {
- Object key = createKey(field);
- fieldName2KeyValue.put(ANNOTATION_HELPER.getCanonicalName(field), key);
- }
-
- ANNOTATION_HELPER.setValuesToAnnotatedFields(object, EdmKey.class, fieldName2KeyValue);
-
- return object;
- }
-
- private Object createKey(Field field) {
- Class<?> type = field.getType();
-
- if (type == String.class) {
- return String.valueOf(idCounter++);
- } else if (type == Integer.class || type == int.class) {
- return Integer.valueOf(idCounter++);
- } else if (type == Long.class || type == long.class) {
- return Long.valueOf(idCounter++);
- }
-
- throw new UnsupportedOperationException("Automated key generation for type '" + type
- + "' is not supported (caused on field '" + field + "').");
- }
-
- public static class DataStoreException extends ODataApplicationException {
- private static final long serialVersionUID = 42L;
-
- public DataStoreException(String message) {
- this(message, null);
- }
-
- public DataStoreException(String message, Throwable cause) {
- super(message, Locale.ENGLISH, cause);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java
deleted file mode 100644
index 97f5b53..0000000
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java
+++ /dev/null
@@ -1,773 +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.core.annotation.edm;
-
-import java.lang.reflect.Field;
-import java.lang.reflect.Modifier;
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-
-import org.apache.olingo.odata2.api.annotation.edm.EdmComplexType;
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
-import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceContent;
-import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
-import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
-import org.apache.olingo.odata2.api.annotation.edm.EdmType;
-import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
-import org.apache.olingo.odata2.api.edm.FullQualifiedName;
-import org.apache.olingo.odata2.api.edm.provider.AnnotationAttribute;
-import org.apache.olingo.odata2.api.edm.provider.AnnotationElement;
-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.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.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.Schema;
-import org.apache.olingo.odata2.api.edm.provider.SimpleProperty;
-import org.apache.olingo.odata2.api.edm.provider.Using;
-import org.apache.olingo.odata2.api.exception.ODataException;
-import org.apache.olingo.odata2.core.annotation.util.AnnotationHelper;
-import org.apache.olingo.odata2.core.annotation.util.ClassHelper;
-import org.apache.olingo.odata2.core.exception.ODataRuntimeException;
-
-/**
- * Provider for the entity data model used in the reference scenario
- *
- */
-public class AnnotationEdmProvider extends EdmProvider {
-
- private static final AnnotationHelper ANNOTATION_HELPER = new AnnotationHelper();
-
- private final List<Class<?>> annotatedClasses;
- private final Map<String, EntityContainer> name2Container = new HashMap<String, EntityContainer>();
- private final Map<String, ContainerBuilder> containerName2ContainerBuilder = new HashMap<String, ContainerBuilder>();
- private final Map<String, Schema> namespace2Schema = new HashMap<String, Schema>();
- private EntityContainer defaultContainer;
-
- public AnnotationEdmProvider(Collection<Class<?>> annotatedClasses) {
-
- this.annotatedClasses = new ArrayList<Class<?>>(annotatedClasses.size());
- for (Class<?> aClass : annotatedClasses) {
- if (ANNOTATION_HELPER.isEdmAnnotated(aClass)) {
- this.annotatedClasses.add(aClass);
- }
- }
-
- init();
- }
-
- public AnnotationEdmProvider(String packageToScan) {
- this.annotatedClasses = ClassHelper.loadClasses(packageToScan, new ClassHelper.ClassValidator() {
- @Override
- public boolean isClassValid(Class<?> c) {
- return ANNOTATION_HELPER.isEdmAnnotated(c);
- }
- });
-
- init();
- }
-
- private void init() {
- for (Class<?> aClass : annotatedClasses) {
- updateSchema(aClass);
- handleEntityContainer(aClass);
- }
-
- finish();
- }
-
- @Override
- public Association getAssociation(FullQualifiedName edmFQName) throws ODataException {
- Schema schema = namespace2Schema.get(edmFQName.getNamespace());
- if (schema != null) {
- List<Association> associations = schema.getAssociations();
- for (Association association : associations) {
- if (association.getName().equals(edmFQName.getName())) {
- return association;
- }
- }
- }
- return null;
- }
-
- @Override
- public AssociationSet getAssociationSet(String entityContainer, FullQualifiedName association,
- String sourceEntitySetName, String sourceEntitySetRole) throws ODataException {
- EntityContainer container = name2Container.get(entityContainer);
- if (container != null) {
- List<AssociationSet> associations = container.getAssociationSets();
- for (AssociationSet associationSet : associations) {
- if (associationSet.getAssociation().equals(association)) {
- final AssociationSetEnd endOne = associationSet.getEnd1();
- if (endOne.getRole().equals(sourceEntitySetRole)
- && endOne.getEntitySet().equals(sourceEntitySetName)) {
- return associationSet;
- }
- final AssociationSetEnd endTwo = associationSet.getEnd2();
- if (endTwo.getRole().equals(sourceEntitySetRole)
- && endTwo.getEntitySet().equals(sourceEntitySetName)) {
- return associationSet;
- }
- }
- }
- }
- return null;
- }
-
- @Override
- public ComplexType getComplexType(FullQualifiedName edmFQName) throws ODataException {
- Schema schema = namespace2Schema.get(edmFQName.getNamespace());
- if (schema != null) {
- List<ComplexType> complexTypes = schema.getComplexTypes();
- for (ComplexType complexType : complexTypes) {
- if (complexType.getName().equals(edmFQName.getName())) {
- return complexType;
- }
- }
- }
- return null;
- }
-
- @Override
- public EntityContainerInfo getEntityContainerInfo(String name) throws ODataException {
- EntityContainer container = name2Container.get(name);
- if (container == null) {
- // use default container (if set)
- container = defaultContainer;
- }
- if (container != null) {
- EntityContainerInfo info = new EntityContainerInfo();
- info.setName(container.getName());
- info.setDefaultEntityContainer(container.isDefaultEntityContainer());
- info.setExtendz(container.getExtendz());
- info.setAnnotationAttributes(container.getAnnotationAttributes());
- info.setAnnotationElements(container.getAnnotationElements());
-
- return info;
- }
-
- return null;
- }
-
- @Override
- public EntitySet getEntitySet(String entityContainer, String name) throws ODataException {
- EntityContainer container = name2Container.get(entityContainer);
- if (container != null) {
- List<EntitySet> entitySets = container.getEntitySets();
- for (EntitySet entitySet : entitySets) {
- if (entitySet.getName().equals(name)) {
- return entitySet;
- }
- }
- }
-
- return null;
- }
-
- @Override
- public EntityType getEntityType(FullQualifiedName edmFQName) throws ODataException {
- Schema schema = namespace2Schema.get(edmFQName.getNamespace());
- if (schema != null) {
- List<EntityType> complexTypes = schema.getEntityTypes();
- for (EntityType complexType : complexTypes) {
- if (complexType.getName().equals(edmFQName.getName())) {
- return complexType;
- }
- }
- }
- return null;
- }
-
- @Override
- public FunctionImport getFunctionImport(String entityContainer, String name) throws ODataException {
- EntityContainer container = name2Container.get(entityContainer);
- if (container != null) {
- List<FunctionImport> functionImports = container.getFunctionImports();
- for (FunctionImport functionImport : functionImports) {
- if (functionImport.getName().equals(name)) {
- return functionImport;
- }
- }
- }
- return null;
- }
-
- @Override
- public List<Schema> getSchemas() throws ODataException {
- return new ArrayList<Schema>(namespace2Schema.values());
- }
-
- //
- //
- //
- private Map<String, SchemaBuilder> namespace2SchemaBuilder = new HashMap<String, SchemaBuilder>();
-
- private void updateSchema(Class<?> aClass) {
- EdmEntityType et = aClass.getAnnotation(EdmEntityType.class);
- if (et != null) {
- updateSchema(aClass, et);
- }
- EdmComplexType ect = aClass.getAnnotation(EdmComplexType.class);
- if (ect != null) {
- updateSchema(aClass, ect);
- }
- }
-
- private void updateSchema(Class<?> aClass, EdmEntityType et) {
- SchemaBuilder b = getSchemaBuilder(et.namespace(), aClass);
- TypeBuilder typeBuilder = TypeBuilder.init(et, aClass);
- b.addEntityType(typeBuilder.buildEntityType());
- b.addAssociations(typeBuilder.buildAssociations());
- }
-
- private SchemaBuilder getSchemaBuilder(String namespace, Class<?> aClass) {
- String usedNamespace = namespace;
- if(usedNamespace.isEmpty()) {
- usedNamespace = ANNOTATION_HELPER.getCanonicalNamespace(aClass);
- }
- SchemaBuilder builder = namespace2SchemaBuilder.get(usedNamespace);
- if (builder == null) {
- builder = SchemaBuilder.init(usedNamespace);
- namespace2SchemaBuilder.put(usedNamespace, builder);
- }
- return builder;
- }
-
- private void updateSchema(Class<?> aClass, EdmComplexType et) {
- SchemaBuilder b = getSchemaBuilder(et.namespace(), aClass);
- TypeBuilder typeBuilder = TypeBuilder.init(et, aClass);
- b.addComplexType(typeBuilder.buildComplexType());
- }
-
- private void handleEntityContainer(Class<?> aClass) {
- EdmEntityType entityType = aClass.getAnnotation(EdmEntityType.class);
- if (entityType != null) {
- FullQualifiedName typeName = createFqnForEntityType(aClass, entityType);
- String containerName = ANNOTATION_HELPER.extractContainerName(aClass);
- ContainerBuilder builder = containerName2ContainerBuilder.get(containerName);
- if (builder == null) {
- builder = ContainerBuilder.init(typeName.getNamespace(), containerName);
- containerName2ContainerBuilder.put(containerName, builder);
- }
- EdmEntitySet entitySet = aClass.getAnnotation(EdmEntitySet.class);
- if (entitySet != null) {
- builder.addEntitySet(createEntitySet(typeName, entitySet));
- }
- }
- }
-
- private EntitySet createEntitySet(FullQualifiedName typeName, EdmEntitySet entitySet) {
- return new EntitySet().setName(entitySet.name()).setEntityType(typeName);
- }
-
- private FullQualifiedName createFqnForEntityType(Class<?> annotatedClass, EdmEntityType entityType) {
- return ANNOTATION_HELPER.extractEntityTypeFqn(annotatedClass);
- }
-
- private void finish() {
- //
- Collection<ContainerBuilder> containers = containerName2ContainerBuilder.values();
- for (ContainerBuilder containerBuilder : containers) {
- SchemaBuilder schemaBuilder = namespace2SchemaBuilder.get(containerBuilder.getNamespace());
- containerBuilder.addAssociationSets(schemaBuilder.name2Associations.values());
- final EntityContainer container = containerBuilder.build();
- schemaBuilder.addEntityContainer(container);
- name2Container.put(container.getName(), container);
- if (container.isDefaultEntityContainer()) {
- defaultContainer = container;
- }
- }
- //
- Collection<SchemaBuilder> schemaBuilders = namespace2SchemaBuilder.values();
- for (SchemaBuilder schemaBuilder : schemaBuilders) {
- final Schema schema = schemaBuilder.build();
- namespace2Schema.put(schema.getNamespace(), schema);
- }
- }
-
- //
- //
- //
- static class TypeBuilder {
-
- final private String namespace;
- final private String name;
- private boolean isAbstract = false;
- private boolean isMediaResource = false;
- private FullQualifiedName baseEntityType = null;
- private final List<PropertyRef> keyProperties = new ArrayList<PropertyRef>();
- private final List<Property> properties = new ArrayList<Property>();
- private final List<NavigationProperty> navProperties = new ArrayList<NavigationProperty>();
- private final List<Association> associations = new ArrayList<Association>();
-
- public TypeBuilder(FullQualifiedName fqn) {
- this.namespace = fqn.getNamespace();
- this.name = fqn.getName();
- }
-
- public static TypeBuilder init(EdmEntityType entity, Class<?> aClass) {
- return new TypeBuilder(ANNOTATION_HELPER.extractEntityTypeFqn(entity, aClass)).withClass(aClass);
- }
-
- public static TypeBuilder init(EdmComplexType entity, Class<?> aClass) {
- return new TypeBuilder(ANNOTATION_HELPER.extractComplexTypeFqn(entity, aClass)).withClass(aClass);
- }
-
- private TypeBuilder withClass(Class<?> aClass) {
- baseEntityType = createBaseEntityFqn(aClass);
-
- if (Modifier.isAbstract(aClass.getModifiers())) {
- this.isAbstract = true;
- }
-
- Field[] fields = aClass.getDeclaredFields();
- for (Field field : fields) {
- EdmProperty ep = field.getAnnotation(EdmProperty.class);
- if (ep != null) {
- properties.add(createProperty(ep, field, namespace));
- EdmKey eti = field.getAnnotation(EdmKey.class);
- if (eti != null) {
- keyProperties.add(createKeyProperty(ep, field));
- }
- }
- EdmNavigationProperty enp = field.getAnnotation(EdmNavigationProperty.class);
- if (enp != null) {
- final NavigationProperty navProperty = createNavigationProperty(namespace, enp, field);
- navProperties.add(navProperty);
- Association association = createAssociation(field, navProperty);
- associations.add(association);
- }
- EdmMediaResourceContent emrc = field.getAnnotation(EdmMediaResourceContent.class);
- if (emrc != null) {
- isMediaResource = true;
- }
- }
-
- return this;
- }
-
- public TypeBuilder addProperty(PropertyRef property) {
- keyProperties.add(property);
- return this;
- }
-
- public TypeBuilder addProperty(Property property) {
- properties.add(property);
- return this;
- }
-
- public TypeBuilder addNavigationProperty(NavigationProperty property) {
- navProperties.add(property);
- return this;
- }
-
- public TypeBuilder setAbstract(boolean isAbstract) {
- this.isAbstract = isAbstract;
- return this;
- }
-
- public ComplexType buildComplexType() {
- ComplexType complexType = new ComplexType();
- if (baseEntityType != null) {
- complexType.setBaseType(baseEntityType);
- }
- return complexType.setName(name).setProperties(properties);
- }
-
- public EntityType buildEntityType() {
- EntityType entityType = new EntityType();
- if (baseEntityType != null) {
- entityType.setBaseType(baseEntityType);
- }
- if (!keyProperties.isEmpty()) {
- entityType.setKey(new Key().setKeys(keyProperties));
- }
- if (!navProperties.isEmpty()) {
- entityType.setNavigationProperties(navProperties);
- }
- return entityType.setName(name)
- .setAbstract(isAbstract)
- .setHasStream(isMediaResource)
- .setProperties(properties);
- }
-
- public Collection<Association> buildAssociations() {
- return Collections.unmodifiableCollection(associations);
- }
-
- private PropertyRef createKeyProperty(EdmProperty et, Field field) {
- PropertyRef keyProperty = new PropertyRef();
- String entityName = et.name();
- if (entityName.isEmpty()) {
- entityName = getCanonicalName(field);
- }
- return keyProperty.setName(entityName);
- }
-
- private Property createProperty(EdmProperty ep, Field field, String defaultNamespace) {
- if (isAnnotatedEntity(field.getType())) {
- return createComplexProperty(field, defaultNamespace);
- } else {
- return createSimpleProperty(ep, field);
- }
- }
-
- private Property createSimpleProperty(EdmProperty ep, Field field) {
- SimpleProperty sp = new SimpleProperty();
- String entityName = ANNOTATION_HELPER.getPropertyName(field);
- sp.setName(entityName);
- //
- EdmType type = ep.type();
- if (type == EdmType.NULL) {
- type = getEdmType(field.getType());
- }
- sp.setType(ANNOTATION_HELPER.mapTypeKind(type));
-
- return sp;
- }
-
- private Property createComplexProperty(Field field, String defaultNamespace) {
- ComplexProperty cp = new ComplexProperty();
- // settings from property
- String entityName = ANNOTATION_HELPER.getPropertyName(field);
- cp.setName(entityName);
-
- // settings from related complex entity
- EdmComplexType ece = field.getType().getAnnotation(EdmComplexType.class);
- String complexEntityNamespace = ece.namespace();
- if (complexEntityNamespace.isEmpty()) {
- complexEntityNamespace = defaultNamespace;
- }
- cp.setType(new FullQualifiedName(complexEntityNamespace, ece.name()));
-
- return cp;
- }
-
- private NavigationProperty createNavigationProperty(String namespace, EdmNavigationProperty enp, Field field) {
- NavigationProperty navProp = new NavigationProperty();
- navProp.setName(ANNOTATION_HELPER.getPropertyName(field));
- String fromRole = ANNOTATION_HELPER.extractFromRoleName(enp, field);
- navProp.setFromRole(fromRole);
-
- String toRole = ANNOTATION_HELPER.extractToRoleName(enp, field);
- navProp.setToRole(toRole);
-
- String relationshipName = ANNOTATION_HELPER.extractRelationshipName(enp, field);
- navProp.setRelationship(new FullQualifiedName(namespace, relationshipName));
-
- return navProp;
- }
-
-// private EdmSimpleTypeKind getEdmSimpleType(Class<?> type) {
-// if (type == String.class) {
-// return EdmType.String;
-// } else if (type == boolean.class || type == Boolean.class) {
-// return EdmType.Boolean;
-// } else if (type == byte.class || type == Byte.class) {
-// return EdmType.SByte;
-// } else if (type == short.class || type == Short.class) {
-// return EdmType.Int16;
-// } else if (type == int.class || type == Integer.class) {
-// return EdmType.Int32;
-// } else if (type == long.class || type == Long.class) {
-// return EdmType.Int64;
-// } else if (type == double.class || type == Double.class) {
-// return EdmType.Double;
-// } else if (type == float.class || type == Float.class) {
-// return EdmType.Single;
-// } else if (type == BigInteger.class || type == BigDecimal.class) {
-// return EdmType.Decimal;
-// } else if (type == Byte[].class || type == byte[].class) {
-// return EdmType.Binary;
-// } else if (type == Date.class) {
-// return EdmType.DateTime;
-// } else if (type == Calendar.class) {
-// return EdmType.DateTimeOffset;
-// } else if (type == UUID.class) {
-// return EdmType.Guid;
-// } else {
-// throw new UnsupportedOperationException("Not yet supported type '" + type + "'.");
-// }
-// }
-
- private EdmType getEdmType(Class<?> type) {
- if (type == String.class) {
- return EdmType.STRING;
- } else if (type == boolean.class || type == Boolean.class) {
- return EdmType.BOOLEAN;
- } else if (type == byte.class || type == Byte.class) {
- return EdmType.SBYTE;
- } else if (type == short.class || type == Short.class) {
- return EdmType.INT16;
- } else if (type == int.class || type == Integer.class) {
- return EdmType.INT32;
- } else if (type == long.class || type == Long.class) {
- return EdmType.INT64;
- } else if (type == double.class || type == Double.class) {
- return EdmType.DOUBLE;
- } else if (type == float.class || type == Float.class) {
- return EdmType.SINGLE;
- } else if (type == BigInteger.class || type == BigDecimal.class) {
- return EdmType.DECIMAL;
- } else if (type == Byte[].class || type == byte[].class) {
- return EdmType.BINARY;
- } else if (type == Date.class) {
- return EdmType.DATE_TIME;
- } else if (type == Calendar.class) {
- return EdmType.DATE_TIME_OFFSET;
- } else if (type == UUID.class) {
- return EdmType.GUID;
- } else {
- throw new UnsupportedOperationException("Not yet supported type '" + type + "'.");
- }
- }
-
-
- private Class<?> checkForBaseEntityClass(Class<?> aClass) {
- Class<?> superClass = aClass.getSuperclass();
- if (superClass == Object.class) {
- return null;
- } else {
- EdmEntityType edmEntity = superClass.getAnnotation(EdmEntityType.class);
- if (edmEntity == null) {
- return checkForBaseEntityClass(superClass);
- } else {
- return superClass;
- }
- }
- }
-
- private FullQualifiedName createBaseEntityFqn(Class<?> aClass) {
- Class<?> baseEntityClass = checkForBaseEntityClass(aClass);
- if (baseEntityClass == null) {
- return null;
- }
- return ANNOTATION_HELPER.extractEntityTypeFqn(baseEntityClass);
- }
-
- private Association createAssociation(Field field, NavigationProperty navProperty) {
- Association association = new Association();
- EdmNavigationProperty navigation = field.getAnnotation(EdmNavigationProperty.class);
-
- AssociationEnd fromEnd = new AssociationEnd();
- fromEnd.setRole(navProperty.getFromRole());
- String typeName = ANNOTATION_HELPER.extractEntityTypeName(field.getDeclaringClass());
- fromEnd.setType(new FullQualifiedName(namespace, typeName));
- fromEnd.setMultiplicity(EdmMultiplicity.ONE);
- association.setEnd1(fromEnd);
-
- AssociationEnd toEnd = new AssociationEnd();
- toEnd.setRole(navProperty.getToRole());
- String toTypeName = ANNOTATION_HELPER.extractEntitTypeName(navigation, field);
- toEnd.setType(new FullQualifiedName(namespace, toTypeName));
- toEnd.setMultiplicity(ANNOTATION_HELPER.getMultiplicity(navigation, field));
- association.setEnd2(toEnd);
-
- String associationName = navProperty.getRelationship().getName();
- association.setName(associationName);
- return association;
- }
-
- private String getCanonicalName(Field field) {
- return ANNOTATION_HELPER.getCanonicalName(field);
- }
-
- private boolean isAnnotatedEntity(Class<?> clazz) {
- return ANNOTATION_HELPER.isEdmTypeAnnotated(clazz);
- }
- }
-
- static class SchemaBuilder {
-
- final private String namespace;
- // private String alias;
- private final List<Using> usings = new ArrayList<Using>();
- private final List<EntityType> entityTypes = new ArrayList<EntityType>();
- private final List<ComplexType> complexTypes = new ArrayList<ComplexType>();
- private final Map<String, Association> name2Associations = new HashMap<String, Association>();
- private final List<EntityContainer> entityContainers = new ArrayList<EntityContainer>();
- private final List<AnnotationAttribute> annotationAttributes = new ArrayList<AnnotationAttribute>();
- private final List<AnnotationElement> annotationElements = new ArrayList<AnnotationElement>();
-
- private SchemaBuilder(String namespace) {
- this.namespace = namespace;
- }
-
- public static SchemaBuilder init(String namespace) {
- return new SchemaBuilder(namespace);
- }
-
- public SchemaBuilder addEntityType(EntityType type) {
- entityTypes.add(type);
- return this;
- }
-
- public SchemaBuilder addEntityContainer(EntityContainer container) {
- entityContainers.add(container);
- return this;
- }
-
- public SchemaBuilder addComplexType(ComplexType createEntityType) {
- complexTypes.add(createEntityType);
- return this;
- }
-
- public void addAssociations(Collection<Association> associations) {
- for (Association association : associations) {
- final String relationshipName = association.getName();
- if (name2Associations.containsKey(relationshipName)) {
- association = mergeAssociations(name2Associations.get(relationshipName), association);
- }
- name2Associations.put(relationshipName, association);
- }
- }
-
- private Association mergeAssociations(Association associationOne, Association associationTwo) {
- AssociationEnd oneEnd1 = associationOne.getEnd1();
- AssociationEnd oneEnd2 = associationOne.getEnd2();
- AssociationEnd twoEnd1 = associationTwo.getEnd1();
- AssociationEnd twoEnd2 = associationTwo.getEnd2();
- AssociationEnd[] oneEnds = new AssociationEnd[] { oneEnd1, oneEnd2 };
-
- for (AssociationEnd associationEnd : oneEnds) {
- if (associationEnd.getRole().equals(twoEnd1.getRole())) {
- if (twoEnd1.getMultiplicity() == EdmMultiplicity.MANY) {
- associationEnd.setMultiplicity(EdmMultiplicity.MANY);
- }
- } else if (associationEnd.getRole().equals(twoEnd2.getRole())) {
- if (twoEnd2.getMultiplicity() == EdmMultiplicity.MANY) {
- associationEnd.setMultiplicity(EdmMultiplicity.MANY);
- }
- }
- }
-
- return associationOne;
- }
-
- public Schema build() {
- Schema s = new Schema();
- s.setUsings(usings);
- s.setEntityTypes(entityTypes);
- s.setComplexTypes(complexTypes);
- s.setAssociations(new ArrayList<Association>(name2Associations.values()));
- s.setEntityContainers(entityContainers);
- s.setAnnotationAttributes(annotationAttributes);
- s.setAnnotationElements(annotationElements);
- s.setNamespace(namespace);
- return s;
- }
- }
-
- private static class ContainerBuilder {
-
- final private String name;
- final private String namespace;
- private boolean defaultContainer = true;
- private final List<EntitySet> entitySets = new ArrayList<EntitySet>();
- private final List<AssociationSet> associationSets = new ArrayList<AssociationSet>();
- private final List<FunctionImport> functionImports = new ArrayList<FunctionImport>();
-
- // private Documentation documentation;
-
- private ContainerBuilder(String namespace, String containerName) {
- this.namespace = namespace;
- name = containerName;
- }
-
- public String getNamespace() {
- return namespace;
- }
-
- public static ContainerBuilder init(String namespace, String containerName) {
- return new ContainerBuilder(namespace, containerName);
- }
-
- public ContainerBuilder setDefaultContainer(boolean isDefault) {
- defaultContainer = isDefault;
- return this;
- }
-
- public ContainerBuilder addEntitySet(EntitySet entitySet) {
- entitySets.add(entitySet);
- return this;
- }
-
- public void addAssociationSets(Collection<Association> associations) {
- for (Association association : associations) {
- AssociationSet as = new AssociationSet();
- as.setName(association.getName());
- FullQualifiedName asAssociationFqn = new FullQualifiedName(namespace, association.getName());
- as.setAssociation(asAssociationFqn);
-
- AssociationSetEnd asEnd1 = new AssociationSetEnd();
- asEnd1.setEntitySet(getEntitySetName(association.getEnd1()));
- asEnd1.setRole(association.getEnd1().getRole());
- as.setEnd1(asEnd1);
-
- AssociationSetEnd asEnd2 = new AssociationSetEnd();
- asEnd2.setEntitySet(getEntitySetName(association.getEnd2()));
- asEnd2.setRole(association.getEnd2().getRole());
- as.setEnd2(asEnd2);
-
- associationSets.add(as);
- }
- }
-
- public EntityContainer build() {
- EntityContainer ec = new EntityContainer();
- ec.setName(name);
- ec.setDefaultEntityContainer(defaultContainer);
- ec.setEntitySets(entitySets);
- ec.setAssociationSets(associationSets);
- ec.setFunctionImports(functionImports);
- return ec;
- }
-
- private String getEntitySetName(AssociationEnd end) {
- for (EntitySet entitySet : entitySets) {
- if (entitySet.getEntityType().equals(end.getType())) {
- return entitySet.getName();
- }
- }
- throw new ODataRuntimeException("No entity set found for " + end.getType());
- }
- }
-}
[04/52] git commit: Removed not used classes/files
Posted by mi...@apache.org.
Removed not used classes/files
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/ae0d7d14
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/ae0d7d14
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/ae0d7d14
Branch: refs/heads/master
Commit: ae0d7d14161d4da7ff05492566bec7e66425c168
Parents: ae7c1f5
Author: Michael Bolz <mi...@sap.com>
Authored: Thu Oct 10 14:24:34 2013 +0200
Committer: Michael Bolz <mi...@sap.com>
Committed: Thu Oct 10 14:24:34 2013 +0200
----------------------------------------------------------------------
.gitignore | 1 +
.../ref/annotation/model/DataContainer.java | 290 -------------------
.../ref/annotation/model/ModelException.java | 32 --
.../ref/annotation/model/ResourceHelper.java | 3 +-
.../src/main/webapp/META-INF/context.xml | 2 -
5 files changed, 2 insertions(+), 326 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ae0d7d14/.gitignore
----------------------------------------------------------------------
diff --git a/.gitignore b/.gitignore
index 3f1a76b..e000e0d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,3 +8,4 @@ bin
classes
.DS_Store
nb-configuration.xml
+context.xml
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ae0d7d14/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/DataContainer.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/DataContainer.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/DataContainer.java
deleted file mode 100644
index d9974e1..0000000
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/DataContainer.java
+++ /dev/null
@@ -1,290 +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.ref.annotation.model;
-
-import org.apache.olingo.odata2.ref.annotation.model.Building;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.List;
-import java.util.TimeZone;
-
-/**
- * Container and initialization code for the data objects of the reference scenario.
- *
- */
-public class DataContainer {
-
- private static final String IMAGE_JPEG = "image/jpeg";
-
- private List<Employee> employees = new ArrayList<Employee>();
- private List<Team> teams = new ArrayList<Team>();
- private List<Room> rooms = new ArrayList<Room>();
- private List<Manager> managers = new ArrayList<Manager>();
- private List<Building> buildings = new ArrayList<Building>();
- private List<Photo> photos = new ArrayList<Photo>();
- private int employeeId = 0;
- private int teamId = 0;
- private int roomId = 0;
- private int buildingId = 0;
- private int photoId = 0;
-
- public void init() {
- // ------------- Teams ---------------
- Team team1 = createTeam();
- team1.setScrumTeam(false);
- teams.add(team1);
-
- Team team2 = createTeam();
- team2.setScrumTeam(true);
- teams.add(team2);
-
- Team team3 = createTeam();
- team3.setScrumTeam(false);
- teams.add(team3);
-
- // ------------- Buildings ---------------
- Building building1 = createBuilding();
- buildings.add(building1);
-
- Building building2 = createBuilding();
- buildings.add(building2);
-
- Building building3 = createBuilding();
- buildings.add(building3);
-
- // ------------- Rooms ---------------
- Room room1 = createRoom();
- room1.setSeats(1);
- room1.setBuilding(building1);
- building1.getRooms().add(room1);
- room1.setVersion(1);
- rooms.add(room1);
-
- Room room2 = createRoom();
- room2.setSeats(5);
- room2.setBuilding(building2);
- building2.getRooms().add(room2);
- room2.setVersion(2);
- rooms.add(room2);
-
- Room room3 = createRoom();
- room3.setSeats(2);
- room3.setBuilding(building2);
- building2.getRooms().add(room3);
- room3.setVersion(3);
- rooms.add(room3);
-
- for (int i = 4; i <= 103; i++) {
- Room roomN = createRoom();
- roomN.setSeats(4 + (i - 3) % 5);
- roomN.setBuilding(building3);
- building3.getRooms().add(roomN);
- roomN.setVersion(1);
- rooms.add(roomN);
- }
-
- // ------------- Employees and Managers ------------
- Manager emp1 = createManager();
- emp1.setEmployeeName("Walter Winter");
- emp1.setAge(52);
- emp1.setTeam(team1);
- team1.getEmployees().add(emp1);
- emp1.setRoom(room1);
- room1.getEmployees().add(emp1);
- emp1.setManager(emp1);
- emp1.getEmployees().add(emp1);
- emp1.setLocation(new Location("Germany", "69124", "Heidelberg"));
- emp1.setEntryDate(generateDate(1999, 1, 1));
- emp1.setImageUri("Employees('1')/$value");
- emp1.setImage("/male_1_WinterW.jpg");
- emp1.setImageType(IMAGE_JPEG);
- employees.add(emp1);
- managers.add(emp1);
-
- Employee emp2 = createEmployee();
- emp2.setEmployeeName("Frederic Fall");
- emp2.setAge(32);
- emp2.setTeam(team1);
- team1.getEmployees().add(emp2);
- emp2.setRoom(room2);
- room2.getEmployees().add(emp2);
- emp2.setManager(emp1);
- emp1.getEmployees().add(emp2);
- emp2.setLocation(new Location("Germany", "69190", "Walldorf"));
- emp2.setEntryDate(generateDate(2003, 7, 1));
- emp2.setImageUri("Employees('2')/$value");
- emp2.setImage("/male_2_FallF.jpg");
- emp2.setImageType(IMAGE_JPEG);
- employees.add(emp2);
-
- Manager emp3 = createManager();
- emp3.setEmployeeName("Jonathan Smith");
- emp3.setAge(56);
- emp3.setTeam(team1);
- team1.getEmployees().add(emp3);
- emp3.setRoom(room2);
- room2.getEmployees().add(emp3);
- emp3.setManager(emp1);
- emp1.getEmployees().add(emp3);
- emp3.setLocation(emp2.getLocation());
- emp3.setEntryDate(null);
- emp3.setImageUri("Employees('3')/$value");
- emp3.setImage("/male_3_SmithJo.jpg");
- emp3.setImageType(IMAGE_JPEG);
- employees.add(emp3);
- managers.add(emp3);
-
- Employee emp4 = createEmployee();
- emp4.setEmployeeName("Peter Burke");
- emp4.setAge(39);
- emp4.setTeam(team2);
- team2.getEmployees().add(emp4);
- emp4.setRoom(room2);
- room2.getEmployees().add(emp4);
- emp4.setManager(emp3);
- emp3.getEmployees().add(emp4);
- emp4.setLocation(emp2.getLocation());
- emp4.setEntryDate(generateDate(2004, 9, 12));
- emp4.setImageUri("Employees('4')/$value");
- emp4.setImage("/male_4_BurkeP.jpg");
- emp4.setImageType(IMAGE_JPEG);
- employees.add(emp4);
-
- Employee emp5 = createEmployee();
- emp5.setEmployeeName("John Field");
- emp5.setAge(42);
- emp5.setTeam(team2);
- team2.getEmployees().add(emp5);
- emp5.setRoom(room3);
- room3.getEmployees().add(emp5);
- emp5.setManager(emp3);
- emp3.getEmployees().add(emp5);
- emp5.setLocation(emp2.getLocation());
- emp5.setEntryDate(generateDate(2001, 2, 1));
- emp5.setImageUri("Employees('5')/$value");
- emp5.setImage("/male_5_FieldJ.jpg");
- emp5.setImageType(IMAGE_JPEG);
- employees.add(emp5);
-
- Employee emp6 = createEmployee();
- emp6.setEmployeeName("Susan Bay");
- emp6.setAge(29);
- emp6.setTeam(team3);
- team3.getEmployees().add(emp6);
- emp6.setRoom(room2);
- room2.getEmployees().add(emp6);
- emp6.setManager(emp1);
- emp1.getEmployees().add(emp6);
- emp6.setLocation(emp2.getLocation());
- emp6.setEntryDate(generateDate(2010, 12, 1));
- emp6.setImageUri("Employees('6')/$value");
- emp6.setImage("/female_6_BaySu.jpg");
- emp6.setImageType(IMAGE_JPEG);
- employees.add(emp6);
-
- // ------------- Photos ---------------
- Photo photo1 = createPhoto("image/png");
- photo1.setContent("Образ");
- photos.add(photo1);
-
- Photo photo2 = createPhoto("image/bmp");
- photos.add(photo2);
-
- Photo photo3 = createPhoto(IMAGE_JPEG);
- photos.add(photo3);
-
- Photo photo4 = createPhoto("foo");
- photo4.setContent("Продукт");
- photos.add(photo4);
- }
-
- private Calendar generateDate(final int year, final int month, final int day) {
- Calendar date = Calendar.getInstance();
-
- date.clear();
- date.setTimeZone(TimeZone.getTimeZone("GMT"));
- date.set(year, month - 1, day); // month is zero-based!
- return date;
- }
-
- public Employee createEmployee() {
- return new Employee(++employeeId, "Employee " + employeeId);
- }
-
- public Team createTeam() {
- return new Team(++teamId, "Team " + teamId);
- }
-
- public Room createRoom() {
- return new Room(++roomId, "Room " + roomId);
- }
-
- public Manager createManager() {
- return new Manager(++employeeId, "Employee " + employeeId);
- }
-
- public Building createBuilding() {
- return new Building(++buildingId, "Building " + buildingId);
- }
-
- public Photo createPhoto(final String type) {
- return new Photo(++photoId, "Photo " + photoId, type);
- }
-
- public List<Employee> getEmployees() {
- return employees;
- }
-
- public List<Team> getTeams() {
- return teams;
- }
-
- public List<Room> getRooms() {
- return rooms;
- }
-
- public List<Manager> getManagers() {
- return managers;
- }
-
- public List<Building> getBuildings() {
- return buildings;
- }
-
- public List<Photo> getPhotos() {
- return photos;
- }
-
- public void reset() {
- employees.clear();
- teams.clear();
- rooms.clear();
- managers.clear();
- buildings.clear();
- photos.clear();
-
- employeeId = 0;
- teamId = 0;
- roomId = 0;
- buildingId = 0;
- photoId = 0;
-
- init();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ae0d7d14/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ModelException.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ModelException.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ModelException.java
deleted file mode 100644
index 3b6d033..0000000
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ModelException.java
+++ /dev/null
@@ -1,32 +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.ref.annotation.model;
-
-/**
- *
- */
-public class ModelException extends RuntimeException {
-
- private static final long serialVersionUID = 1L;
-
- public ModelException(final Exception e) {
- super(e);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ae0d7d14/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ResourceHelper.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ResourceHelper.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ResourceHelper.java
index adc5f11..97ace81 100644
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ResourceHelper.java
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ResourceHelper.java
@@ -26,7 +26,6 @@ import java.util.logging.Logger;
/**
*
- * @author d046871
*/
class ResourceHelper {
@@ -49,7 +48,7 @@ class ResourceHelper {
return stream.toByteArray();
} catch (IOException e) {
- throw new ModelException(e);
+ throw new RuntimeException(e);
} finally {
if(instream != null) {
try {
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ae0d7d14/odata2-edm-annotation/edm-annotation-webref/src/main/webapp/META-INF/context.xml
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/webapp/META-INF/context.xml b/odata2-edm-annotation/edm-annotation-webref/src/main/webapp/META-INF/context.xml
deleted file mode 100644
index 1b76b24..0000000
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/webapp/META-INF/context.xml
+++ /dev/null
@@ -1,2 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<Context antiJARLocking="true" path="/olingo.odata2.edm.annotation.refweb"/>
[50/52] Renamed project
Posted by mi...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/ListsProcessor.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/ListsProcessor.java b/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/ListsProcessor.java
new file mode 100644
index 0000000..19218d7
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/ListsProcessor.java
@@ -0,0 +1,1630 @@
+/*******************************************************************************
+ * 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.core.annotation.processor;
+
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+
+import org.apache.olingo.odata2.api.ODataCallback;
+import org.apache.olingo.odata2.api.batch.BatchHandler;
+import org.apache.olingo.odata2.api.batch.BatchRequestPart;
+import org.apache.olingo.odata2.api.batch.BatchResponsePart;
+import org.apache.olingo.odata2.api.commons.HttpContentType;
+import org.apache.olingo.odata2.api.commons.HttpStatusCodes;
+import org.apache.olingo.odata2.api.commons.InlineCount;
+import org.apache.olingo.odata2.api.data.DataSource;
+import org.apache.olingo.odata2.api.data.DataSource.BinaryData;
+import org.apache.olingo.odata2.api.data.DataSourceProcessor;
+import org.apache.olingo.odata2.api.data.ValueAccess;
+import org.apache.olingo.odata2.api.edm.Edm;
+import org.apache.olingo.odata2.api.edm.EdmConcurrencyMode;
+import org.apache.olingo.odata2.api.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.edm.EdmException;
+import org.apache.olingo.odata2.api.edm.EdmFunctionImport;
+import org.apache.olingo.odata2.api.edm.EdmLiteral;
+import org.apache.olingo.odata2.api.edm.EdmLiteralKind;
+import org.apache.olingo.odata2.api.edm.EdmMapping;
+import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
+import org.apache.olingo.odata2.api.edm.EdmNavigationProperty;
+import org.apache.olingo.odata2.api.edm.EdmProperty;
+import org.apache.olingo.odata2.api.edm.EdmSimpleType;
+import org.apache.olingo.odata2.api.edm.EdmSimpleTypeException;
+import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
+import org.apache.olingo.odata2.api.edm.EdmStructuralType;
+import org.apache.olingo.odata2.api.edm.EdmType;
+import org.apache.olingo.odata2.api.edm.EdmTypeKind;
+import org.apache.olingo.odata2.api.edm.EdmTyped;
+import org.apache.olingo.odata2.api.ep.EntityProvider;
+import org.apache.olingo.odata2.api.ep.EntityProviderBatchProperties;
+import org.apache.olingo.odata2.api.ep.EntityProviderException;
+import org.apache.olingo.odata2.api.ep.EntityProviderReadProperties;
+import org.apache.olingo.odata2.api.ep.EntityProviderWriteProperties;
+import org.apache.olingo.odata2.api.ep.callback.OnWriteEntryContent;
+import org.apache.olingo.odata2.api.ep.callback.OnWriteFeedContent;
+import org.apache.olingo.odata2.api.ep.callback.WriteCallbackContext;
+import org.apache.olingo.odata2.api.ep.callback.WriteEntryCallbackContext;
+import org.apache.olingo.odata2.api.ep.callback.WriteEntryCallbackResult;
+import org.apache.olingo.odata2.api.ep.callback.WriteFeedCallbackContext;
+import org.apache.olingo.odata2.api.ep.callback.WriteFeedCallbackResult;
+import org.apache.olingo.odata2.api.ep.entry.ODataEntry;
+import org.apache.olingo.odata2.api.ep.feed.ODataFeed;
+import org.apache.olingo.odata2.api.exception.ODataApplicationException;
+import org.apache.olingo.odata2.api.exception.ODataBadRequestException;
+import org.apache.olingo.odata2.api.exception.ODataException;
+import org.apache.olingo.odata2.api.exception.ODataHttpException;
+import org.apache.olingo.odata2.api.exception.ODataNotFoundException;
+import org.apache.olingo.odata2.api.exception.ODataNotImplementedException;
+import org.apache.olingo.odata2.api.processor.ODataContext;
+import org.apache.olingo.odata2.api.processor.ODataRequest;
+import org.apache.olingo.odata2.api.processor.ODataResponse;
+import org.apache.olingo.odata2.api.uri.ExpandSelectTreeNode;
+import org.apache.olingo.odata2.api.uri.KeyPredicate;
+import org.apache.olingo.odata2.api.uri.NavigationSegment;
+import org.apache.olingo.odata2.api.uri.PathInfo;
+import org.apache.olingo.odata2.api.uri.UriParser;
+import org.apache.olingo.odata2.api.uri.expression.BinaryExpression;
+import org.apache.olingo.odata2.api.uri.expression.CommonExpression;
+import org.apache.olingo.odata2.api.uri.expression.ExpressionKind;
+import org.apache.olingo.odata2.api.uri.expression.FilterExpression;
+import org.apache.olingo.odata2.api.uri.expression.LiteralExpression;
+import org.apache.olingo.odata2.api.uri.expression.MemberExpression;
+import org.apache.olingo.odata2.api.uri.expression.MethodExpression;
+import org.apache.olingo.odata2.api.uri.expression.OrderByExpression;
+import org.apache.olingo.odata2.api.uri.expression.OrderExpression;
+import org.apache.olingo.odata2.api.uri.expression.PropertyExpression;
+import org.apache.olingo.odata2.api.uri.expression.SortOrder;
+import org.apache.olingo.odata2.api.uri.expression.UnaryExpression;
+import org.apache.olingo.odata2.api.uri.info.DeleteUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetComplexPropertyUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetEntityCountUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetEntityLinkCountUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetEntityLinkUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetEntitySetCountUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetEntitySetLinksCountUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetEntitySetLinksUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetEntitySetUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetEntityUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetFunctionImportUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetMediaResourceUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetSimplePropertyUriInfo;
+import org.apache.olingo.odata2.api.uri.info.PostUriInfo;
+import org.apache.olingo.odata2.api.uri.info.PutMergePatchUriInfo;
+
+/**
+ * Implementation of the centralized parts of OData processing,
+ * allowing to use the simplified {@link DataSource} for the
+ * actual data handling.
+ *
+ */
+public class ListsProcessor extends DataSourceProcessor {
+
+ // TODO: Paging size should be configurable.
+ private static final int SERVER_PAGING_SIZE = 100;
+
+ public ListsProcessor(final DataSource dataSource, final ValueAccess valueAccess) {
+ super(dataSource, valueAccess);
+ }
+
+ @Override
+ public ODataResponse readEntitySet(final GetEntitySetUriInfo uriInfo, final String contentType)
+ throws ODataException {
+ ArrayList<Object> data = new ArrayList<Object>();
+ try {
+ data.addAll((List<?>) retrieveData(
+ uriInfo.getStartEntitySet(),
+ uriInfo.getKeyPredicates(),
+ uriInfo.getFunctionImport(),
+ mapFunctionParameters(uriInfo.getFunctionImportParameters()),
+ uriInfo.getNavigationSegments()));
+ } catch (final ODataNotFoundException e) {
+ data.clear();
+ }
+
+ final EdmEntitySet entitySet = uriInfo.getTargetEntitySet();
+ final InlineCount inlineCountType = uriInfo.getInlineCount();
+ final Integer count = applySystemQueryOptions(
+ entitySet,
+ data,
+ uriInfo.getFilter(),
+ inlineCountType,
+ uriInfo.getOrderBy(),
+ uriInfo.getSkipToken(),
+ uriInfo.getSkip(),
+ uriInfo.getTop());
+
+ ODataContext context = getContext();
+ String nextLink = null;
+
+ // Limit the number of returned entities and provide a "next" link
+ // if there are further entities.
+ // Almost all system query options in the current request must be carried
+ // over to the URI for the "next" link, with the exception of $skiptoken
+ // and $skip.
+ if (data.size() > SERVER_PAGING_SIZE) {
+ if (uriInfo.getOrderBy() == null
+ && uriInfo.getSkipToken() == null
+ && uriInfo.getSkip() == null
+ && uriInfo.getTop() == null) {
+ sortInDefaultOrder(entitySet, data);
+ }
+
+ // TODO: Percent-encode "next" link.
+ nextLink = context.getPathInfo().getServiceRoot().relativize(context.getPathInfo().getRequestUri()).toString()
+ .replaceAll("\\$skiptoken=.+?&?", "")
+ .replaceAll("\\$skip=.+?&?", "")
+ .replaceFirst("(?:\\?|&)$", ""); // Remove potentially trailing "?" or "&" left over from remove actions
+ // above.
+ nextLink += (nextLink.contains("?") ? "&" : "?")
+ + "$skiptoken=" + getSkipToken(entitySet, data.get(SERVER_PAGING_SIZE));
+
+ while (data.size() > SERVER_PAGING_SIZE) {
+ data.remove(SERVER_PAGING_SIZE);
+ }
+ }
+
+ final EdmEntityType entityType = entitySet.getEntityType();
+ List<Map<String, Object>> values = new ArrayList<Map<String, Object>>();
+ for (final Object entryData : data) {
+ values.add(getStructuralTypeValueMap(entryData, entityType));
+ }
+
+ final EntityProviderWriteProperties feedProperties = EntityProviderWriteProperties
+ .serviceRoot(context.getPathInfo().getServiceRoot())
+ .inlineCountType(inlineCountType)
+ .inlineCount(count)
+ .expandSelectTree(UriParser.createExpandSelectTree(uriInfo.getSelect(), uriInfo.getExpand()))
+ .callbacks(getCallbacks(data, entityType))
+ .nextLink(nextLink)
+ .build();
+
+ final int timingHandle = context.startRuntimeMeasurement("EntityProvider", "writeFeed");
+ final ODataResponse response = EntityProvider.writeFeed(contentType, entitySet, values, feedProperties);
+
+ context.stopRuntimeMeasurement(timingHandle);
+
+ return ODataResponse.fromResponse(response).build();
+ }
+
+ @Override
+ public ODataResponse countEntitySet(final GetEntitySetCountUriInfo uriInfo, final String contentType)
+ throws ODataException {
+ ArrayList<Object> data = new ArrayList<Object>();
+ try {
+ data.addAll((List<?>) retrieveData(
+ uriInfo.getStartEntitySet(),
+ uriInfo.getKeyPredicates(),
+ uriInfo.getFunctionImport(),
+ mapFunctionParameters(uriInfo.getFunctionImportParameters()),
+ uriInfo.getNavigationSegments()));
+ } catch (final ODataNotFoundException e) {
+ data.clear();
+ }
+
+ applySystemQueryOptions(
+ uriInfo.getTargetEntitySet(),
+ data,
+ uriInfo.getFilter(),
+ null,
+ null,
+ null,
+ uriInfo.getSkip(),
+ uriInfo.getTop());
+
+ return ODataResponse.fromResponse(EntityProvider.writeText(String.valueOf(data.size()))).build();
+ }
+
+ @Override
+ public ODataResponse readEntityLinks(final GetEntitySetLinksUriInfo uriInfo, final String contentType)
+ throws ODataException {
+ ArrayList<Object> data = new ArrayList<Object>();
+ try {
+ data.addAll((List<?>) retrieveData(
+ uriInfo.getStartEntitySet(),
+ uriInfo.getKeyPredicates(),
+ uriInfo.getFunctionImport(),
+ mapFunctionParameters(uriInfo.getFunctionImportParameters()),
+ uriInfo.getNavigationSegments()));
+ } catch (final ODataNotFoundException e) {
+ data.clear();
+ }
+
+ final Integer count = applySystemQueryOptions(
+ uriInfo.getTargetEntitySet(),
+ data,
+ uriInfo.getFilter(),
+ uriInfo.getInlineCount(),
+ null, // uriInfo.getOrderBy(),
+ uriInfo.getSkipToken(),
+ uriInfo.getSkip(),
+ uriInfo.getTop());
+
+ final EdmEntitySet entitySet = uriInfo.getTargetEntitySet();
+
+ List<Map<String, Object>> values = new ArrayList<Map<String, Object>>();
+ for (final Object entryData : data) {
+ Map<String, Object> entryValues = new HashMap<String, Object>();
+ for (final EdmProperty property : entitySet.getEntityType().getKeyProperties()) {
+ entryValues.put(property.getName(), valueAccess.getPropertyValue(entryData, property));
+ }
+ values.add(entryValues);
+ }
+
+ ODataContext context = getContext();
+ final EntityProviderWriteProperties entryProperties = EntityProviderWriteProperties
+ .serviceRoot(context.getPathInfo().getServiceRoot())
+ .inlineCountType(uriInfo.getInlineCount())
+ .inlineCount(count)
+ .build();
+
+ final int timingHandle = context.startRuntimeMeasurement("EntityProvider", "writeLinks");
+
+ final ODataResponse response = EntityProvider.writeLinks(contentType, entitySet, values, entryProperties);
+
+ context.stopRuntimeMeasurement(timingHandle);
+
+ return ODataResponse.fromResponse(response).build();
+ }
+
+ @Override
+ public ODataResponse countEntityLinks(final GetEntitySetLinksCountUriInfo uriInfo, final String contentType)
+ throws ODataException {
+ return countEntitySet((GetEntitySetCountUriInfo) uriInfo, contentType);
+ }
+
+ @Override
+ public ODataResponse readEntity(final GetEntityUriInfo uriInfo, final String contentType) throws ODataException {
+ final Object data = retrieveData(
+ uriInfo.getStartEntitySet(),
+ uriInfo.getKeyPredicates(),
+ uriInfo.getFunctionImport(),
+ mapFunctionParameters(uriInfo.getFunctionImportParameters()),
+ uriInfo.getNavigationSegments());
+
+ if (!appliesFilter(data, uriInfo.getFilter())) {
+ throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
+ }
+
+ final ExpandSelectTreeNode expandSelectTreeNode =
+ UriParser.createExpandSelectTree(uriInfo.getSelect(), uriInfo.getExpand());
+ ODataResponse odr =
+ ODataResponse.fromResponse(writeEntry(uriInfo.getTargetEntitySet(), expandSelectTreeNode, data, contentType))
+ .build();
+
+ return odr;
+ }
+
+ @Override
+ public ODataResponse existsEntity(final GetEntityCountUriInfo uriInfo, final String contentType)
+ throws ODataException {
+ final Object data = retrieveData(
+ uriInfo.getStartEntitySet(),
+ uriInfo.getKeyPredicates(),
+ uriInfo.getFunctionImport(),
+ mapFunctionParameters(uriInfo.getFunctionImportParameters()),
+ uriInfo.getNavigationSegments());
+
+ return ODataResponse.fromResponse(EntityProvider.writeText(appliesFilter(data, uriInfo.getFilter()) ? "1" : "0"))
+ .build();
+ }
+
+ @Override
+ public ODataResponse deleteEntity(final DeleteUriInfo uriInfo, final String contentType) throws ODataException {
+ dataSource.deleteData(
+ uriInfo.getStartEntitySet(),
+ mapKey(uriInfo.getKeyPredicates()));
+ return ODataResponse.newBuilder().build();
+ }
+
+ @Override
+ public ODataResponse createEntity(final PostUriInfo uriInfo, final InputStream content,
+ final String requestContentType, final String contentType) throws ODataException {
+ final EdmEntitySet entitySet = uriInfo.getTargetEntitySet();
+ final EdmEntityType entityType = entitySet.getEntityType();
+
+ Object data = dataSource.newDataObject(entitySet);
+ ExpandSelectTreeNode expandSelectTree = null;
+
+ if (entityType.hasStream()) {
+ dataSource.createData(entitySet, data);
+ dataSource.writeBinaryData(entitySet, data,
+ new BinaryData(EntityProvider.readBinary(content), requestContentType));
+
+ } else {
+ final EntityProviderReadProperties properties = EntityProviderReadProperties.init()
+ .mergeSemantic(false)
+ .addTypeMappings(getStructuralTypeTypeMap(data, entityType))
+ .build();
+ final ODataEntry entryValues = parseEntry(entitySet, content, requestContentType, properties);
+
+ setStructuralTypeValuesFromMap(data, entityType, entryValues.getProperties(), false);
+
+ dataSource.createData(entitySet, data);
+
+ createInlinedEntities(entitySet, data, entryValues);
+
+ expandSelectTree = entryValues.getExpandSelectTree();
+ }
+
+ // Link back to the entity the target entity set is related to, if any.
+ final List<NavigationSegment> navigationSegments = uriInfo.getNavigationSegments();
+ if (!navigationSegments.isEmpty()) {
+ final List<NavigationSegment> previousSegments = navigationSegments.subList(0, navigationSegments.size() - 1);
+ final Object sourceData = retrieveData(
+ uriInfo.getStartEntitySet(),
+ uriInfo.getKeyPredicates(),
+ uriInfo.getFunctionImport(),
+ mapFunctionParameters(uriInfo.getFunctionImportParameters()),
+ previousSegments);
+ final EdmEntitySet previousEntitySet = previousSegments.isEmpty() ?
+ uriInfo.getStartEntitySet() : previousSegments.get(previousSegments.size() - 1).getEntitySet();
+ dataSource.writeRelation(previousEntitySet, sourceData, entitySet, getStructuralTypeValueMap(data, entityType));
+ }
+
+ return ODataResponse.fromResponse(writeEntry(uriInfo.getTargetEntitySet(), expandSelectTree, data, contentType))
+ .eTag(constructETag(entitySet, data)).build();
+ }
+
+ @Override
+ public ODataResponse updateEntity(final PutMergePatchUriInfo uriInfo, final InputStream content,
+ final String requestContentType, final boolean merge, final String contentType) throws ODataException {
+ Object data = retrieveData(
+ uriInfo.getStartEntitySet(),
+ uriInfo.getKeyPredicates(),
+ uriInfo.getFunctionImport(),
+ mapFunctionParameters(uriInfo.getFunctionImportParameters()),
+ uriInfo.getNavigationSegments());
+
+ if (!appliesFilter(data, uriInfo.getFilter())) {
+ throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
+ }
+
+ final EdmEntitySet entitySet = uriInfo.getTargetEntitySet();
+ final EdmEntityType entityType = entitySet.getEntityType();
+ final EntityProviderReadProperties properties = EntityProviderReadProperties.init()
+ .mergeSemantic(merge)
+ .addTypeMappings(getStructuralTypeTypeMap(data, entityType))
+ .build();
+ final ODataEntry entryValues = parseEntry(entitySet, content, requestContentType, properties);
+
+ setStructuralTypeValuesFromMap(data, entityType, entryValues.getProperties(), merge);
+
+ return ODataResponse.newBuilder().eTag(constructETag(entitySet, data)).build();
+ }
+
+ @Override
+ public ODataResponse readEntityLink(final GetEntityLinkUriInfo uriInfo, final String contentType)
+ throws ODataException {
+ final Object data = retrieveData(
+ uriInfo.getStartEntitySet(),
+ uriInfo.getKeyPredicates(),
+ uriInfo.getFunctionImport(),
+ mapFunctionParameters(uriInfo.getFunctionImportParameters()),
+ uriInfo.getNavigationSegments());
+
+ // if (!appliesFilter(data, uriInfo.getFilter()))
+ if (data == null) {
+ throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
+ }
+
+ final EdmEntitySet entitySet = uriInfo.getTargetEntitySet();
+
+ Map<String, Object> values = new HashMap<String, Object>();
+ for (final EdmProperty property : entitySet.getEntityType().getKeyProperties()) {
+ values.put(property.getName(), valueAccess.getPropertyValue(data, property));
+ }
+
+ ODataContext context = getContext();
+ final EntityProviderWriteProperties entryProperties = EntityProviderWriteProperties
+ .serviceRoot(context.getPathInfo().getServiceRoot())
+ .build();
+
+ final int timingHandle = context.startRuntimeMeasurement("EntityProvider", "writeLink");
+
+ final ODataResponse response = EntityProvider.writeLink(contentType, entitySet, values, entryProperties);
+
+ context.stopRuntimeMeasurement(timingHandle);
+
+ return ODataResponse.fromResponse(response).build();
+ }
+
+ @Override
+ public ODataResponse existsEntityLink(final GetEntityLinkCountUriInfo uriInfo, final String contentType)
+ throws ODataException {
+ return existsEntity((GetEntityCountUriInfo) uriInfo, contentType);
+ }
+
+ @Override
+ public ODataResponse deleteEntityLink(final DeleteUriInfo uriInfo, final String contentType) throws ODataException {
+ final List<NavigationSegment> navigationSegments = uriInfo.getNavigationSegments();
+ final List<NavigationSegment> previousSegments = navigationSegments.subList(0, navigationSegments.size() - 1);
+
+ final Object sourceData = retrieveData(
+ uriInfo.getStartEntitySet(),
+ uriInfo.getKeyPredicates(),
+ uriInfo.getFunctionImport(),
+ mapFunctionParameters(uriInfo.getFunctionImportParameters()),
+ previousSegments);
+
+ final EdmEntitySet entitySet = previousSegments.isEmpty() ?
+ uriInfo.getStartEntitySet() : previousSegments.get(previousSegments.size() - 1).getEntitySet();
+ final EdmEntitySet targetEntitySet = uriInfo.getTargetEntitySet();
+ final Map<String, Object> keys = mapKey(uriInfo.getTargetKeyPredicates());
+
+ final Object targetData = dataSource.readRelatedData(entitySet, sourceData, targetEntitySet, keys);
+
+ // if (!appliesFilter(targetData, uriInfo.getFilter()))
+ if (targetData == null) {
+ throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
+ }
+
+ dataSource.deleteRelation(entitySet, sourceData, targetEntitySet, keys);
+
+ return ODataResponse.newBuilder().build();
+ }
+
+ @Override
+ public ODataResponse createEntityLink(final PostUriInfo uriInfo, final InputStream content,
+ final String requestContentType, final String contentType) throws ODataException {
+ final List<NavigationSegment> navigationSegments = uriInfo.getNavigationSegments();
+ final List<NavigationSegment> previousSegments = navigationSegments.subList(0, navigationSegments.size() - 1);
+
+ final Object sourceData = retrieveData(
+ uriInfo.getStartEntitySet(),
+ uriInfo.getKeyPredicates(),
+ uriInfo.getFunctionImport(),
+ mapFunctionParameters(uriInfo.getFunctionImportParameters()),
+ previousSegments);
+
+ final EdmEntitySet entitySet = previousSegments.isEmpty() ?
+ uriInfo.getStartEntitySet() : previousSegments.get(previousSegments.size() - 1).getEntitySet();
+ final EdmEntitySet targetEntitySet = uriInfo.getTargetEntitySet();
+
+ final Map<String, Object> targetKeys = parseLink(targetEntitySet, content, requestContentType);
+
+ dataSource.writeRelation(entitySet, sourceData, targetEntitySet, targetKeys);
+
+ return ODataResponse.newBuilder().build();
+ }
+
+ @Override
+ public ODataResponse updateEntityLink(final PutMergePatchUriInfo uriInfo, final InputStream content,
+ final String requestContentType, final String contentType) throws ODataException {
+ final List<NavigationSegment> navigationSegments = uriInfo.getNavigationSegments();
+ final List<NavigationSegment> previousSegments = navigationSegments.subList(0, navigationSegments.size() - 1);
+
+ final Object sourceData = retrieveData(
+ uriInfo.getStartEntitySet(),
+ uriInfo.getKeyPredicates(),
+ uriInfo.getFunctionImport(),
+ mapFunctionParameters(uriInfo.getFunctionImportParameters()),
+ previousSegments);
+
+ final EdmEntitySet entitySet = previousSegments.isEmpty() ?
+ uriInfo.getStartEntitySet() : previousSegments.get(previousSegments.size() - 1).getEntitySet();
+ final EdmEntitySet targetEntitySet = uriInfo.getTargetEntitySet();
+ final Map<String, Object> keys = mapKey(uriInfo.getTargetKeyPredicates());
+
+ final Object targetData = dataSource.readRelatedData(entitySet, sourceData, targetEntitySet, keys);
+
+ if (!appliesFilter(targetData, uriInfo.getFilter())) {
+ throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
+ }
+
+ dataSource.deleteRelation(entitySet, sourceData, targetEntitySet, keys);
+
+ final Map<String, Object> newKeys = parseLink(targetEntitySet, content, requestContentType);
+
+ dataSource.writeRelation(entitySet, sourceData, targetEntitySet, newKeys);
+
+ return ODataResponse.newBuilder().build();
+ }
+
+ @Override
+ public ODataResponse readEntityComplexProperty(final GetComplexPropertyUriInfo uriInfo, final String contentType)
+ throws ODataException {
+ Object data = retrieveData(
+ uriInfo.getStartEntitySet(),
+ uriInfo.getKeyPredicates(),
+ uriInfo.getFunctionImport(),
+ mapFunctionParameters(uriInfo.getFunctionImportParameters()),
+ uriInfo.getNavigationSegments());
+
+ // if (!appliesFilter(data, uriInfo.getFilter()))
+ if (data == null) {
+ throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
+ }
+
+ final List<EdmProperty> propertyPath = uriInfo.getPropertyPath();
+ final EdmProperty property = propertyPath.get(propertyPath.size() - 1);
+ final Object value = property.isSimple() ?
+ property.getMapping() == null || property.getMapping().getMimeType() == null ?
+ getPropertyValue(data, propertyPath) : getSimpleTypeValueMap(data, propertyPath) :
+ getStructuralTypeValueMap(getPropertyValue(data, propertyPath), (EdmStructuralType) property.getType());
+
+ ODataContext context = getContext();
+ final int timingHandle = context.startRuntimeMeasurement("EntityProvider", "writeProperty");
+
+ final ODataResponse response = EntityProvider.writeProperty(contentType, property, value);
+
+ context.stopRuntimeMeasurement(timingHandle);
+
+ return ODataResponse.fromResponse(response).eTag(constructETag(uriInfo.getTargetEntitySet(), data)).build();
+ }
+
+ @Override
+ public ODataResponse readEntitySimpleProperty(final GetSimplePropertyUriInfo uriInfo, final String contentType)
+ throws ODataException {
+ return readEntityComplexProperty((GetComplexPropertyUriInfo) uriInfo, contentType);
+ }
+
+ @Override
+ public ODataResponse readEntitySimplePropertyValue(final GetSimplePropertyUriInfo uriInfo, final String contentType)
+ throws ODataException {
+ Object data = retrieveData(
+ uriInfo.getStartEntitySet(),
+ uriInfo.getKeyPredicates(),
+ uriInfo.getFunctionImport(),
+ mapFunctionParameters(uriInfo.getFunctionImportParameters()),
+ uriInfo.getNavigationSegments());
+
+ // if (!appliesFilter(data, uriInfo.getFilter()))
+ if (data == null) {
+ throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
+ }
+
+ final List<EdmProperty> propertyPath = uriInfo.getPropertyPath();
+ final EdmProperty property = propertyPath.get(propertyPath.size() - 1);
+ final Object value = property.getMapping() == null || property.getMapping().getMimeType() == null ?
+ getPropertyValue(data, propertyPath) : getSimpleTypeValueMap(data, propertyPath);
+
+ return ODataResponse.fromResponse(EntityProvider.writePropertyValue(property, value)).eTag(
+ constructETag(uriInfo.getTargetEntitySet(), data)).build();
+ }
+
+ @Override
+ public ODataResponse deleteEntitySimplePropertyValue(final DeleteUriInfo uriInfo, final String contentType)
+ throws ODataException {
+ Object data = retrieveData(
+ uriInfo.getStartEntitySet(),
+ uriInfo.getKeyPredicates(),
+ uriInfo.getFunctionImport(),
+ mapFunctionParameters(uriInfo.getFunctionImportParameters()),
+ uriInfo.getNavigationSegments());
+
+ if (data == null) {
+ throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
+ }
+
+ final List<EdmProperty> propertyPath = uriInfo.getPropertyPath();
+ final EdmProperty property = propertyPath.get(propertyPath.size() - 1);
+
+ data = getPropertyValue(data, propertyPath.subList(0, propertyPath.size() - 1));
+ valueAccess.setPropertyValue(data, property, null);
+ valueAccess.setMappingValue(data, property.getMapping(), null);
+
+ return ODataResponse.newBuilder().build();
+ }
+
+ @Override
+ public ODataResponse updateEntityComplexProperty(final PutMergePatchUriInfo uriInfo, final InputStream content,
+ final String requestContentType, final boolean merge, final String contentType) throws ODataException {
+ Object data = retrieveData(
+ uriInfo.getStartEntitySet(),
+ uriInfo.getKeyPredicates(),
+ uriInfo.getFunctionImport(),
+ mapFunctionParameters(uriInfo.getFunctionImportParameters()),
+ uriInfo.getNavigationSegments());
+
+ if (!appliesFilter(data, uriInfo.getFilter())) {
+ throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
+ }
+
+ final List<EdmProperty> propertyPath = uriInfo.getPropertyPath();
+ final EdmProperty property = propertyPath.get(propertyPath.size() - 1);
+
+ data = getPropertyValue(data, propertyPath.subList(0, propertyPath.size() - 1));
+
+ ODataContext context = getContext();
+ int timingHandle = context.startRuntimeMeasurement("EntityConsumer", "readProperty");
+
+ Map<String, Object> values;
+ try {
+ values =
+ EntityProvider.readProperty(requestContentType, property, content, EntityProviderReadProperties.init()
+ .mergeSemantic(merge).build());
+ } catch (final EntityProviderException e) {
+ throw new ODataBadRequestException(ODataBadRequestException.BODY, e);
+ }
+
+ context.stopRuntimeMeasurement(timingHandle);
+
+ final Object value = values.get(property.getName());
+ if (property.isSimple()) {
+ valueAccess.setPropertyValue(data, property, value);
+ } else {
+ @SuppressWarnings("unchecked")
+ final Map<String, Object> propertyValue = (Map<String, Object>) value;
+ setStructuralTypeValuesFromMap(valueAccess.getPropertyValue(data, property),
+ (EdmStructuralType) property.getType(), propertyValue, merge);
+ }
+
+ return ODataResponse.newBuilder().eTag(constructETag(uriInfo.getTargetEntitySet(), data)).build();
+ }
+
+ @Override
+ public ODataResponse updateEntitySimpleProperty(final PutMergePatchUriInfo uriInfo, final InputStream content,
+ final String requestContentType, final String contentType) throws ODataException {
+ return updateEntityComplexProperty(uriInfo, content, requestContentType, false, contentType);
+ }
+
+ @Override
+ public ODataResponse updateEntitySimplePropertyValue(final PutMergePatchUriInfo uriInfo, final InputStream content,
+ final String requestContentType, final String contentType) throws ODataException {
+ Object data = retrieveData(
+ uriInfo.getStartEntitySet(),
+ uriInfo.getKeyPredicates(),
+ uriInfo.getFunctionImport(),
+ mapFunctionParameters(uriInfo.getFunctionImportParameters()),
+ uriInfo.getNavigationSegments());
+
+ if (!appliesFilter(data, uriInfo.getFilter())) {
+ throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
+ }
+
+ final List<EdmProperty> propertyPath = uriInfo.getPropertyPath();
+ final EdmProperty property = propertyPath.get(propertyPath.size() - 1);
+
+ data = getPropertyValue(data, propertyPath.subList(0, propertyPath.size() - 1));
+
+ ODataContext context = getContext();
+ int timingHandle = context.startRuntimeMeasurement("EntityConsumer", "readPropertyValue");
+
+ Object value;
+ try {
+ value = EntityProvider.readPropertyValue(property, content);
+ } catch (final EntityProviderException e) {
+ throw new ODataBadRequestException(ODataBadRequestException.BODY, e);
+ }
+
+ context.stopRuntimeMeasurement(timingHandle);
+
+ valueAccess.setPropertyValue(data, property, value);
+ valueAccess.setMappingValue(data, property.getMapping(), requestContentType);
+
+ return ODataResponse.newBuilder().eTag(constructETag(uriInfo.getTargetEntitySet(), data)).build();
+ }
+
+ @Override
+ public ODataResponse readEntityMedia(final GetMediaResourceUriInfo uriInfo, final String contentType)
+ throws ODataException {
+ final Object data = retrieveData(
+ uriInfo.getStartEntitySet(),
+ uriInfo.getKeyPredicates(),
+ uriInfo.getFunctionImport(),
+ mapFunctionParameters(uriInfo.getFunctionImportParameters()),
+ uriInfo.getNavigationSegments());
+
+ if (!appliesFilter(data, uriInfo.getFilter())) {
+ throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
+ }
+
+ final EdmEntitySet entitySet = uriInfo.getTargetEntitySet();
+ final BinaryData binaryData = dataSource.readBinaryData(entitySet, data);
+ if (binaryData == null) {
+ throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
+ }
+
+ final String mimeType = binaryData.getMimeType() == null ?
+ HttpContentType.APPLICATION_OCTET_STREAM : binaryData.getMimeType();
+
+ return ODataResponse.fromResponse(EntityProvider.writeBinary(mimeType, binaryData.getData())).eTag(
+ constructETag(entitySet, data)).build();
+ }
+
+ @Override
+ public ODataResponse deleteEntityMedia(final DeleteUriInfo uriInfo, final String contentType) throws ODataException {
+ final Object data = retrieveData(
+ uriInfo.getStartEntitySet(),
+ uriInfo.getKeyPredicates(),
+ uriInfo.getFunctionImport(),
+ mapFunctionParameters(uriInfo.getFunctionImportParameters()),
+ uriInfo.getNavigationSegments());
+
+ if (data == null) {
+ throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
+ }
+
+ dataSource.writeBinaryData(uriInfo.getTargetEntitySet(), data, new BinaryData(null, null));
+
+ return ODataResponse.newBuilder().build();
+ }
+
+ @Override
+ public ODataResponse updateEntityMedia(final PutMergePatchUriInfo uriInfo, final InputStream content,
+ final String requestContentType, final String contentType) throws ODataException {
+ final Object data = retrieveData(
+ uriInfo.getStartEntitySet(),
+ uriInfo.getKeyPredicates(),
+ uriInfo.getFunctionImport(),
+ mapFunctionParameters(uriInfo.getFunctionImportParameters()),
+ uriInfo.getNavigationSegments());
+
+ if (!appliesFilter(data, uriInfo.getFilter())) {
+ throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
+ }
+
+ ODataContext context = getContext();
+ final int timingHandle = context.startRuntimeMeasurement("EntityProvider", "readBinary");
+
+ final byte[] value = EntityProvider.readBinary(content);
+
+ context.stopRuntimeMeasurement(timingHandle);
+
+ final EdmEntitySet entitySet = uriInfo.getTargetEntitySet();
+ dataSource.writeBinaryData(entitySet, data, new BinaryData(value, requestContentType));
+
+ return ODataResponse.newBuilder().eTag(constructETag(entitySet, data)).build();
+ }
+
+ @Override
+ public ODataResponse executeFunctionImport(final GetFunctionImportUriInfo uriInfo, final String contentType)
+ throws ODataException {
+ final EdmFunctionImport functionImport = uriInfo.getFunctionImport();
+ final EdmType type = functionImport.getReturnType().getType();
+
+ final Object data = dataSource.readData(
+ functionImport,
+ mapFunctionParameters(uriInfo.getFunctionImportParameters()),
+ null);
+
+ if (data == null) {
+ throw new ODataNotFoundException(ODataHttpException.COMMON);
+ }
+
+ Object value;
+ if (type.getKind() == EdmTypeKind.SIMPLE) {
+ value = type == EdmSimpleTypeKind.Binary.getEdmSimpleTypeInstance() ?
+ ((BinaryData) data).getData() : data;
+ } else if (functionImport.getReturnType().getMultiplicity() == EdmMultiplicity.MANY) {
+ List<Map<String, Object>> values = new ArrayList<Map<String, Object>>();
+ for (final Object typeData : (List<?>) data) {
+ values.add(getStructuralTypeValueMap(typeData, (EdmStructuralType) type));
+ }
+ value = values;
+ } else {
+ value = getStructuralTypeValueMap(data, (EdmStructuralType) type);
+ }
+
+ ODataContext context = getContext();
+
+ final EntityProviderWriteProperties entryProperties = EntityProviderWriteProperties
+ .serviceRoot(context.getPathInfo().getServiceRoot()).build();
+
+ final int timingHandle = context.startRuntimeMeasurement("EntityProvider", "writeFunctionImport");
+
+ final ODataResponse response =
+ EntityProvider.writeFunctionImport(contentType, functionImport, value, entryProperties);
+
+ context.stopRuntimeMeasurement(timingHandle);
+
+ return ODataResponse.fromResponse(response).build();
+ }
+
+ @Override
+ public ODataResponse executeFunctionImportValue(final GetFunctionImportUriInfo uriInfo, final String contentType)
+ throws ODataException {
+ final EdmFunctionImport functionImport = uriInfo.getFunctionImport();
+ final EdmSimpleType type = (EdmSimpleType) functionImport.getReturnType().getType();
+
+ final Object data = dataSource.readData(
+ functionImport,
+ mapFunctionParameters(uriInfo.getFunctionImportParameters()),
+ null);
+
+ if (data == null) {
+ throw new ODataNotFoundException(ODataHttpException.COMMON);
+ }
+
+ ODataResponse response;
+ if (type == EdmSimpleTypeKind.Binary.getEdmSimpleTypeInstance()) {
+ response = EntityProvider.writeBinary(((BinaryData) data).getMimeType(), ((BinaryData) data).getData());
+ } else {
+ final String value = type.valueToString(data, EdmLiteralKind.DEFAULT, null);
+ response = EntityProvider.writeText(value == null ? "" : value);
+ }
+ return ODataResponse.fromResponse(response).build();
+ }
+
+ private static Map<String, Object> mapKey(final List<KeyPredicate> keys) throws EdmException {
+ Map<String, Object> keyMap = new HashMap<String, Object>();
+ for (final KeyPredicate key : keys) {
+ final EdmProperty property = key.getProperty();
+ final EdmSimpleType type = (EdmSimpleType) property.getType();
+ keyMap.put(property.getName(), type.valueOfString(key.getLiteral(), EdmLiteralKind.DEFAULT, property.getFacets(),
+ type.getDefaultType()));
+ }
+ return keyMap;
+ }
+
+ private static Map<String, Object> mapFunctionParameters(final Map<String, EdmLiteral> functionImportParameters)
+ throws EdmSimpleTypeException {
+ if (functionImportParameters == null) {
+ return Collections.emptyMap();
+ } else {
+ Map<String, Object> parameterMap = new HashMap<String, Object>();
+ for (final String parameterName : functionImportParameters.keySet()) {
+ final EdmLiteral literal = functionImportParameters.get(parameterName);
+ final EdmSimpleType type = literal.getType();
+ parameterMap.put(parameterName, type.valueOfString(literal.getLiteral(), EdmLiteralKind.DEFAULT, null, type
+ .getDefaultType()));
+ }
+ return parameterMap;
+ }
+ }
+
+ private Object retrieveData(final EdmEntitySet startEntitySet, final List<KeyPredicate> keyPredicates,
+ final EdmFunctionImport functionImport, final Map<String, Object> functionImportParameters,
+ final List<NavigationSegment> navigationSegments) throws ODataException {
+ Object data;
+ final Map<String, Object> keys = mapKey(keyPredicates);
+
+ ODataContext context = getContext();
+ final int timingHandle = context.startRuntimeMeasurement(getClass().getSimpleName(), "retrieveData");
+
+ data = functionImport == null ?
+ keys.isEmpty() ?
+ dataSource.readData(startEntitySet) : dataSource.readData(startEntitySet, keys) :
+ dataSource.readData(functionImport, functionImportParameters, keys);
+
+ EdmEntitySet currentEntitySet =
+ functionImport == null ? startEntitySet : functionImport.getEntitySet();
+ for (NavigationSegment navigationSegment : navigationSegments) {
+ data = dataSource.readRelatedData(
+ currentEntitySet,
+ data,
+ navigationSegment.getEntitySet(),
+ mapKey(navigationSegment.getKeyPredicates()));
+ currentEntitySet = navigationSegment.getEntitySet();
+ }
+
+ context.stopRuntimeMeasurement(timingHandle);
+
+ return data;
+ }
+
+ private <T> String constructETag(final EdmEntitySet entitySet, final T data) throws ODataException {
+ final EdmEntityType entityType = entitySet.getEntityType();
+ String eTag = null;
+ for (final String propertyName : entityType.getPropertyNames()) {
+ final EdmProperty property = (EdmProperty) entityType.getProperty(propertyName);
+ if (property.getFacets() != null && property.getFacets().getConcurrencyMode() == EdmConcurrencyMode.Fixed) {
+ final EdmSimpleType type = (EdmSimpleType) property.getType();
+ final String component = type.valueToString(valueAccess.getPropertyValue(data, property),
+ EdmLiteralKind.DEFAULT, property.getFacets());
+ eTag = eTag == null ? component : eTag + Edm.DELIMITER + component;
+ }
+ }
+ return eTag == null ? null : "W/\"" + eTag + "\"";
+ }
+
+ private <T> Map<String, ODataCallback> getCallbacks(final T data, final EdmEntityType entityType)
+ throws EdmException {
+ final List<String> navigationPropertyNames = entityType.getNavigationPropertyNames();
+ if (navigationPropertyNames.isEmpty()) {
+ return null;
+ } else {
+ final WriteCallback callback = new WriteCallback(data);
+ Map<String, ODataCallback> callbacks = new HashMap<String, ODataCallback>();
+ for (final String name : navigationPropertyNames) {
+ callbacks.put(name, callback);
+ }
+ return callbacks;
+ }
+ }
+
+ private class WriteCallback implements OnWriteEntryContent, OnWriteFeedContent {
+ private final Object data;
+
+ private <T> WriteCallback(final T data) {
+ this.data = data;
+ }
+
+ @Override
+ public WriteFeedCallbackResult retrieveFeedResult(final WriteFeedCallbackContext context)
+ throws ODataApplicationException {
+ try {
+ final EdmEntityType entityType =
+ context.getSourceEntitySet().getRelatedEntitySet(context.getNavigationProperty()).getEntityType();
+ List<Map<String, Object>> values = new ArrayList<Map<String, Object>>();
+ Object relatedData = null;
+ try {
+ relatedData = readRelatedData(context);
+ for (final Object entryData : (List<?>) relatedData) {
+ values.add(getStructuralTypeValueMap(entryData, entityType));
+ }
+ } catch (final ODataNotFoundException e) {
+ values.clear();
+ }
+ WriteFeedCallbackResult result = new WriteFeedCallbackResult();
+ result.setFeedData(values);
+ EntityProviderWriteProperties inlineProperties =
+ EntityProviderWriteProperties.serviceRoot(getContext().getPathInfo().getServiceRoot()).callbacks(
+ getCallbacks(relatedData, entityType)).expandSelectTree(context.getCurrentExpandSelectTreeNode())
+ .selfLink(context.getSelfLink()).build();
+ result.setInlineProperties(inlineProperties);
+ return result;
+ } catch (final ODataException e) {
+ throw new ODataApplicationException(e.getLocalizedMessage(), Locale.ROOT, e);
+ }
+ }
+
+ @Override
+ public WriteEntryCallbackResult retrieveEntryResult(final WriteEntryCallbackContext context)
+ throws ODataApplicationException {
+ try {
+ final EdmEntityType entityType =
+ context.getSourceEntitySet().getRelatedEntitySet(context.getNavigationProperty()).getEntityType();
+ WriteEntryCallbackResult result = new WriteEntryCallbackResult();
+ Object relatedData;
+ try {
+ relatedData = readRelatedData(context);
+ } catch (final ODataNotFoundException e) {
+ relatedData = null;
+ }
+
+ if (relatedData == null) {
+ result.setEntryData(Collections.<String, Object> emptyMap());
+ } else {
+ result.setEntryData(getStructuralTypeValueMap(relatedData, entityType));
+
+ EntityProviderWriteProperties inlineProperties =
+ EntityProviderWriteProperties.serviceRoot(getContext().getPathInfo().getServiceRoot()).callbacks(
+ getCallbacks(relatedData, entityType)).expandSelectTree(context.getCurrentExpandSelectTreeNode())
+ .build();
+ result.setInlineProperties(inlineProperties);
+ }
+ return result;
+ } catch (final ODataException e) {
+ throw new ODataApplicationException(e.getLocalizedMessage(), Locale.ROOT, e);
+ }
+ }
+
+ private Object readRelatedData(final WriteCallbackContext context) throws ODataException {
+ final EdmEntitySet entitySet = context.getSourceEntitySet();
+ return dataSource.readRelatedData(
+ entitySet,
+ data instanceof List ? readEntryData((List<?>) data, entitySet.getEntityType(), context
+ .extractKeyFromEntryData()) : data,
+ entitySet.getRelatedEntitySet(context.getNavigationProperty()),
+ Collections.<String, Object> emptyMap());
+ }
+
+ private <T> T readEntryData(final List<T> data, final EdmEntityType entityType, final Map<String, Object> key)
+ throws ODataException {
+ for (final T entryData : data) {
+ boolean found = true;
+ for (final EdmProperty keyProperty : entityType.getKeyProperties()) {
+ if (!valueAccess.getPropertyValue(entryData, keyProperty).equals(key.get(keyProperty.getName()))) {
+ found = false;
+ break;
+ }
+ }
+ if (found) {
+ return entryData;
+ }
+ }
+ return null;
+ }
+ }
+
+ private <T> ODataResponse writeEntry(final EdmEntitySet entitySet, final ExpandSelectTreeNode expandSelectTree,
+ final T data, final String contentType) throws ODataException, EntityProviderException {
+ final EdmEntityType entityType = entitySet.getEntityType();
+ final Map<String, Object> values = getStructuralTypeValueMap(data, entityType);
+
+ ODataContext context = getContext();
+ EntityProviderWriteProperties writeProperties = EntityProviderWriteProperties
+ .serviceRoot(context.getPathInfo().getServiceRoot())
+ .expandSelectTree(expandSelectTree)
+ .callbacks(getCallbacks(data, entityType))
+ .build();
+
+ final int timingHandle = context.startRuntimeMeasurement("EntityProvider", "writeEntry");
+
+ final ODataResponse response = EntityProvider.writeEntry(contentType, entitySet, values, writeProperties);
+
+ context.stopRuntimeMeasurement(timingHandle);
+
+ return response;
+ }
+
+ private ODataEntry parseEntry(final EdmEntitySet entitySet, final InputStream content,
+ final String requestContentType, final EntityProviderReadProperties properties) throws ODataBadRequestException {
+ ODataContext context = getContext();
+ final int timingHandle = context.startRuntimeMeasurement("EntityConsumer", "readEntry");
+
+ ODataEntry entryValues;
+ try {
+ entryValues = EntityProvider.readEntry(requestContentType, entitySet, content, properties);
+ } catch (final EntityProviderException e) {
+ throw new ODataBadRequestException(ODataBadRequestException.BODY, e);
+ }
+
+ context.stopRuntimeMeasurement(timingHandle);
+
+ return entryValues;
+ }
+
+ private Map<String, Object> parseLink(final EdmEntitySet entitySet, final InputStream content,
+ final String contentType) throws ODataException {
+ ODataContext context = getContext();
+ final int timingHandle = context.startRuntimeMeasurement("EntityProvider", "readLink");
+
+ final String uriString = EntityProvider.readLink(contentType, entitySet, content);
+
+ context.stopRuntimeMeasurement(timingHandle);
+
+ final Map<String, Object> targetKeys = parseLinkUri(entitySet, uriString);
+ if (targetKeys == null) {
+ throw new ODataBadRequestException(ODataBadRequestException.BODY);
+ }
+ return targetKeys;
+ }
+
+ private Map<String, Object> parseLinkUri(final EdmEntitySet targetEntitySet, final String uriString)
+ throws EdmException {
+ ODataContext context = getContext();
+ final int timingHandle = context.startRuntimeMeasurement("UriParser", "getKeyPredicatesFromEntityLink");
+
+ List<KeyPredicate> key = null;
+ try {
+ key = UriParser.getKeyPredicatesFromEntityLink(targetEntitySet, uriString,
+ context.getPathInfo().getServiceRoot());
+ } catch (ODataException e) {
+ // We don't understand the link target. This could also be seen as an error.
+ }
+
+ context.stopRuntimeMeasurement(timingHandle);
+
+ return key == null ? null : mapKey(key);
+ }
+
+ private <T> void createInlinedEntities(final EdmEntitySet entitySet, final T data, final ODataEntry entryValues)
+ throws ODataException {
+ final EdmEntityType entityType = entitySet.getEntityType();
+ for (final String navigationPropertyName : entityType.getNavigationPropertyNames()) {
+
+ final EdmNavigationProperty navigationProperty =
+ (EdmNavigationProperty) entityType.getProperty(navigationPropertyName);
+ final EdmEntitySet relatedEntitySet = entitySet.getRelatedEntitySet(navigationProperty);
+ final EdmEntityType relatedEntityType = relatedEntitySet.getEntityType();
+
+ final Object relatedValue = entryValues.getProperties().get(navigationPropertyName);
+ if (relatedValue == null) {
+ for (final String uriString : entryValues.getMetadata().getAssociationUris(navigationPropertyName)) {
+ final Map<String, Object> key = parseLinkUri(relatedEntitySet, uriString);
+ if (key != null) {
+ dataSource.writeRelation(entitySet, data, relatedEntitySet, key);
+ }
+ }
+
+ } else {
+ if (relatedValue instanceof ODataFeed) {
+ ODataFeed feed = (ODataFeed) relatedValue;
+ final List<ODataEntry> relatedValueList = feed.getEntries();
+ for (final ODataEntry relatedValues : relatedValueList) {
+ Object relatedData = dataSource.newDataObject(relatedEntitySet);
+ setStructuralTypeValuesFromMap(relatedData, relatedEntityType, relatedValues.getProperties(), false);
+ dataSource.createData(relatedEntitySet, relatedData);
+ dataSource.writeRelation(entitySet, data, relatedEntitySet, getStructuralTypeValueMap(relatedData,
+ relatedEntityType));
+ createInlinedEntities(relatedEntitySet, relatedData, relatedValues);
+ }
+ } else if (relatedValue instanceof ODataEntry) {
+ final ODataEntry relatedValueEntry = (ODataEntry) relatedValue;
+ Object relatedData = dataSource.newDataObject(relatedEntitySet);
+ setStructuralTypeValuesFromMap(relatedData, relatedEntityType, relatedValueEntry.getProperties(), false);
+ dataSource.createData(relatedEntitySet, relatedData);
+ dataSource.writeRelation(entitySet, data, relatedEntitySet, getStructuralTypeValueMap(relatedData,
+ relatedEntityType));
+ createInlinedEntities(relatedEntitySet, relatedData, relatedValueEntry);
+ } else {
+ throw new ODataException("Unexpected class for a related value: " + relatedValue.getClass().getSimpleName());
+ }
+
+ }
+ }
+ }
+
+ private <T> Integer applySystemQueryOptions(final EdmEntitySet entitySet, final List<T> data,
+ final FilterExpression filter, final InlineCount inlineCount, final OrderByExpression orderBy,
+ final String skipToken, final Integer skip, final Integer top) throws ODataException {
+ ODataContext context = getContext();
+ final int timingHandle = context.startRuntimeMeasurement(getClass().getSimpleName(), "applySystemQueryOptions");
+
+ if (filter != null) {
+ // Remove all elements the filter does not apply for.
+ // A for-each loop would not work with "remove", see Java documentation.
+ for (Iterator<T> iterator = data.iterator(); iterator.hasNext();) {
+ if (!appliesFilter(iterator.next(), filter)) {
+ iterator.remove();
+ }
+ }
+ }
+
+ final Integer count = inlineCount == InlineCount.ALLPAGES ? data.size() : null;
+
+ if (orderBy != null) {
+ sort(data, orderBy);
+ } else if (skipToken != null || skip != null || top != null) {
+ sortInDefaultOrder(entitySet, data);
+ }
+
+ if (skipToken != null) {
+ while (!data.isEmpty() && !getSkipToken(entitySet, data.get(0)).equals(skipToken)) {
+ data.remove(0);
+ }
+ }
+
+ if (skip != null) {
+ if (skip >= data.size()) {
+ data.clear();
+ } else {
+ for (int i = 0; i < skip; i++) {
+ data.remove(0);
+ }
+ }
+ }
+
+ if (top != null) {
+ while (data.size() > top) {
+ data.remove(top.intValue());
+ }
+ }
+
+ context.stopRuntimeMeasurement(timingHandle);
+
+ return count;
+ }
+
+ private <T> void sort(final List<T> data, final OrderByExpression orderBy) {
+ Collections.sort(data, new Comparator<T>() {
+ @Override
+ public int compare(final T entity1, final T entity2) {
+ try {
+ int result = 0;
+ for (final OrderExpression expression : orderBy.getOrders()) {
+ result = evaluateExpression(entity1, expression.getExpression()).compareTo(
+ evaluateExpression(entity2, expression.getExpression()));
+ if (expression.getSortOrder() == SortOrder.desc) {
+ result = -result;
+ }
+ if (result != 0) {
+ break;
+ }
+ }
+ return result;
+ } catch (final ODataException e) {
+ return 0;
+ }
+ }
+ });
+ }
+
+ private <T> void sortInDefaultOrder(final EdmEntitySet entitySet, final List<T> data) {
+ Collections.sort(data, new Comparator<T>() {
+ @Override
+ public int compare(final T entity1, final T entity2) {
+ try {
+ return getSkipToken(entitySet, entity1).compareTo(getSkipToken(entitySet, entity2));
+ } catch (final ODataException e) {
+ return 0;
+ }
+ }
+ });
+ }
+
+ private <T> boolean appliesFilter(final T data, final FilterExpression filter) throws ODataException {
+ ODataContext context = getContext();
+ final int timingHandle = context.startRuntimeMeasurement(getClass().getSimpleName(), "appliesFilter");
+
+ try {
+ return data != null && (filter == null || evaluateExpression(data, filter.getExpression()).equals("true"));
+ } catch (final RuntimeException e) {
+ return false;
+ } finally {
+ context.stopRuntimeMeasurement(timingHandle);
+ }
+ }
+
+ private <T> String evaluateExpression(final T data, final CommonExpression expression) throws ODataException {
+ switch (expression.getKind()) {
+ case UNARY:
+ final UnaryExpression unaryExpression = (UnaryExpression) expression;
+ final String operand = evaluateExpression(data, unaryExpression.getOperand());
+
+ switch (unaryExpression.getOperator()) {
+ case NOT:
+ return Boolean.toString(!Boolean.parseBoolean(operand));
+ case MINUS:
+ return operand.startsWith("-") ? operand.substring(1) : "-" + operand;
+ default:
+ throw new ODataNotImplementedException();
+ }
+
+ case BINARY:
+ final BinaryExpression binaryExpression = (BinaryExpression) expression;
+ final EdmSimpleType type = (EdmSimpleType) binaryExpression.getLeftOperand().getEdmType();
+ final String left = evaluateExpression(data, binaryExpression.getLeftOperand());
+ final String right = evaluateExpression(data, binaryExpression.getRightOperand());
+
+ switch (binaryExpression.getOperator()) {
+ case ADD:
+ if (binaryExpression.getEdmType() == EdmSimpleTypeKind.Decimal.getEdmSimpleTypeInstance()
+ || binaryExpression.getEdmType() == EdmSimpleTypeKind.Double.getEdmSimpleTypeInstance()
+ || binaryExpression.getEdmType() == EdmSimpleTypeKind.Single.getEdmSimpleTypeInstance()) {
+ return Double.toString(Double.valueOf(left) + Double.valueOf(right));
+ } else {
+ return Long.toString(Long.valueOf(left) + Long.valueOf(right));
+ }
+ case SUB:
+ if (binaryExpression.getEdmType() == EdmSimpleTypeKind.Decimal.getEdmSimpleTypeInstance()
+ || binaryExpression.getEdmType() == EdmSimpleTypeKind.Double.getEdmSimpleTypeInstance()
+ || binaryExpression.getEdmType() == EdmSimpleTypeKind.Single.getEdmSimpleTypeInstance()) {
+ return Double.toString(Double.valueOf(left) - Double.valueOf(right));
+ } else {
+ return Long.toString(Long.valueOf(left) - Long.valueOf(right));
+ }
+ case MUL:
+ if (binaryExpression.getEdmType() == EdmSimpleTypeKind.Decimal.getEdmSimpleTypeInstance()
+ || binaryExpression.getEdmType() == EdmSimpleTypeKind.Double.getEdmSimpleTypeInstance()
+ || binaryExpression.getEdmType() == EdmSimpleTypeKind.Single.getEdmSimpleTypeInstance()) {
+ return Double.toString(Double.valueOf(left) * Double.valueOf(right));
+ } else {
+ return Long.toString(Long.valueOf(left) * Long.valueOf(right));
+ }
+ case DIV:
+ final String number = Double.toString(Double.valueOf(left) / Double.valueOf(right));
+ return number.endsWith(".0") ? number.replace(".0", "") : number;
+ case MODULO:
+ if (binaryExpression.getEdmType() == EdmSimpleTypeKind.Decimal.getEdmSimpleTypeInstance()
+ || binaryExpression.getEdmType() == EdmSimpleTypeKind.Double.getEdmSimpleTypeInstance()
+ || binaryExpression.getEdmType() == EdmSimpleTypeKind.Single.getEdmSimpleTypeInstance()) {
+ return Double.toString(Double.valueOf(left) % Double.valueOf(right));
+ } else {
+ return Long.toString(Long.valueOf(left) % Long.valueOf(right));
+ }
+ case AND:
+ return Boolean.toString(left.equals("true") && right.equals("true"));
+ case OR:
+ return Boolean.toString(left.equals("true") || right.equals("true"));
+ case EQ:
+ return Boolean.toString(left.equals(right));
+ case NE:
+ return Boolean.toString(!left.equals(right));
+ case LT:
+ if (type == EdmSimpleTypeKind.String.getEdmSimpleTypeInstance()
+ || type == EdmSimpleTypeKind.DateTime.getEdmSimpleTypeInstance()
+ || type == EdmSimpleTypeKind.DateTimeOffset.getEdmSimpleTypeInstance()
+ || type == EdmSimpleTypeKind.Guid.getEdmSimpleTypeInstance()
+ || type == EdmSimpleTypeKind.Time.getEdmSimpleTypeInstance()) {
+ return Boolean.toString(left.compareTo(right) < 0);
+ } else {
+ return Boolean.toString(Double.valueOf(left) < Double.valueOf(right));
+ }
+ case LE:
+ if (type == EdmSimpleTypeKind.String.getEdmSimpleTypeInstance()
+ || type == EdmSimpleTypeKind.DateTime.getEdmSimpleTypeInstance()
+ || type == EdmSimpleTypeKind.DateTimeOffset.getEdmSimpleTypeInstance()
+ || type == EdmSimpleTypeKind.Guid.getEdmSimpleTypeInstance()
+ || type == EdmSimpleTypeKind.Time.getEdmSimpleTypeInstance()) {
+ return Boolean.toString(left.compareTo(right) <= 0);
+ } else {
+ return Boolean.toString(Double.valueOf(left) <= Double.valueOf(right));
+ }
+ case GT:
+ if (type == EdmSimpleTypeKind.String.getEdmSimpleTypeInstance()
+ || type == EdmSimpleTypeKind.DateTime.getEdmSimpleTypeInstance()
+ || type == EdmSimpleTypeKind.DateTimeOffset.getEdmSimpleTypeInstance()
+ || type == EdmSimpleTypeKind.Guid.getEdmSimpleTypeInstance()
+ || type == EdmSimpleTypeKind.Time.getEdmSimpleTypeInstance()) {
+ return Boolean.toString(left.compareTo(right) > 0);
+ } else {
+ return Boolean.toString(Double.valueOf(left) > Double.valueOf(right));
+ }
+ case GE:
+ if (type == EdmSimpleTypeKind.String.getEdmSimpleTypeInstance()
+ || type == EdmSimpleTypeKind.DateTime.getEdmSimpleTypeInstance()
+ || type == EdmSimpleTypeKind.DateTimeOffset.getEdmSimpleTypeInstance()
+ || type == EdmSimpleTypeKind.Guid.getEdmSimpleTypeInstance()
+ || type == EdmSimpleTypeKind.Time.getEdmSimpleTypeInstance()) {
+ return Boolean.toString(left.compareTo(right) >= 0);
+ } else {
+ return Boolean.toString(Double.valueOf(left) >= Double.valueOf(right));
+ }
+ case PROPERTY_ACCESS:
+ throw new ODataNotImplementedException();
+ default:
+ throw new ODataNotImplementedException();
+ }
+
+ case PROPERTY:
+ final EdmProperty property = (EdmProperty) ((PropertyExpression) expression).getEdmProperty();
+ final EdmSimpleType propertyType = (EdmSimpleType) property.getType();
+ return propertyType.valueToString(valueAccess.getPropertyValue(data, property), EdmLiteralKind.DEFAULT,
+ property.getFacets());
+
+ case MEMBER:
+ final MemberExpression memberExpression = (MemberExpression) expression;
+ final PropertyExpression propertyExpression = (PropertyExpression) memberExpression.getProperty();
+ final EdmProperty memberProperty = (EdmProperty) propertyExpression.getEdmProperty();
+ final EdmSimpleType memberType = (EdmSimpleType) memberExpression.getEdmType();
+ List<EdmProperty> propertyPath = new ArrayList<EdmProperty>();
+ CommonExpression currentExpression = memberExpression;
+ while (currentExpression != null) {
+ final PropertyExpression currentPropertyExpression =
+ (PropertyExpression) (currentExpression.getKind() == ExpressionKind.MEMBER ?
+ ((MemberExpression) currentExpression).getProperty() : currentExpression);
+ final EdmTyped currentProperty = currentPropertyExpression.getEdmProperty();
+ final EdmTypeKind kind = currentProperty.getType().getKind();
+ if (kind == EdmTypeKind.SIMPLE || kind == EdmTypeKind.COMPLEX) {
+ propertyPath.add(0, (EdmProperty) currentProperty);
+ } else {
+ throw new ODataNotImplementedException();
+ }
+ currentExpression =
+ currentExpression.getKind() == ExpressionKind.MEMBER ? ((MemberExpression) currentExpression).getPath()
+ : null;
+ }
+ return memberType.valueToString(getPropertyValue(data, propertyPath), EdmLiteralKind.DEFAULT, memberProperty
+ .getFacets());
+
+ case LITERAL:
+ final LiteralExpression literal = (LiteralExpression) expression;
+ final EdmSimpleType literalType = (EdmSimpleType) literal.getEdmType();
+ return literalType.valueToString(literalType.valueOfString(literal.getUriLiteral(), EdmLiteralKind.URI, null,
+ literalType.getDefaultType()),
+ EdmLiteralKind.DEFAULT, null);
+
+ case METHOD:
+ final MethodExpression methodExpression = (MethodExpression) expression;
+ final String first = evaluateExpression(data, methodExpression.getParameters().get(0));
+ final String second = methodExpression.getParameterCount() > 1 ?
+ evaluateExpression(data, methodExpression.getParameters().get(1)) : null;
+ final String third = methodExpression.getParameterCount() > 2 ?
+ evaluateExpression(data, methodExpression.getParameters().get(2)) : null;
+
+ switch (methodExpression.getMethod()) {
+ case ENDSWITH:
+ return Boolean.toString(first.endsWith(second));
+ case INDEXOF:
+ return Integer.toString(first.indexOf(second));
+ case STARTSWITH:
+ return Boolean.toString(first.startsWith(second));
+ case TOLOWER:
+ return first.toLowerCase(Locale.ROOT);
+ case TOUPPER:
+ return first.toUpperCase(Locale.ROOT);
+ case TRIM:
+ return first.trim();
+ case SUBSTRING:
+ final int offset = Integer.parseInt(second);
+ return first.substring(offset, offset + Integer.parseInt(third));
+ case SUBSTRINGOF:
+ return Boolean.toString(second.contains(first));
+ case CONCAT:
+ return first + second;
+ case LENGTH:
+ return Integer.toString(first.length());
+ case YEAR:
+ return String.valueOf(Integer.parseInt(first.substring(0, 4)));
+ case MONTH:
+ return String.valueOf(Integer.parseInt(first.substring(5, 7)));
+ case DAY:
+ return String.valueOf(Integer.parseInt(first.substring(8, 10)));
+ case HOUR:
+ return String.valueOf(Integer.parseInt(first.substring(11, 13)));
+ case MINUTE:
+ return String.valueOf(Integer.parseInt(first.substring(14, 16)));
+ case SECOND:
+ return String.valueOf(Integer.parseInt(first.substring(17, 19)));
+ case ROUND:
+ return Long.toString(Math.round(Double.valueOf(first)));
+ case FLOOR:
+ return Long.toString(Math.round(Math.floor(Double.valueOf(first))));
+ case CEILING:
+ return Long.toString(Math.round(Math.ceil(Double.valueOf(first))));
+ default:
+ throw new ODataNotImplementedException();
+ }
+
+ default:
+ throw new ODataNotImplementedException();
+ }
+ }
+
+ private <T> String getSkipToken(final EdmEntitySet entitySet, final T data) throws ODataException {
+ String skipToken = "";
+ for (final EdmProperty property : entitySet.getEntityType().getKeyProperties()) {
+ final EdmSimpleType type = (EdmSimpleType) property.getType();
+ skipToken = skipToken.concat(type.valueToString(valueAccess.getPropertyValue(data, property),
+ EdmLiteralKind.DEFAULT, property.getFacets()));
+ }
+ return skipToken;
+ }
+
+ private <T> Object getPropertyValue(final T data, final List<EdmProperty> propertyPath) throws ODataException {
+ Object dataObject = data;
+ for (final EdmProperty property : propertyPath) {
+ if (dataObject != null) {
+ dataObject = valueAccess.getPropertyValue(dataObject, property);
+ }
+ }
+ return dataObject;
+ }
+
+ private void handleMimeType(Object data, EdmMapping mapping, Map<String, Object> valueMap)
+ throws ODataException {
+ final String mimeTypeName = mapping.getMimeType();
+ if (mimeTypeName != null) {
+ Object value = valueAccess.getMappingValue(data, mapping);
+ valueMap.put(mimeTypeName, value);
+ if (mapping.getMediaResourceMimeTypeKey() != null) {
+ valueMap.put(mapping.getMediaResourceMimeTypeKey(), value);
+ }
+ }
+ }
+
+ private <T> Map<String, Object> getSimpleTypeValueMap(final T data, final List<EdmProperty> propertyPath)
+ throws ODataException {
+ final EdmProperty property = propertyPath.get(propertyPath.size() - 1);
+ Map<String, Object> valueWithMimeType = new HashMap<String, Object>();
+ valueWithMimeType.put(property.getName(), getPropertyValue(data, propertyPath));
+
+ handleMimeType(data, property.getMapping(), valueWithMimeType);
+
+ return valueWithMimeType;
+ }
+
+ private <T> Map<String, Object> getStructuralTypeValueMap(final T data, final EdmStructuralType type)
+ throws ODataException {
+ ODataContext context = getContext();
+ final int timingHandle = context.startRuntimeMeasurement(getClass().getSimpleName(), "getStructuralTypeValueMap");
+
+ Map<String, Object> valueMap = new HashMap<String, Object>();
+
+ EdmMapping mapping = type.getMapping();
+ if (mapping != null) {
+ handleMimeType(data, mapping, valueMap);
+ }
+
+ for (final String propertyName : type.getPropertyNames()) {
+ final EdmProperty property = (EdmProperty) type.getProperty(propertyName);
+ final Object value = valueAccess.getPropertyValue(data, property);
+
+ if (property.isSimple()) {
+ if (property.getMapping() == null || property.getMapping().getMimeType() == null) {
+ valueMap.put(propertyName, value);
+ } else {
+ // TODO: enable MIME type mapping outside the current subtree
+ valueMap.put(propertyName, getSimpleTypeValueMap(data, Arrays.asList(property)));
+ }
+ } else {
+ valueMap.put(propertyName, getStructuralTypeValueMap(value, (EdmStructuralType) property.getType()));
+ }
+ }
+
+ context.stopRuntimeMeasurement(timingHandle);
+
+ return valueMap;
+ }
+
+ private <T> Map<String, Object> getStructuralTypeTypeMap(final T data, final EdmStructuralType type)
+ throws ODataException {
+ ODataContext context = getContext();
+ final int timingHandle = context.startRuntimeMeasurement(getClass().getSimpleName(), "getStructuralTypeTypeMap");
+
+ Map<String, Object> typeMap = new HashMap<String, Object>();
+ for (final String propertyName : type.getPropertyNames()) {
+ final EdmProperty property = (EdmProperty) type.getProperty(propertyName);
+ if (property.isSimple()) {
+ typeMap.put(propertyName, valueAccess.getPropertyType(data, property));
+ } else {
+ typeMap.put(propertyName, getStructuralTypeTypeMap(valueAccess.getPropertyValue(data, property),
+ (EdmStructuralType) property.getType()));
+ }
+ }
+
+ context.stopRuntimeMeasurement(timingHandle);
+
+ return typeMap;
+ }
+
+ private <T> void setStructuralTypeValuesFromMap(final T data, final EdmStructuralType type,
+ final Map<String, Object> valueMap, final boolean merge) throws ODataException {
+ ODataContext context = getContext();
+ final int timingHandle =
+ context.startRuntimeMeasurement(getClass().getSimpleName(), "setStructuralTypeValuesFromMap");
+
+ for (final String propertyName : type.getPropertyNames()) {
+ final EdmProperty property = (EdmProperty) type.getProperty(propertyName);
+ if (type instanceof EdmEntityType && ((EdmEntityType) type).getKeyProperties().contains(property)) {
+ Object v = valueAccess.getPropertyValue(data, property);
+ if(v != null) {
+ continue;
+ }
+ }
+
+ if (!merge || valueMap != null && valueMap.containsKey(propertyName)) {
+ final Object value = valueMap == null ? null : valueMap.get(propertyName);
+ if (property.isSimple()) {
+ valueAccess.setPropertyValue(data, property, value);
+ } else {
+ @SuppressWarnings("unchecked")
+ final Map<String, Object> values = (Map<String, Object>) value;
+ setStructuralTypeValuesFromMap(valueAccess.getPropertyValue(data, property),
+ (EdmStructuralType) property.getType(), values, merge);
+ }
+ }
+ }
+
+ context.stopRuntimeMeasurement(timingHandle);
+ }
+
+ @Override
+ public ODataResponse executeBatch(final BatchHandler handler, final String contentType, final InputStream content)
+ throws ODataException {
+ ODataResponse batchResponse;
+ List<BatchResponsePart> batchResponseParts = new ArrayList<BatchResponsePart>();
+ PathInfo pathInfo = getContext().getPathInfo();
+ EntityProviderBatchProperties batchProperties = EntityProviderBatchProperties.init().pathInfo(pathInfo).build();
+ List<BatchRequestPart> batchParts = EntityProvider.parseBatchRequest(contentType, content, batchProperties);
+ for (BatchRequestPart batchPart : batchParts) {
+ batchResponseParts.add(handler.handleBatchPart(batchPart));
+ }
+ batchResponse = EntityProvider.writeBatchResponse(batchResponseParts);
+ return batchResponse;
+ }
+
+ @Override
+ public BatchResponsePart executeChangeSet(final BatchHandler handler, final List<ODataRequest> requests)
+ throws ODataException {
+ List<ODataResponse> responses = new ArrayList<ODataResponse>();
+ for (ODataRequest request : requests) {
+ ODataResponse response = handler.handleRequest(request);
+ if (response.getStatus().getStatusCode() >= HttpStatusCodes.BAD_REQUEST.getStatusCode()) {
+ // Rollback
+ List<ODataResponse> errorResponses = new ArrayList<ODataResponse>(1);
+ errorResponses.add(response);
+ return BatchResponsePart.responses(errorResponses).changeSet(false).build();
+ }
+ responses.add(response);
+ }
+ return BatchResponsePart.responses(responses).changeSet(true).build();
+ }
+}
[12/52] Poc for ListsDs and Processor
Posted by mi...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d83070de/odata2-lib/odata-ref/src/main/java/org/apache/olingo/odata2/ref/processor/ListsProcessor.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-ref/src/main/java/org/apache/olingo/odata2/ref/processor/ListsProcessor.java b/odata2-lib/odata-ref/src/main/java/org/apache/olingo/odata2/ref/processor/ListsProcessor.java
deleted file mode 100644
index 3238293..0000000
--- a/odata2-lib/odata-ref/src/main/java/org/apache/olingo/odata2/ref/processor/ListsProcessor.java
+++ /dev/null
@@ -1,1623 +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.ref.processor;
-
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-
-import org.apache.olingo.odata2.api.ODataCallback;
-import org.apache.olingo.odata2.api.batch.BatchHandler;
-import org.apache.olingo.odata2.api.batch.BatchRequestPart;
-import org.apache.olingo.odata2.api.batch.BatchResponsePart;
-import org.apache.olingo.odata2.api.commons.HttpContentType;
-import org.apache.olingo.odata2.api.commons.HttpStatusCodes;
-import org.apache.olingo.odata2.api.commons.InlineCount;
-import org.apache.olingo.odata2.api.edm.Edm;
-import org.apache.olingo.odata2.api.edm.EdmConcurrencyMode;
-import org.apache.olingo.odata2.api.edm.EdmEntitySet;
-import org.apache.olingo.odata2.api.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.edm.EdmException;
-import org.apache.olingo.odata2.api.edm.EdmFunctionImport;
-import org.apache.olingo.odata2.api.edm.EdmLiteral;
-import org.apache.olingo.odata2.api.edm.EdmLiteralKind;
-import org.apache.olingo.odata2.api.edm.EdmMapping;
-import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
-import org.apache.olingo.odata2.api.edm.EdmNavigationProperty;
-import org.apache.olingo.odata2.api.edm.EdmProperty;
-import org.apache.olingo.odata2.api.edm.EdmSimpleType;
-import org.apache.olingo.odata2.api.edm.EdmSimpleTypeException;
-import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
-import org.apache.olingo.odata2.api.edm.EdmStructuralType;
-import org.apache.olingo.odata2.api.edm.EdmType;
-import org.apache.olingo.odata2.api.edm.EdmTypeKind;
-import org.apache.olingo.odata2.api.edm.EdmTyped;
-import org.apache.olingo.odata2.api.ep.EntityProvider;
-import org.apache.olingo.odata2.api.ep.EntityProviderBatchProperties;
-import org.apache.olingo.odata2.api.ep.EntityProviderException;
-import org.apache.olingo.odata2.api.ep.EntityProviderReadProperties;
-import org.apache.olingo.odata2.api.ep.EntityProviderWriteProperties;
-import org.apache.olingo.odata2.api.ep.callback.OnWriteEntryContent;
-import org.apache.olingo.odata2.api.ep.callback.OnWriteFeedContent;
-import org.apache.olingo.odata2.api.ep.callback.WriteCallbackContext;
-import org.apache.olingo.odata2.api.ep.callback.WriteEntryCallbackContext;
-import org.apache.olingo.odata2.api.ep.callback.WriteEntryCallbackResult;
-import org.apache.olingo.odata2.api.ep.callback.WriteFeedCallbackContext;
-import org.apache.olingo.odata2.api.ep.callback.WriteFeedCallbackResult;
-import org.apache.olingo.odata2.api.ep.entry.ODataEntry;
-import org.apache.olingo.odata2.api.ep.feed.ODataFeed;
-import org.apache.olingo.odata2.api.exception.ODataApplicationException;
-import org.apache.olingo.odata2.api.exception.ODataBadRequestException;
-import org.apache.olingo.odata2.api.exception.ODataException;
-import org.apache.olingo.odata2.api.exception.ODataHttpException;
-import org.apache.olingo.odata2.api.exception.ODataNotFoundException;
-import org.apache.olingo.odata2.api.exception.ODataNotImplementedException;
-import org.apache.olingo.odata2.api.processor.ODataContext;
-import org.apache.olingo.odata2.api.processor.ODataRequest;
-import org.apache.olingo.odata2.api.processor.ODataResponse;
-import org.apache.olingo.odata2.api.processor.ODataSingleProcessor;
-import org.apache.olingo.odata2.api.uri.ExpandSelectTreeNode;
-import org.apache.olingo.odata2.api.uri.KeyPredicate;
-import org.apache.olingo.odata2.api.uri.NavigationSegment;
-import org.apache.olingo.odata2.api.uri.PathInfo;
-import org.apache.olingo.odata2.api.uri.UriParser;
-import org.apache.olingo.odata2.api.uri.expression.BinaryExpression;
-import org.apache.olingo.odata2.api.uri.expression.CommonExpression;
-import org.apache.olingo.odata2.api.uri.expression.ExpressionKind;
-import org.apache.olingo.odata2.api.uri.expression.FilterExpression;
-import org.apache.olingo.odata2.api.uri.expression.LiteralExpression;
-import org.apache.olingo.odata2.api.uri.expression.MemberExpression;
-import org.apache.olingo.odata2.api.uri.expression.MethodExpression;
-import org.apache.olingo.odata2.api.uri.expression.OrderByExpression;
-import org.apache.olingo.odata2.api.uri.expression.OrderExpression;
-import org.apache.olingo.odata2.api.uri.expression.PropertyExpression;
-import org.apache.olingo.odata2.api.uri.expression.SortOrder;
-import org.apache.olingo.odata2.api.uri.expression.UnaryExpression;
-import org.apache.olingo.odata2.api.uri.info.DeleteUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetComplexPropertyUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetEntityCountUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetEntityLinkCountUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetEntityLinkUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetEntitySetCountUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetEntitySetLinksCountUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetEntitySetLinksUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetEntitySetUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetEntityUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetFunctionImportUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetMediaResourceUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetSimplePropertyUriInfo;
-import org.apache.olingo.odata2.api.uri.info.PostUriInfo;
-import org.apache.olingo.odata2.api.uri.info.PutMergePatchUriInfo;
-import org.apache.olingo.odata2.ref.processor.ListsDataSource.BinaryData;
-
-/**
- * Implementation of the centralized parts of OData processing,
- * allowing to use the simplified {@link ListsDataSource} for the
- * actual data handling.
- *
- */
-public class ListsProcessor extends ODataSingleProcessor {
-
- // TODO: Paging size should be configurable.
- private static final int SERVER_PAGING_SIZE = 100;
-
- private final ListsDataSource dataSource;
- private final ValueAccess valueAccess;
-
- public ListsProcessor(final ListsDataSource dataSource, final ValueAccess valueAccess) {
- this.dataSource = dataSource;
- this.valueAccess = valueAccess;
- }
-
- @Override
- public ODataResponse readEntitySet(final GetEntitySetUriInfo uriInfo, final String contentType)
- throws ODataException {
- ArrayList<Object> data = new ArrayList<Object>();
- try {
- data.addAll((List<?>) retrieveData(
- uriInfo.getStartEntitySet(),
- uriInfo.getKeyPredicates(),
- uriInfo.getFunctionImport(),
- mapFunctionParameters(uriInfo.getFunctionImportParameters()),
- uriInfo.getNavigationSegments()));
- } catch (final ODataNotFoundException e) {
- data.clear();
- }
-
- final EdmEntitySet entitySet = uriInfo.getTargetEntitySet();
- final InlineCount inlineCountType = uriInfo.getInlineCount();
- final Integer count = applySystemQueryOptions(
- entitySet,
- data,
- uriInfo.getFilter(),
- inlineCountType,
- uriInfo.getOrderBy(),
- uriInfo.getSkipToken(),
- uriInfo.getSkip(),
- uriInfo.getTop());
-
- ODataContext context = getContext();
- String nextLink = null;
-
- // Limit the number of returned entities and provide a "next" link
- // if there are further entities.
- // Almost all system query options in the current request must be carried
- // over to the URI for the "next" link, with the exception of $skiptoken
- // and $skip.
- if (data.size() > SERVER_PAGING_SIZE) {
- if (uriInfo.getOrderBy() == null
- && uriInfo.getSkipToken() == null
- && uriInfo.getSkip() == null
- && uriInfo.getTop() == null) {
- sortInDefaultOrder(entitySet, data);
- }
-
- // TODO: Percent-encode "next" link.
- nextLink = context.getPathInfo().getServiceRoot().relativize(context.getPathInfo().getRequestUri()).toString()
- .replaceAll("\\$skiptoken=.+?&?", "")
- .replaceAll("\\$skip=.+?&?", "")
- .replaceFirst("(?:\\?|&)$", ""); // Remove potentially trailing "?" or "&" left over from remove actions
- // above.
- nextLink += (nextLink.contains("?") ? "&" : "?")
- + "$skiptoken=" + getSkipToken(entitySet, data.get(SERVER_PAGING_SIZE));
-
- while (data.size() > SERVER_PAGING_SIZE) {
- data.remove(SERVER_PAGING_SIZE);
- }
- }
-
- final EdmEntityType entityType = entitySet.getEntityType();
- List<Map<String, Object>> values = new ArrayList<Map<String, Object>>();
- for (final Object entryData : data) {
- values.add(getStructuralTypeValueMap(entryData, entityType));
- }
-
- final EntityProviderWriteProperties feedProperties = EntityProviderWriteProperties
- .serviceRoot(context.getPathInfo().getServiceRoot())
- .inlineCountType(inlineCountType)
- .inlineCount(count)
- .expandSelectTree(UriParser.createExpandSelectTree(uriInfo.getSelect(), uriInfo.getExpand()))
- .callbacks(getCallbacks(data, entityType))
- .nextLink(nextLink)
- .build();
-
- final int timingHandle = context.startRuntimeMeasurement("EntityProvider", "writeFeed");
- final ODataResponse response = EntityProvider.writeFeed(contentType, entitySet, values, feedProperties);
-
- context.stopRuntimeMeasurement(timingHandle);
-
- return ODataResponse.fromResponse(response).build();
- }
-
- @Override
- public ODataResponse countEntitySet(final GetEntitySetCountUriInfo uriInfo, final String contentType)
- throws ODataException {
- ArrayList<Object> data = new ArrayList<Object>();
- try {
- data.addAll((List<?>) retrieveData(
- uriInfo.getStartEntitySet(),
- uriInfo.getKeyPredicates(),
- uriInfo.getFunctionImport(),
- mapFunctionParameters(uriInfo.getFunctionImportParameters()),
- uriInfo.getNavigationSegments()));
- } catch (final ODataNotFoundException e) {
- data.clear();
- }
-
- applySystemQueryOptions(
- uriInfo.getTargetEntitySet(),
- data,
- uriInfo.getFilter(),
- null,
- null,
- null,
- uriInfo.getSkip(),
- uriInfo.getTop());
-
- return ODataResponse.fromResponse(EntityProvider.writeText(String.valueOf(data.size()))).build();
- }
-
- @Override
- public ODataResponse readEntityLinks(final GetEntitySetLinksUriInfo uriInfo, final String contentType)
- throws ODataException {
- ArrayList<Object> data = new ArrayList<Object>();
- try {
- data.addAll((List<?>) retrieveData(
- uriInfo.getStartEntitySet(),
- uriInfo.getKeyPredicates(),
- uriInfo.getFunctionImport(),
- mapFunctionParameters(uriInfo.getFunctionImportParameters()),
- uriInfo.getNavigationSegments()));
- } catch (final ODataNotFoundException e) {
- data.clear();
- }
-
- final Integer count = applySystemQueryOptions(
- uriInfo.getTargetEntitySet(),
- data,
- uriInfo.getFilter(),
- uriInfo.getInlineCount(),
- null, // uriInfo.getOrderBy(),
- uriInfo.getSkipToken(),
- uriInfo.getSkip(),
- uriInfo.getTop());
-
- final EdmEntitySet entitySet = uriInfo.getTargetEntitySet();
-
- List<Map<String, Object>> values = new ArrayList<Map<String, Object>>();
- for (final Object entryData : data) {
- Map<String, Object> entryValues = new HashMap<String, Object>();
- for (final EdmProperty property : entitySet.getEntityType().getKeyProperties()) {
- entryValues.put(property.getName(), valueAccess.getPropertyValue(entryData, property));
- }
- values.add(entryValues);
- }
-
- ODataContext context = getContext();
- final EntityProviderWriteProperties entryProperties = EntityProviderWriteProperties
- .serviceRoot(context.getPathInfo().getServiceRoot())
- .inlineCountType(uriInfo.getInlineCount())
- .inlineCount(count)
- .build();
-
- final int timingHandle = context.startRuntimeMeasurement("EntityProvider", "writeLinks");
-
- final ODataResponse response = EntityProvider.writeLinks(contentType, entitySet, values, entryProperties);
-
- context.stopRuntimeMeasurement(timingHandle);
-
- return ODataResponse.fromResponse(response).build();
- }
-
- @Override
- public ODataResponse countEntityLinks(final GetEntitySetLinksCountUriInfo uriInfo, final String contentType)
- throws ODataException {
- return countEntitySet((GetEntitySetCountUriInfo) uriInfo, contentType);
- }
-
- @Override
- public ODataResponse readEntity(final GetEntityUriInfo uriInfo, final String contentType) throws ODataException {
- final Object data = retrieveData(
- uriInfo.getStartEntitySet(),
- uriInfo.getKeyPredicates(),
- uriInfo.getFunctionImport(),
- mapFunctionParameters(uriInfo.getFunctionImportParameters()),
- uriInfo.getNavigationSegments());
-
- if (!appliesFilter(data, uriInfo.getFilter())) {
- throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
- }
-
- final ExpandSelectTreeNode expandSelectTreeNode =
- UriParser.createExpandSelectTree(uriInfo.getSelect(), uriInfo.getExpand());
- ODataResponse odr =
- ODataResponse.fromResponse(writeEntry(uriInfo.getTargetEntitySet(), expandSelectTreeNode, data, contentType))
- .build();
-
- return odr;
- }
-
- @Override
- public ODataResponse existsEntity(final GetEntityCountUriInfo uriInfo, final String contentType)
- throws ODataException {
- final Object data = retrieveData(
- uriInfo.getStartEntitySet(),
- uriInfo.getKeyPredicates(),
- uriInfo.getFunctionImport(),
- mapFunctionParameters(uriInfo.getFunctionImportParameters()),
- uriInfo.getNavigationSegments());
-
- return ODataResponse.fromResponse(EntityProvider.writeText(appliesFilter(data, uriInfo.getFilter()) ? "1" : "0"))
- .build();
- }
-
- @Override
- public ODataResponse deleteEntity(final DeleteUriInfo uriInfo, final String contentType) throws ODataException {
- dataSource.deleteData(
- uriInfo.getStartEntitySet(),
- mapKey(uriInfo.getKeyPredicates()));
- return ODataResponse.newBuilder().build();
- }
-
- @Override
- public ODataResponse createEntity(final PostUriInfo uriInfo, final InputStream content,
- final String requestContentType, final String contentType) throws ODataException {
- final EdmEntitySet entitySet = uriInfo.getTargetEntitySet();
- final EdmEntityType entityType = entitySet.getEntityType();
-
- Object data = dataSource.newDataObject(entitySet);
- ExpandSelectTreeNode expandSelectTree = null;
-
- if (entityType.hasStream()) {
- dataSource.createData(entitySet, data);
- dataSource.writeBinaryData(entitySet, data,
- new BinaryData(EntityProvider.readBinary(content), requestContentType));
-
- } else {
- final EntityProviderReadProperties properties = EntityProviderReadProperties.init()
- .mergeSemantic(false)
- .addTypeMappings(getStructuralTypeTypeMap(data, entityType))
- .build();
- final ODataEntry entryValues = parseEntry(entitySet, content, requestContentType, properties);
-
- setStructuralTypeValuesFromMap(data, entityType, entryValues.getProperties(), false);
-
- dataSource.createData(entitySet, data);
-
- createInlinedEntities(entitySet, data, entryValues);
-
- expandSelectTree = entryValues.getExpandSelectTree();
- }
-
- // Link back to the entity the target entity set is related to, if any.
- final List<NavigationSegment> navigationSegments = uriInfo.getNavigationSegments();
- if (!navigationSegments.isEmpty()) {
- final List<NavigationSegment> previousSegments = navigationSegments.subList(0, navigationSegments.size() - 1);
- final Object sourceData = retrieveData(
- uriInfo.getStartEntitySet(),
- uriInfo.getKeyPredicates(),
- uriInfo.getFunctionImport(),
- mapFunctionParameters(uriInfo.getFunctionImportParameters()),
- previousSegments);
- final EdmEntitySet previousEntitySet = previousSegments.isEmpty() ?
- uriInfo.getStartEntitySet() : previousSegments.get(previousSegments.size() - 1).getEntitySet();
- dataSource.writeRelation(previousEntitySet, sourceData, entitySet, getStructuralTypeValueMap(data, entityType));
- }
-
- return ODataResponse.fromResponse(writeEntry(uriInfo.getTargetEntitySet(), expandSelectTree, data, contentType))
- .eTag(constructETag(entitySet, data)).build();
- }
-
- @Override
- public ODataResponse updateEntity(final PutMergePatchUriInfo uriInfo, final InputStream content,
- final String requestContentType, final boolean merge, final String contentType) throws ODataException {
- Object data = retrieveData(
- uriInfo.getStartEntitySet(),
- uriInfo.getKeyPredicates(),
- uriInfo.getFunctionImport(),
- mapFunctionParameters(uriInfo.getFunctionImportParameters()),
- uriInfo.getNavigationSegments());
-
- if (!appliesFilter(data, uriInfo.getFilter())) {
- throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
- }
-
- final EdmEntitySet entitySet = uriInfo.getTargetEntitySet();
- final EdmEntityType entityType = entitySet.getEntityType();
- final EntityProviderReadProperties properties = EntityProviderReadProperties.init()
- .mergeSemantic(merge)
- .addTypeMappings(getStructuralTypeTypeMap(data, entityType))
- .build();
- final ODataEntry entryValues = parseEntry(entitySet, content, requestContentType, properties);
-
- setStructuralTypeValuesFromMap(data, entityType, entryValues.getProperties(), merge);
-
- return ODataResponse.newBuilder().eTag(constructETag(entitySet, data)).build();
- }
-
- @Override
- public ODataResponse readEntityLink(final GetEntityLinkUriInfo uriInfo, final String contentType)
- throws ODataException {
- final Object data = retrieveData(
- uriInfo.getStartEntitySet(),
- uriInfo.getKeyPredicates(),
- uriInfo.getFunctionImport(),
- mapFunctionParameters(uriInfo.getFunctionImportParameters()),
- uriInfo.getNavigationSegments());
-
- // if (!appliesFilter(data, uriInfo.getFilter()))
- if (data == null) {
- throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
- }
-
- final EdmEntitySet entitySet = uriInfo.getTargetEntitySet();
-
- Map<String, Object> values = new HashMap<String, Object>();
- for (final EdmProperty property : entitySet.getEntityType().getKeyProperties()) {
- values.put(property.getName(), valueAccess.getPropertyValue(data, property));
- }
-
- ODataContext context = getContext();
- final EntityProviderWriteProperties entryProperties = EntityProviderWriteProperties
- .serviceRoot(context.getPathInfo().getServiceRoot())
- .build();
-
- final int timingHandle = context.startRuntimeMeasurement("EntityProvider", "writeLink");
-
- final ODataResponse response = EntityProvider.writeLink(contentType, entitySet, values, entryProperties);
-
- context.stopRuntimeMeasurement(timingHandle);
-
- return ODataResponse.fromResponse(response).build();
- }
-
- @Override
- public ODataResponse existsEntityLink(final GetEntityLinkCountUriInfo uriInfo, final String contentType)
- throws ODataException {
- return existsEntity((GetEntityCountUriInfo) uriInfo, contentType);
- }
-
- @Override
- public ODataResponse deleteEntityLink(final DeleteUriInfo uriInfo, final String contentType) throws ODataException {
- final List<NavigationSegment> navigationSegments = uriInfo.getNavigationSegments();
- final List<NavigationSegment> previousSegments = navigationSegments.subList(0, navigationSegments.size() - 1);
-
- final Object sourceData = retrieveData(
- uriInfo.getStartEntitySet(),
- uriInfo.getKeyPredicates(),
- uriInfo.getFunctionImport(),
- mapFunctionParameters(uriInfo.getFunctionImportParameters()),
- previousSegments);
-
- final EdmEntitySet entitySet = previousSegments.isEmpty() ?
- uriInfo.getStartEntitySet() : previousSegments.get(previousSegments.size() - 1).getEntitySet();
- final EdmEntitySet targetEntitySet = uriInfo.getTargetEntitySet();
- final Map<String, Object> keys = mapKey(uriInfo.getTargetKeyPredicates());
-
- final Object targetData = dataSource.readRelatedData(entitySet, sourceData, targetEntitySet, keys);
-
- // if (!appliesFilter(targetData, uriInfo.getFilter()))
- if (targetData == null) {
- throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
- }
-
- dataSource.deleteRelation(entitySet, sourceData, targetEntitySet, keys);
-
- return ODataResponse.newBuilder().build();
- }
-
- @Override
- public ODataResponse createEntityLink(final PostUriInfo uriInfo, final InputStream content,
- final String requestContentType, final String contentType) throws ODataException {
- final List<NavigationSegment> navigationSegments = uriInfo.getNavigationSegments();
- final List<NavigationSegment> previousSegments = navigationSegments.subList(0, navigationSegments.size() - 1);
-
- final Object sourceData = retrieveData(
- uriInfo.getStartEntitySet(),
- uriInfo.getKeyPredicates(),
- uriInfo.getFunctionImport(),
- mapFunctionParameters(uriInfo.getFunctionImportParameters()),
- previousSegments);
-
- final EdmEntitySet entitySet = previousSegments.isEmpty() ?
- uriInfo.getStartEntitySet() : previousSegments.get(previousSegments.size() - 1).getEntitySet();
- final EdmEntitySet targetEntitySet = uriInfo.getTargetEntitySet();
-
- final Map<String, Object> targetKeys = parseLink(targetEntitySet, content, requestContentType);
-
- dataSource.writeRelation(entitySet, sourceData, targetEntitySet, targetKeys);
-
- return ODataResponse.newBuilder().build();
- }
-
- @Override
- public ODataResponse updateEntityLink(final PutMergePatchUriInfo uriInfo, final InputStream content,
- final String requestContentType, final String contentType) throws ODataException {
- final List<NavigationSegment> navigationSegments = uriInfo.getNavigationSegments();
- final List<NavigationSegment> previousSegments = navigationSegments.subList(0, navigationSegments.size() - 1);
-
- final Object sourceData = retrieveData(
- uriInfo.getStartEntitySet(),
- uriInfo.getKeyPredicates(),
- uriInfo.getFunctionImport(),
- mapFunctionParameters(uriInfo.getFunctionImportParameters()),
- previousSegments);
-
- final EdmEntitySet entitySet = previousSegments.isEmpty() ?
- uriInfo.getStartEntitySet() : previousSegments.get(previousSegments.size() - 1).getEntitySet();
- final EdmEntitySet targetEntitySet = uriInfo.getTargetEntitySet();
- final Map<String, Object> keys = mapKey(uriInfo.getTargetKeyPredicates());
-
- final Object targetData = dataSource.readRelatedData(entitySet, sourceData, targetEntitySet, keys);
-
- if (!appliesFilter(targetData, uriInfo.getFilter())) {
- throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
- }
-
- dataSource.deleteRelation(entitySet, sourceData, targetEntitySet, keys);
-
- final Map<String, Object> newKeys = parseLink(targetEntitySet, content, requestContentType);
-
- dataSource.writeRelation(entitySet, sourceData, targetEntitySet, newKeys);
-
- return ODataResponse.newBuilder().build();
- }
-
- @Override
- public ODataResponse readEntityComplexProperty(final GetComplexPropertyUriInfo uriInfo, final String contentType)
- throws ODataException {
- Object data = retrieveData(
- uriInfo.getStartEntitySet(),
- uriInfo.getKeyPredicates(),
- uriInfo.getFunctionImport(),
- mapFunctionParameters(uriInfo.getFunctionImportParameters()),
- uriInfo.getNavigationSegments());
-
- // if (!appliesFilter(data, uriInfo.getFilter()))
- if (data == null) {
- throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
- }
-
- final List<EdmProperty> propertyPath = uriInfo.getPropertyPath();
- final EdmProperty property = propertyPath.get(propertyPath.size() - 1);
- final Object value = property.isSimple() ?
- property.getMapping() == null || property.getMapping().getMimeType() == null ?
- getPropertyValue(data, propertyPath) : getSimpleTypeValueMap(data, propertyPath) :
- getStructuralTypeValueMap(getPropertyValue(data, propertyPath), (EdmStructuralType) property.getType());
-
- ODataContext context = getContext();
- final int timingHandle = context.startRuntimeMeasurement("EntityProvider", "writeProperty");
-
- final ODataResponse response = EntityProvider.writeProperty(contentType, property, value);
-
- context.stopRuntimeMeasurement(timingHandle);
-
- return ODataResponse.fromResponse(response).eTag(constructETag(uriInfo.getTargetEntitySet(), data)).build();
- }
-
- @Override
- public ODataResponse readEntitySimpleProperty(final GetSimplePropertyUriInfo uriInfo, final String contentType)
- throws ODataException {
- return readEntityComplexProperty((GetComplexPropertyUriInfo) uriInfo, contentType);
- }
-
- @Override
- public ODataResponse readEntitySimplePropertyValue(final GetSimplePropertyUriInfo uriInfo, final String contentType)
- throws ODataException {
- Object data = retrieveData(
- uriInfo.getStartEntitySet(),
- uriInfo.getKeyPredicates(),
- uriInfo.getFunctionImport(),
- mapFunctionParameters(uriInfo.getFunctionImportParameters()),
- uriInfo.getNavigationSegments());
-
- // if (!appliesFilter(data, uriInfo.getFilter()))
- if (data == null) {
- throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
- }
-
- final List<EdmProperty> propertyPath = uriInfo.getPropertyPath();
- final EdmProperty property = propertyPath.get(propertyPath.size() - 1);
- final Object value = property.getMapping() == null || property.getMapping().getMimeType() == null ?
- getPropertyValue(data, propertyPath) : getSimpleTypeValueMap(data, propertyPath);
-
- return ODataResponse.fromResponse(EntityProvider.writePropertyValue(property, value)).eTag(
- constructETag(uriInfo.getTargetEntitySet(), data)).build();
- }
-
- @Override
- public ODataResponse deleteEntitySimplePropertyValue(final DeleteUriInfo uriInfo, final String contentType)
- throws ODataException {
- Object data = retrieveData(
- uriInfo.getStartEntitySet(),
- uriInfo.getKeyPredicates(),
- uriInfo.getFunctionImport(),
- mapFunctionParameters(uriInfo.getFunctionImportParameters()),
- uriInfo.getNavigationSegments());
-
- if (data == null) {
- throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
- }
-
- final List<EdmProperty> propertyPath = uriInfo.getPropertyPath();
- final EdmProperty property = propertyPath.get(propertyPath.size() - 1);
-
- data = getPropertyValue(data, propertyPath.subList(0, propertyPath.size() - 1));
- valueAccess.setPropertyValue(data, property, null);
- valueAccess.setMappingValue(data, property.getMapping(), null);
-
- return ODataResponse.newBuilder().build();
- }
-
- @Override
- public ODataResponse updateEntityComplexProperty(final PutMergePatchUriInfo uriInfo, final InputStream content,
- final String requestContentType, final boolean merge, final String contentType) throws ODataException {
- Object data = retrieveData(
- uriInfo.getStartEntitySet(),
- uriInfo.getKeyPredicates(),
- uriInfo.getFunctionImport(),
- mapFunctionParameters(uriInfo.getFunctionImportParameters()),
- uriInfo.getNavigationSegments());
-
- if (!appliesFilter(data, uriInfo.getFilter())) {
- throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
- }
-
- final List<EdmProperty> propertyPath = uriInfo.getPropertyPath();
- final EdmProperty property = propertyPath.get(propertyPath.size() - 1);
-
- data = getPropertyValue(data, propertyPath.subList(0, propertyPath.size() - 1));
-
- ODataContext context = getContext();
- int timingHandle = context.startRuntimeMeasurement("EntityConsumer", "readProperty");
-
- Map<String, Object> values;
- try {
- values =
- EntityProvider.readProperty(requestContentType, property, content, EntityProviderReadProperties.init()
- .mergeSemantic(merge).build());
- } catch (final EntityProviderException e) {
- throw new ODataBadRequestException(ODataBadRequestException.BODY, e);
- }
-
- context.stopRuntimeMeasurement(timingHandle);
-
- final Object value = values.get(property.getName());
- if (property.isSimple()) {
- valueAccess.setPropertyValue(data, property, value);
- } else {
- @SuppressWarnings("unchecked")
- final Map<String, Object> propertyValue = (Map<String, Object>) value;
- setStructuralTypeValuesFromMap(valueAccess.getPropertyValue(data, property),
- (EdmStructuralType) property.getType(), propertyValue, merge);
- }
-
- return ODataResponse.newBuilder().eTag(constructETag(uriInfo.getTargetEntitySet(), data)).build();
- }
-
- @Override
- public ODataResponse updateEntitySimpleProperty(final PutMergePatchUriInfo uriInfo, final InputStream content,
- final String requestContentType, final String contentType) throws ODataException {
- return updateEntityComplexProperty(uriInfo, content, requestContentType, false, contentType);
- }
-
- @Override
- public ODataResponse updateEntitySimplePropertyValue(final PutMergePatchUriInfo uriInfo, final InputStream content,
- final String requestContentType, final String contentType) throws ODataException {
- Object data = retrieveData(
- uriInfo.getStartEntitySet(),
- uriInfo.getKeyPredicates(),
- uriInfo.getFunctionImport(),
- mapFunctionParameters(uriInfo.getFunctionImportParameters()),
- uriInfo.getNavigationSegments());
-
- if (!appliesFilter(data, uriInfo.getFilter())) {
- throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
- }
-
- final List<EdmProperty> propertyPath = uriInfo.getPropertyPath();
- final EdmProperty property = propertyPath.get(propertyPath.size() - 1);
-
- data = getPropertyValue(data, propertyPath.subList(0, propertyPath.size() - 1));
-
- ODataContext context = getContext();
- int timingHandle = context.startRuntimeMeasurement("EntityConsumer", "readPropertyValue");
-
- Object value;
- try {
- value = EntityProvider.readPropertyValue(property, content);
- } catch (final EntityProviderException e) {
- throw new ODataBadRequestException(ODataBadRequestException.BODY, e);
- }
-
- context.stopRuntimeMeasurement(timingHandle);
-
- valueAccess.setPropertyValue(data, property, value);
- valueAccess.setMappingValue(data, property.getMapping(), requestContentType);
-
- return ODataResponse.newBuilder().eTag(constructETag(uriInfo.getTargetEntitySet(), data)).build();
- }
-
- @Override
- public ODataResponse readEntityMedia(final GetMediaResourceUriInfo uriInfo, final String contentType)
- throws ODataException {
- final Object data = retrieveData(
- uriInfo.getStartEntitySet(),
- uriInfo.getKeyPredicates(),
- uriInfo.getFunctionImport(),
- mapFunctionParameters(uriInfo.getFunctionImportParameters()),
- uriInfo.getNavigationSegments());
-
- if (!appliesFilter(data, uriInfo.getFilter())) {
- throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
- }
-
- final EdmEntitySet entitySet = uriInfo.getTargetEntitySet();
- final BinaryData binaryData = dataSource.readBinaryData(entitySet, data);
- if (binaryData == null) {
- throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
- }
-
- final String mimeType = binaryData.getMimeType() == null ?
- HttpContentType.APPLICATION_OCTET_STREAM : binaryData.getMimeType();
-
- return ODataResponse.fromResponse(EntityProvider.writeBinary(mimeType, binaryData.getData())).eTag(
- constructETag(entitySet, data)).build();
- }
-
- @Override
- public ODataResponse deleteEntityMedia(final DeleteUriInfo uriInfo, final String contentType) throws ODataException {
- final Object data = retrieveData(
- uriInfo.getStartEntitySet(),
- uriInfo.getKeyPredicates(),
- uriInfo.getFunctionImport(),
- mapFunctionParameters(uriInfo.getFunctionImportParameters()),
- uriInfo.getNavigationSegments());
-
- if (data == null) {
- throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
- }
-
- dataSource.writeBinaryData(uriInfo.getTargetEntitySet(), data, new BinaryData(null, null));
-
- return ODataResponse.newBuilder().build();
- }
-
- @Override
- public ODataResponse updateEntityMedia(final PutMergePatchUriInfo uriInfo, final InputStream content,
- final String requestContentType, final String contentType) throws ODataException {
- final Object data = retrieveData(
- uriInfo.getStartEntitySet(),
- uriInfo.getKeyPredicates(),
- uriInfo.getFunctionImport(),
- mapFunctionParameters(uriInfo.getFunctionImportParameters()),
- uriInfo.getNavigationSegments());
-
- if (!appliesFilter(data, uriInfo.getFilter())) {
- throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
- }
-
- ODataContext context = getContext();
- final int timingHandle = context.startRuntimeMeasurement("EntityProvider", "readBinary");
-
- final byte[] value = EntityProvider.readBinary(content);
-
- context.stopRuntimeMeasurement(timingHandle);
-
- final EdmEntitySet entitySet = uriInfo.getTargetEntitySet();
- dataSource.writeBinaryData(entitySet, data, new BinaryData(value, requestContentType));
-
- return ODataResponse.newBuilder().eTag(constructETag(entitySet, data)).build();
- }
-
- @Override
- public ODataResponse executeFunctionImport(final GetFunctionImportUriInfo uriInfo, final String contentType)
- throws ODataException {
- final EdmFunctionImport functionImport = uriInfo.getFunctionImport();
- final EdmType type = functionImport.getReturnType().getType();
-
- final Object data = dataSource.readData(
- functionImport,
- mapFunctionParameters(uriInfo.getFunctionImportParameters()),
- null);
-
- if (data == null) {
- throw new ODataNotFoundException(ODataHttpException.COMMON);
- }
-
- Object value;
- if (type.getKind() == EdmTypeKind.SIMPLE) {
- value = type == EdmSimpleTypeKind.Binary.getEdmSimpleTypeInstance() ?
- ((BinaryData) data).getData() : data;
- } else if (functionImport.getReturnType().getMultiplicity() == EdmMultiplicity.MANY) {
- List<Map<String, Object>> values = new ArrayList<Map<String, Object>>();
- for (final Object typeData : (List<?>) data) {
- values.add(getStructuralTypeValueMap(typeData, (EdmStructuralType) type));
- }
- value = values;
- } else {
- value = getStructuralTypeValueMap(data, (EdmStructuralType) type);
- }
-
- ODataContext context = getContext();
-
- final EntityProviderWriteProperties entryProperties = EntityProviderWriteProperties
- .serviceRoot(context.getPathInfo().getServiceRoot()).build();
-
- final int timingHandle = context.startRuntimeMeasurement("EntityProvider", "writeFunctionImport");
-
- final ODataResponse response =
- EntityProvider.writeFunctionImport(contentType, functionImport, value, entryProperties);
-
- context.stopRuntimeMeasurement(timingHandle);
-
- return ODataResponse.fromResponse(response).build();
- }
-
- @Override
- public ODataResponse executeFunctionImportValue(final GetFunctionImportUriInfo uriInfo, final String contentType)
- throws ODataException {
- final EdmFunctionImport functionImport = uriInfo.getFunctionImport();
- final EdmSimpleType type = (EdmSimpleType) functionImport.getReturnType().getType();
-
- final Object data = dataSource.readData(
- functionImport,
- mapFunctionParameters(uriInfo.getFunctionImportParameters()),
- null);
-
- if (data == null) {
- throw new ODataNotFoundException(ODataHttpException.COMMON);
- }
-
- ODataResponse response;
- if (type == EdmSimpleTypeKind.Binary.getEdmSimpleTypeInstance()) {
- response = EntityProvider.writeBinary(((BinaryData) data).getMimeType(), ((BinaryData) data).getData());
- } else {
- final String value = type.valueToString(data, EdmLiteralKind.DEFAULT, null);
- response = EntityProvider.writeText(value == null ? "" : value);
- }
- return ODataResponse.fromResponse(response).build();
- }
-
- private static Map<String, Object> mapKey(final List<KeyPredicate> keys) throws EdmException {
- Map<String, Object> keyMap = new HashMap<String, Object>();
- for (final KeyPredicate key : keys) {
- final EdmProperty property = key.getProperty();
- final EdmSimpleType type = (EdmSimpleType) property.getType();
- keyMap.put(property.getName(), type.valueOfString(key.getLiteral(), EdmLiteralKind.DEFAULT, property.getFacets(),
- type.getDefaultType()));
- }
- return keyMap;
- }
-
- private static Map<String, Object> mapFunctionParameters(final Map<String, EdmLiteral> functionImportParameters)
- throws EdmSimpleTypeException {
- if (functionImportParameters == null) {
- return Collections.emptyMap();
- } else {
- Map<String, Object> parameterMap = new HashMap<String, Object>();
- for (final String parameterName : functionImportParameters.keySet()) {
- final EdmLiteral literal = functionImportParameters.get(parameterName);
- final EdmSimpleType type = literal.getType();
- parameterMap.put(parameterName, type.valueOfString(literal.getLiteral(), EdmLiteralKind.DEFAULT, null, type
- .getDefaultType()));
- }
- return parameterMap;
- }
- }
-
- private Object retrieveData(final EdmEntitySet startEntitySet, final List<KeyPredicate> keyPredicates,
- final EdmFunctionImport functionImport, final Map<String, Object> functionImportParameters,
- final List<NavigationSegment> navigationSegments) throws ODataException {
- Object data;
- final Map<String, Object> keys = mapKey(keyPredicates);
-
- ODataContext context = getContext();
- final int timingHandle = context.startRuntimeMeasurement(getClass().getSimpleName(), "retrieveData");
-
- data = functionImport == null ?
- keys.isEmpty() ?
- dataSource.readData(startEntitySet) : dataSource.readData(startEntitySet, keys) :
- dataSource.readData(functionImport, functionImportParameters, keys);
-
- EdmEntitySet currentEntitySet =
- functionImport == null ? startEntitySet : functionImport.getEntitySet();
- for (NavigationSegment navigationSegment : navigationSegments) {
- data = dataSource.readRelatedData(
- currentEntitySet,
- data,
- navigationSegment.getEntitySet(),
- mapKey(navigationSegment.getKeyPredicates()));
- currentEntitySet = navigationSegment.getEntitySet();
- }
-
- context.stopRuntimeMeasurement(timingHandle);
-
- return data;
- }
-
- private <T> String constructETag(final EdmEntitySet entitySet, final T data) throws ODataException {
- final EdmEntityType entityType = entitySet.getEntityType();
- String eTag = null;
- for (final String propertyName : entityType.getPropertyNames()) {
- final EdmProperty property = (EdmProperty) entityType.getProperty(propertyName);
- if (property.getFacets() != null && property.getFacets().getConcurrencyMode() == EdmConcurrencyMode.Fixed) {
- final EdmSimpleType type = (EdmSimpleType) property.getType();
- final String component = type.valueToString(valueAccess.getPropertyValue(data, property),
- EdmLiteralKind.DEFAULT, property.getFacets());
- eTag = eTag == null ? component : eTag + Edm.DELIMITER + component;
- }
- }
- return eTag == null ? null : "W/\"" + eTag + "\"";
- }
-
- private <T> Map<String, ODataCallback> getCallbacks(final T data, final EdmEntityType entityType)
- throws EdmException {
- final List<String> navigationPropertyNames = entityType.getNavigationPropertyNames();
- if (navigationPropertyNames.isEmpty()) {
- return null;
- } else {
- final WriteCallback callback = new WriteCallback(data);
- Map<String, ODataCallback> callbacks = new HashMap<String, ODataCallback>();
- for (final String name : navigationPropertyNames) {
- callbacks.put(name, callback);
- }
- return callbacks;
- }
- }
-
- private class WriteCallback implements OnWriteEntryContent, OnWriteFeedContent {
- private final Object data;
-
- private <T> WriteCallback(final T data) {
- this.data = data;
- }
-
- @Override
- public WriteFeedCallbackResult retrieveFeedResult(final WriteFeedCallbackContext context)
- throws ODataApplicationException {
- try {
- final EdmEntityType entityType =
- context.getSourceEntitySet().getRelatedEntitySet(context.getNavigationProperty()).getEntityType();
- List<Map<String, Object>> values = new ArrayList<Map<String, Object>>();
- Object relatedData = null;
- try {
- relatedData = readRelatedData(context);
- for (final Object entryData : (List<?>) relatedData) {
- values.add(getStructuralTypeValueMap(entryData, entityType));
- }
- } catch (final ODataNotFoundException e) {
- values.clear();
- }
- WriteFeedCallbackResult result = new WriteFeedCallbackResult();
- result.setFeedData(values);
- EntityProviderWriteProperties inlineProperties =
- EntityProviderWriteProperties.serviceRoot(getContext().getPathInfo().getServiceRoot()).callbacks(
- getCallbacks(relatedData, entityType)).expandSelectTree(context.getCurrentExpandSelectTreeNode())
- .selfLink(context.getSelfLink()).build();
- result.setInlineProperties(inlineProperties);
- return result;
- } catch (final ODataException e) {
- throw new ODataApplicationException(e.getLocalizedMessage(), Locale.ROOT, e);
- }
- }
-
- @Override
- public WriteEntryCallbackResult retrieveEntryResult(final WriteEntryCallbackContext context)
- throws ODataApplicationException {
- try {
- final EdmEntityType entityType =
- context.getSourceEntitySet().getRelatedEntitySet(context.getNavigationProperty()).getEntityType();
- WriteEntryCallbackResult result = new WriteEntryCallbackResult();
- Object relatedData;
- try {
- relatedData = readRelatedData(context);
- } catch (final ODataNotFoundException e) {
- relatedData = null;
- }
- result.setEntryData(getStructuralTypeValueMap(relatedData, entityType));
-
- EntityProviderWriteProperties inlineProperties =
- EntityProviderWriteProperties.serviceRoot(getContext().getPathInfo().getServiceRoot()).callbacks(
- getCallbacks(relatedData, entityType)).expandSelectTree(context.getCurrentExpandSelectTreeNode())
- .build();
- result.setInlineProperties(inlineProperties);
- return result;
- } catch (final ODataException e) {
- throw new ODataApplicationException(e.getLocalizedMessage(), Locale.ROOT, e);
- }
- }
-
- private Object readRelatedData(final WriteCallbackContext context) throws ODataException {
- final EdmEntitySet entitySet = context.getSourceEntitySet();
- return dataSource.readRelatedData(
- entitySet,
- data instanceof List ? readEntryData((List<?>) data, entitySet.getEntityType(), context
- .extractKeyFromEntryData()) : data,
- entitySet.getRelatedEntitySet(context.getNavigationProperty()),
- Collections.<String, Object> emptyMap());
- }
-
- private <T> T readEntryData(final List<T> data, final EdmEntityType entityType, final Map<String, Object> key)
- throws ODataException {
- for (final T entryData : data) {
- boolean found = true;
- for (final EdmProperty keyProperty : entityType.getKeyProperties()) {
- if (!valueAccess.getPropertyValue(entryData, keyProperty).equals(key.get(keyProperty.getName()))) {
- found = false;
- break;
- }
- }
- if (found) {
- return entryData;
- }
- }
- return null;
- }
- }
-
- private <T> ODataResponse writeEntry(final EdmEntitySet entitySet, final ExpandSelectTreeNode expandSelectTree,
- final T data, final String contentType) throws ODataException, EntityProviderException {
- final EdmEntityType entityType = entitySet.getEntityType();
- final Map<String, Object> values = getStructuralTypeValueMap(data, entityType);
-
- ODataContext context = getContext();
- EntityProviderWriteProperties writeProperties = EntityProviderWriteProperties
- .serviceRoot(context.getPathInfo().getServiceRoot())
- .expandSelectTree(expandSelectTree)
- .callbacks(getCallbacks(data, entityType))
- .build();
-
- final int timingHandle = context.startRuntimeMeasurement("EntityProvider", "writeEntry");
-
- final ODataResponse response = EntityProvider.writeEntry(contentType, entitySet, values, writeProperties);
-
- context.stopRuntimeMeasurement(timingHandle);
-
- return response;
- }
-
- private ODataEntry parseEntry(final EdmEntitySet entitySet, final InputStream content,
- final String requestContentType, final EntityProviderReadProperties properties) throws ODataBadRequestException {
- ODataContext context = getContext();
- final int timingHandle = context.startRuntimeMeasurement("EntityConsumer", "readEntry");
-
- ODataEntry entryValues;
- try {
- entryValues = EntityProvider.readEntry(requestContentType, entitySet, content, properties);
- } catch (final EntityProviderException e) {
- throw new ODataBadRequestException(ODataBadRequestException.BODY, e);
- }
-
- context.stopRuntimeMeasurement(timingHandle);
-
- return entryValues;
- }
-
- private Map<String, Object> parseLink(final EdmEntitySet entitySet, final InputStream content,
- final String contentType) throws ODataException {
- ODataContext context = getContext();
- final int timingHandle = context.startRuntimeMeasurement("EntityProvider", "readLink");
-
- final String uriString = EntityProvider.readLink(contentType, entitySet, content);
-
- context.stopRuntimeMeasurement(timingHandle);
-
- final Map<String, Object> targetKeys = parseLinkUri(entitySet, uriString);
- if (targetKeys == null) {
- throw new ODataBadRequestException(ODataBadRequestException.BODY);
- }
- return targetKeys;
- }
-
- private Map<String, Object> parseLinkUri(final EdmEntitySet targetEntitySet, final String uriString)
- throws EdmException {
- ODataContext context = getContext();
- final int timingHandle = context.startRuntimeMeasurement("UriParser", "getKeyPredicatesFromEntityLink");
-
- List<KeyPredicate> key = null;
- try {
- key = UriParser.getKeyPredicatesFromEntityLink(targetEntitySet, uriString,
- context.getPathInfo().getServiceRoot());
- } catch (ODataException e) {
- // We don't understand the link target. This could also be seen as an error.
- }
-
- context.stopRuntimeMeasurement(timingHandle);
-
- return key == null ? null : mapKey(key);
- }
-
- private <T> void createInlinedEntities(final EdmEntitySet entitySet, final T data, final ODataEntry entryValues)
- throws ODataException {
- final EdmEntityType entityType = entitySet.getEntityType();
- for (final String navigationPropertyName : entityType.getNavigationPropertyNames()) {
-
- final EdmNavigationProperty navigationProperty =
- (EdmNavigationProperty) entityType.getProperty(navigationPropertyName);
- final EdmEntitySet relatedEntitySet = entitySet.getRelatedEntitySet(navigationProperty);
- final EdmEntityType relatedEntityType = relatedEntitySet.getEntityType();
-
- final Object relatedValue = entryValues.getProperties().get(navigationPropertyName);
- if (relatedValue == null) {
- for (final String uriString : entryValues.getMetadata().getAssociationUris(navigationPropertyName)) {
- final Map<String, Object> key = parseLinkUri(relatedEntitySet, uriString);
- if (key != null) {
- dataSource.writeRelation(entitySet, data, relatedEntitySet, key);
- }
- }
-
- } else {
- if (relatedValue instanceof ODataFeed) {
- ODataFeed feed = (ODataFeed) relatedValue;
- final List<ODataEntry> relatedValueList = feed.getEntries();
- for (final ODataEntry relatedValues : relatedValueList) {
- Object relatedData = dataSource.newDataObject(relatedEntitySet);
- setStructuralTypeValuesFromMap(relatedData, relatedEntityType, relatedValues.getProperties(), false);
- dataSource.createData(relatedEntitySet, relatedData);
- dataSource.writeRelation(entitySet, data, relatedEntitySet, getStructuralTypeValueMap(relatedData,
- relatedEntityType));
- createInlinedEntities(relatedEntitySet, relatedData, relatedValues);
- }
- } else if (relatedValue instanceof ODataEntry) {
- final ODataEntry relatedValueEntry = (ODataEntry) relatedValue;
- Object relatedData = dataSource.newDataObject(relatedEntitySet);
- setStructuralTypeValuesFromMap(relatedData, relatedEntityType, relatedValueEntry.getProperties(), false);
- dataSource.createData(relatedEntitySet, relatedData);
- dataSource.writeRelation(entitySet, data, relatedEntitySet, getStructuralTypeValueMap(relatedData,
- relatedEntityType));
- createInlinedEntities(relatedEntitySet, relatedData, relatedValueEntry);
- } else {
- throw new ODataException("Unexpected class for a related value: " + relatedValue.getClass().getSimpleName());
- }
-
- }
- }
- }
-
- private <T> Integer applySystemQueryOptions(final EdmEntitySet entitySet, final List<T> data,
- final FilterExpression filter, final InlineCount inlineCount, final OrderByExpression orderBy,
- final String skipToken, final Integer skip, final Integer top) throws ODataException {
- ODataContext context = getContext();
- final int timingHandle = context.startRuntimeMeasurement(getClass().getSimpleName(), "applySystemQueryOptions");
-
- if (filter != null) {
- // Remove all elements the filter does not apply for.
- // A for-each loop would not work with "remove", see Java documentation.
- for (Iterator<T> iterator = data.iterator(); iterator.hasNext();) {
- if (!appliesFilter(iterator.next(), filter)) {
- iterator.remove();
- }
- }
- }
-
- final Integer count = inlineCount == InlineCount.ALLPAGES ? data.size() : null;
-
- if (orderBy != null) {
- sort(data, orderBy);
- } else if (skipToken != null || skip != null || top != null) {
- sortInDefaultOrder(entitySet, data);
- }
-
- if (skipToken != null) {
- while (!data.isEmpty() && !getSkipToken(entitySet, data.get(0)).equals(skipToken)) {
- data.remove(0);
- }
- }
-
- if (skip != null) {
- if (skip >= data.size()) {
- data.clear();
- } else {
- for (int i = 0; i < skip; i++) {
- data.remove(0);
- }
- }
- }
-
- if (top != null) {
- while (data.size() > top) {
- data.remove(top.intValue());
- }
- }
-
- context.stopRuntimeMeasurement(timingHandle);
-
- return count;
- }
-
- private <T> void sort(final List<T> data, final OrderByExpression orderBy) {
- Collections.sort(data, new Comparator<T>() {
- @Override
- public int compare(final T entity1, final T entity2) {
- try {
- int result = 0;
- for (final OrderExpression expression : orderBy.getOrders()) {
- result = evaluateExpression(entity1, expression.getExpression()).compareTo(
- evaluateExpression(entity2, expression.getExpression()));
- if (expression.getSortOrder() == SortOrder.desc) {
- result = -result;
- }
- if (result != 0) {
- break;
- }
- }
- return result;
- } catch (final ODataException e) {
- return 0;
- }
- }
- });
- }
-
- private <T> void sortInDefaultOrder(final EdmEntitySet entitySet, final List<T> data) {
- Collections.sort(data, new Comparator<T>() {
- @Override
- public int compare(final T entity1, final T entity2) {
- try {
- return getSkipToken(entitySet, entity1).compareTo(getSkipToken(entitySet, entity2));
- } catch (final ODataException e) {
- return 0;
- }
- }
- });
- }
-
- private <T> boolean appliesFilter(final T data, final FilterExpression filter) throws ODataException {
- ODataContext context = getContext();
- final int timingHandle = context.startRuntimeMeasurement(getClass().getSimpleName(), "appliesFilter");
-
- try {
- return data != null && (filter == null || evaluateExpression(data, filter.getExpression()).equals("true"));
- } catch (final RuntimeException e) {
- return false;
- } finally {
- context.stopRuntimeMeasurement(timingHandle);
- }
- }
-
- private <T> String evaluateExpression(final T data, final CommonExpression expression) throws ODataException {
- switch (expression.getKind()) {
- case UNARY:
- final UnaryExpression unaryExpression = (UnaryExpression) expression;
- final String operand = evaluateExpression(data, unaryExpression.getOperand());
-
- switch (unaryExpression.getOperator()) {
- case NOT:
- return Boolean.toString(!Boolean.parseBoolean(operand));
- case MINUS:
- return operand.startsWith("-") ? operand.substring(1) : "-" + operand;
- default:
- throw new ODataNotImplementedException();
- }
-
- case BINARY:
- final BinaryExpression binaryExpression = (BinaryExpression) expression;
- final EdmSimpleType type = (EdmSimpleType) binaryExpression.getLeftOperand().getEdmType();
- final String left = evaluateExpression(data, binaryExpression.getLeftOperand());
- final String right = evaluateExpression(data, binaryExpression.getRightOperand());
-
- switch (binaryExpression.getOperator()) {
- case ADD:
- if (binaryExpression.getEdmType() == EdmSimpleTypeKind.Decimal.getEdmSimpleTypeInstance()
- || binaryExpression.getEdmType() == EdmSimpleTypeKind.Double.getEdmSimpleTypeInstance()
- || binaryExpression.getEdmType() == EdmSimpleTypeKind.Single.getEdmSimpleTypeInstance()) {
- return Double.toString(Double.valueOf(left) + Double.valueOf(right));
- } else {
- return Long.toString(Long.valueOf(left) + Long.valueOf(right));
- }
- case SUB:
- if (binaryExpression.getEdmType() == EdmSimpleTypeKind.Decimal.getEdmSimpleTypeInstance()
- || binaryExpression.getEdmType() == EdmSimpleTypeKind.Double.getEdmSimpleTypeInstance()
- || binaryExpression.getEdmType() == EdmSimpleTypeKind.Single.getEdmSimpleTypeInstance()) {
- return Double.toString(Double.valueOf(left) - Double.valueOf(right));
- } else {
- return Long.toString(Long.valueOf(left) - Long.valueOf(right));
- }
- case MUL:
- if (binaryExpression.getEdmType() == EdmSimpleTypeKind.Decimal.getEdmSimpleTypeInstance()
- || binaryExpression.getEdmType() == EdmSimpleTypeKind.Double.getEdmSimpleTypeInstance()
- || binaryExpression.getEdmType() == EdmSimpleTypeKind.Single.getEdmSimpleTypeInstance()) {
- return Double.toString(Double.valueOf(left) * Double.valueOf(right));
- } else {
- return Long.toString(Long.valueOf(left) * Long.valueOf(right));
- }
- case DIV:
- final String number = Double.toString(Double.valueOf(left) / Double.valueOf(right));
- return number.endsWith(".0") ? number.replace(".0", "") : number;
- case MODULO:
- if (binaryExpression.getEdmType() == EdmSimpleTypeKind.Decimal.getEdmSimpleTypeInstance()
- || binaryExpression.getEdmType() == EdmSimpleTypeKind.Double.getEdmSimpleTypeInstance()
- || binaryExpression.getEdmType() == EdmSimpleTypeKind.Single.getEdmSimpleTypeInstance()) {
- return Double.toString(Double.valueOf(left) % Double.valueOf(right));
- } else {
- return Long.toString(Long.valueOf(left) % Long.valueOf(right));
- }
- case AND:
- return Boolean.toString(left.equals("true") && right.equals("true"));
- case OR:
- return Boolean.toString(left.equals("true") || right.equals("true"));
- case EQ:
- return Boolean.toString(left.equals(right));
- case NE:
- return Boolean.toString(!left.equals(right));
- case LT:
- if (type == EdmSimpleTypeKind.String.getEdmSimpleTypeInstance()
- || type == EdmSimpleTypeKind.DateTime.getEdmSimpleTypeInstance()
- || type == EdmSimpleTypeKind.DateTimeOffset.getEdmSimpleTypeInstance()
- || type == EdmSimpleTypeKind.Guid.getEdmSimpleTypeInstance()
- || type == EdmSimpleTypeKind.Time.getEdmSimpleTypeInstance()) {
- return Boolean.toString(left.compareTo(right) < 0);
- } else {
- return Boolean.toString(Double.valueOf(left) < Double.valueOf(right));
- }
- case LE:
- if (type == EdmSimpleTypeKind.String.getEdmSimpleTypeInstance()
- || type == EdmSimpleTypeKind.DateTime.getEdmSimpleTypeInstance()
- || type == EdmSimpleTypeKind.DateTimeOffset.getEdmSimpleTypeInstance()
- || type == EdmSimpleTypeKind.Guid.getEdmSimpleTypeInstance()
- || type == EdmSimpleTypeKind.Time.getEdmSimpleTypeInstance()) {
- return Boolean.toString(left.compareTo(right) <= 0);
- } else {
- return Boolean.toString(Double.valueOf(left) <= Double.valueOf(right));
- }
- case GT:
- if (type == EdmSimpleTypeKind.String.getEdmSimpleTypeInstance()
- || type == EdmSimpleTypeKind.DateTime.getEdmSimpleTypeInstance()
- || type == EdmSimpleTypeKind.DateTimeOffset.getEdmSimpleTypeInstance()
- || type == EdmSimpleTypeKind.Guid.getEdmSimpleTypeInstance()
- || type == EdmSimpleTypeKind.Time.getEdmSimpleTypeInstance()) {
- return Boolean.toString(left.compareTo(right) > 0);
- } else {
- return Boolean.toString(Double.valueOf(left) > Double.valueOf(right));
- }
- case GE:
- if (type == EdmSimpleTypeKind.String.getEdmSimpleTypeInstance()
- || type == EdmSimpleTypeKind.DateTime.getEdmSimpleTypeInstance()
- || type == EdmSimpleTypeKind.DateTimeOffset.getEdmSimpleTypeInstance()
- || type == EdmSimpleTypeKind.Guid.getEdmSimpleTypeInstance()
- || type == EdmSimpleTypeKind.Time.getEdmSimpleTypeInstance()) {
- return Boolean.toString(left.compareTo(right) >= 0);
- } else {
- return Boolean.toString(Double.valueOf(left) >= Double.valueOf(right));
- }
- case PROPERTY_ACCESS:
- throw new ODataNotImplementedException();
- default:
- throw new ODataNotImplementedException();
- }
-
- case PROPERTY:
- final EdmProperty property = (EdmProperty) ((PropertyExpression) expression).getEdmProperty();
- final EdmSimpleType propertyType = (EdmSimpleType) property.getType();
- return propertyType.valueToString(valueAccess.getPropertyValue(data, property), EdmLiteralKind.DEFAULT,
- property.getFacets());
-
- case MEMBER:
- final MemberExpression memberExpression = (MemberExpression) expression;
- final PropertyExpression propertyExpression = (PropertyExpression) memberExpression.getProperty();
- final EdmProperty memberProperty = (EdmProperty) propertyExpression.getEdmProperty();
- final EdmSimpleType memberType = (EdmSimpleType) memberExpression.getEdmType();
- List<EdmProperty> propertyPath = new ArrayList<EdmProperty>();
- CommonExpression currentExpression = memberExpression;
- while (currentExpression != null) {
- final PropertyExpression currentPropertyExpression =
- (PropertyExpression) (currentExpression.getKind() == ExpressionKind.MEMBER ?
- ((MemberExpression) currentExpression).getProperty() : currentExpression);
- final EdmTyped currentProperty = currentPropertyExpression.getEdmProperty();
- final EdmTypeKind kind = currentProperty.getType().getKind();
- if (kind == EdmTypeKind.SIMPLE || kind == EdmTypeKind.COMPLEX) {
- propertyPath.add(0, (EdmProperty) currentProperty);
- } else {
- throw new ODataNotImplementedException();
- }
- currentExpression =
- currentExpression.getKind() == ExpressionKind.MEMBER ? ((MemberExpression) currentExpression).getPath()
- : null;
- }
- return memberType.valueToString(getPropertyValue(data, propertyPath), EdmLiteralKind.DEFAULT, memberProperty
- .getFacets());
-
- case LITERAL:
- final LiteralExpression literal = (LiteralExpression) expression;
- final EdmSimpleType literalType = (EdmSimpleType) literal.getEdmType();
- return literalType.valueToString(literalType.valueOfString(literal.getUriLiteral(), EdmLiteralKind.URI, null,
- literalType.getDefaultType()),
- EdmLiteralKind.DEFAULT, null);
-
- case METHOD:
- final MethodExpression methodExpression = (MethodExpression) expression;
- final String first = evaluateExpression(data, methodExpression.getParameters().get(0));
- final String second = methodExpression.getParameterCount() > 1 ?
- evaluateExpression(data, methodExpression.getParameters().get(1)) : null;
- final String third = methodExpression.getParameterCount() > 2 ?
- evaluateExpression(data, methodExpression.getParameters().get(2)) : null;
-
- switch (methodExpression.getMethod()) {
- case ENDSWITH:
- return Boolean.toString(first.endsWith(second));
- case INDEXOF:
- return Integer.toString(first.indexOf(second));
- case STARTSWITH:
- return Boolean.toString(first.startsWith(second));
- case TOLOWER:
- return first.toLowerCase(Locale.ROOT);
- case TOUPPER:
- return first.toUpperCase(Locale.ROOT);
- case TRIM:
- return first.trim();
- case SUBSTRING:
- final int offset = Integer.parseInt(second);
- return first.substring(offset, offset + Integer.parseInt(third));
- case SUBSTRINGOF:
- return Boolean.toString(second.contains(first));
- case CONCAT:
- return first + second;
- case LENGTH:
- return Integer.toString(first.length());
- case YEAR:
- return String.valueOf(Integer.parseInt(first.substring(0, 4)));
- case MONTH:
- return String.valueOf(Integer.parseInt(first.substring(5, 7)));
- case DAY:
- return String.valueOf(Integer.parseInt(first.substring(8, 10)));
- case HOUR:
- return String.valueOf(Integer.parseInt(first.substring(11, 13)));
- case MINUTE:
- return String.valueOf(Integer.parseInt(first.substring(14, 16)));
- case SECOND:
- return String.valueOf(Integer.parseInt(first.substring(17, 19)));
- case ROUND:
- return Long.toString(Math.round(Double.valueOf(first)));
- case FLOOR:
- return Long.toString(Math.round(Math.floor(Double.valueOf(first))));
- case CEILING:
- return Long.toString(Math.round(Math.ceil(Double.valueOf(first))));
- default:
- throw new ODataNotImplementedException();
- }
-
- default:
- throw new ODataNotImplementedException();
- }
- }
-
- private <T> String getSkipToken(final EdmEntitySet entitySet, final T data) throws ODataException {
- String skipToken = "";
- for (final EdmProperty property : entitySet.getEntityType().getKeyProperties()) {
- final EdmSimpleType type = (EdmSimpleType) property.getType();
- skipToken = skipToken.concat(type.valueToString(valueAccess.getPropertyValue(data, property),
- EdmLiteralKind.DEFAULT, property.getFacets()));
- }
- return skipToken;
- }
-
- private <T> Object getPropertyValue(final T data, final List<EdmProperty> propertyPath) throws ODataException {
- Object dataObject = data;
- for (final EdmProperty property : propertyPath) {
- if (dataObject != null) {
- dataObject = valueAccess.getPropertyValue(dataObject, property);
- }
- }
- return dataObject;
- }
-
- private void handleMimeType(Object data, EdmMapping mapping, Map<String, Object> valueMap)
- throws ODataException {
- final String mimeTypeName = mapping.getMimeType();
- if (mimeTypeName != null) {
- Object value = valueAccess.getMappingValue(data, mapping);
- valueMap.put(mimeTypeName, value);
- if (mapping.getMediaResourceMimeTypeKey() != null) {
- valueMap.put(mapping.getMediaResourceMimeTypeKey(), value);
- }
- }
- }
-
- private <T> Map<String, Object> getSimpleTypeValueMap(final T data, final List<EdmProperty> propertyPath)
- throws ODataException {
- final EdmProperty property = propertyPath.get(propertyPath.size() - 1);
- Map<String, Object> valueWithMimeType = new HashMap<String, Object>();
- valueWithMimeType.put(property.getName(), getPropertyValue(data, propertyPath));
-
- handleMimeType(data, property.getMapping(), valueWithMimeType);
-
- return valueWithMimeType;
- }
-
- private <T> Map<String, Object> getStructuralTypeValueMap(final T data, final EdmStructuralType type)
- throws ODataException {
- ODataContext context = getContext();
- final int timingHandle = context.startRuntimeMeasurement(getClass().getSimpleName(), "getStructuralTypeValueMap");
-
- Map<String, Object> valueMap = new HashMap<String, Object>();
-
- EdmMapping mapping = type.getMapping();
- if (mapping != null) {
- handleMimeType(data, mapping, valueMap);
- }
-
- for (final String propertyName : type.getPropertyNames()) {
- final EdmProperty property = (EdmProperty) type.getProperty(propertyName);
- final Object value = valueAccess.getPropertyValue(data, property);
-
- if (property.isSimple()) {
- if (property.getMapping() == null || property.getMapping().getMimeType() == null) {
- valueMap.put(propertyName, value);
- } else {
- // TODO: enable MIME type mapping outside the current subtree
- valueMap.put(propertyName, getSimpleTypeValueMap(data, Arrays.asList(property)));
- }
- } else {
- valueMap.put(propertyName, getStructuralTypeValueMap(value, (EdmStructuralType) property.getType()));
- }
- }
-
- context.stopRuntimeMeasurement(timingHandle);
-
- return valueMap;
- }
-
- private <T> Map<String, Object> getStructuralTypeTypeMap(final T data, final EdmStructuralType type)
- throws ODataException {
- ODataContext context = getContext();
- final int timingHandle = context.startRuntimeMeasurement(getClass().getSimpleName(), "getStructuralTypeTypeMap");
-
- Map<String, Object> typeMap = new HashMap<String, Object>();
- for (final String propertyName : type.getPropertyNames()) {
- final EdmProperty property = (EdmProperty) type.getProperty(propertyName);
- if (property.isSimple()) {
- typeMap.put(propertyName, valueAccess.getPropertyType(data, property));
- } else {
- typeMap.put(propertyName, getStructuralTypeTypeMap(valueAccess.getPropertyValue(data, property),
- (EdmStructuralType) property.getType()));
- }
- }
-
- context.stopRuntimeMeasurement(timingHandle);
-
- return typeMap;
- }
-
- private <T> void setStructuralTypeValuesFromMap(final T data, final EdmStructuralType type,
- final Map<String, Object> valueMap, final boolean merge) throws ODataException {
- ODataContext context = getContext();
- final int timingHandle =
- context.startRuntimeMeasurement(getClass().getSimpleName(), "setStructuralTypeValuesFromMap");
-
- for (final String propertyName : type.getPropertyNames()) {
- final EdmProperty property = (EdmProperty) type.getProperty(propertyName);
- if (type instanceof EdmEntityType && ((EdmEntityType) type).getKeyProperties().contains(property)) {
- continue;
- }
- if (!merge || valueMap != null && valueMap.containsKey(propertyName)) {
- final Object value = valueMap == null ? null : valueMap.get(propertyName);
- if (property.isSimple()) {
- valueAccess.setPropertyValue(data, property, value);
- } else {
- @SuppressWarnings("unchecked")
- final Map<String, Object> values = (Map<String, Object>) value;
- setStructuralTypeValuesFromMap(valueAccess.getPropertyValue(data, property),
- (EdmStructuralType) property.getType(), values, merge);
- }
- }
- }
-
- context.stopRuntimeMeasurement(timingHandle);
- }
-
- @Override
- public ODataResponse executeBatch(final BatchHandler handler, final String contentType, final InputStream content)
- throws ODataException {
- ODataResponse batchResponse;
- List<BatchResponsePart> batchResponseParts = new ArrayList<BatchResponsePart>();
- PathInfo pathInfo = getContext().getPathInfo();
- EntityProviderBatchProperties batchProperties = EntityProviderBatchProperties.init().pathInfo(pathInfo).build();
- List<BatchRequestPart> batchParts = EntityProvider.parseBatchRequest(contentType, content, batchProperties);
- for (BatchRequestPart batchPart : batchParts) {
- batchResponseParts.add(handler.handleBatchPart(batchPart));
- }
- batchResponse = EntityProvider.writeBatchResponse(batchResponseParts);
- return batchResponse;
- }
-
- @Override
- public BatchResponsePart executeChangeSet(final BatchHandler handler, final List<ODataRequest> requests)
- throws ODataException {
- List<ODataResponse> responses = new ArrayList<ODataResponse>();
- for (ODataRequest request : requests) {
- ODataResponse response = handler.handleRequest(request);
- if (response.getStatus().getStatusCode() >= HttpStatusCodes.BAD_REQUEST.getStatusCode()) {
- // Rollback
- List<ODataResponse> errorResponses = new ArrayList<ODataResponse>(1);
- errorResponses.add(response);
- return BatchResponsePart.responses(errorResponses).changeSet(false).build();
- }
- responses.add(response);
- }
- return BatchResponsePart.responses(responses).changeSet(true).build();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d83070de/odata2-lib/odata-ref/src/main/java/org/apache/olingo/odata2/ref/processor/ScenarioDataSource.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-ref/src/main/java/org/apache/olingo/odata2/ref/processor/ScenarioDataSource.java b/odata2-lib/odata-ref/src/main/java/org/apache/olingo/odata2/ref/processor/ScenarioDataSource.java
index e3a4c9a..0047226 100644
--- a/odata2-lib/odata-ref/src/main/java/org/apache/olingo/odata2/ref/processor/ScenarioDataSource.java
+++ b/odata2-lib/odata-ref/src/main/java/org/apache/olingo/odata2/ref/processor/ScenarioDataSource.java
@@ -28,6 +28,7 @@ import java.util.Map;
import java.util.Map.Entry;
import org.apache.olingo.odata2.api.commons.HttpContentType;
+import org.apache.olingo.odata2.api.data.ListsDataSource;
import org.apache.olingo.odata2.api.edm.EdmEntitySet;
import org.apache.olingo.odata2.api.edm.EdmException;
import org.apache.olingo.odata2.api.edm.EdmFunctionImport;
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d83070de/odata2-lib/odata-ref/src/main/java/org/apache/olingo/odata2/ref/processor/ScenarioServiceFactory.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-ref/src/main/java/org/apache/olingo/odata2/ref/processor/ScenarioServiceFactory.java b/odata2-lib/odata-ref/src/main/java/org/apache/olingo/odata2/ref/processor/ScenarioServiceFactory.java
index ba1e66e..49cd8b2 100644
--- a/odata2-lib/odata-ref/src/main/java/org/apache/olingo/odata2/ref/processor/ScenarioServiceFactory.java
+++ b/odata2-lib/odata-ref/src/main/java/org/apache/olingo/odata2/ref/processor/ScenarioServiceFactory.java
@@ -24,6 +24,8 @@ import org.apache.olingo.odata2.api.ODataService;
import org.apache.olingo.odata2.api.ODataServiceFactory;
import org.apache.olingo.odata2.api.exception.ODataException;
import org.apache.olingo.odata2.api.processor.ODataContext;
+import org.apache.olingo.odata2.core.annotation.ds.BeanPropertyAccess;
+import org.apache.olingo.odata2.core.annotation.processor.ListsProcessor;
import org.apache.olingo.odata2.ref.edm.ScenarioEdmProvider;
import org.apache.olingo.odata2.ref.model.DataContainer;
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d83070de/odata2-lib/odata-ref/src/main/java/org/apache/olingo/odata2/ref/processor/ValueAccess.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-ref/src/main/java/org/apache/olingo/odata2/ref/processor/ValueAccess.java b/odata2-lib/odata-ref/src/main/java/org/apache/olingo/odata2/ref/processor/ValueAccess.java
deleted file mode 100644
index 75e54eb..0000000
--- a/odata2-lib/odata-ref/src/main/java/org/apache/olingo/odata2/ref/processor/ValueAccess.java
+++ /dev/null
@@ -1,69 +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.ref.processor;
-
-import org.apache.olingo.odata2.api.edm.EdmMapping;
-import org.apache.olingo.odata2.api.edm.EdmProperty;
-import org.apache.olingo.odata2.api.exception.ODataException;
-
-/**
- * This interface is intended to access values in a Java object.
- */
-public interface ValueAccess {
-
- /**
- * Retrieves the value of an EDM property for the given data object.
- * @param data the Java data object
- * @param property the requested {@link EdmProperty}
- * @return the requested property value
- */
- public <T> Object getPropertyValue(final T data, final EdmProperty property) throws ODataException;
-
- /**
- * Sets the value of an EDM property for the given data object.
- * @param data the Java data object
- * @param property the {@link EdmProperty}
- * @param value the new value of the property
- */
- public <T, V> void setPropertyValue(T data, final EdmProperty property, final V value) throws ODataException;
-
- /**
- * Retrieves the Java type of an EDM property for the given data object.
- * @param data the Java data object
- * @param property the requested {@link EdmProperty}
- * @return the requested Java type
- */
- public <T> Class<?> getPropertyType(final T data, final EdmProperty property) throws ODataException;
-
- /**
- * Retrieves the value defined by a mapping object for the given data object.
- * @param data the Java data object
- * @param mapping the requested {@link EdmMapping}
- * @return the requested value
- */
- public <T> Object getMappingValue(final T data, final EdmMapping mapping) throws ODataException;
-
- /**
- * Sets the value defined by a mapping object for the given data object.
- * @param data the Java data object
- * @param mapping the {@link EdmMapping}
- * @param value the new value
- */
- public <T, V> void setMappingValue(T data, final EdmMapping mapping, final V value) throws ODataException;
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d83070de/odata2-lib/odata-ref/src/test/java/org/apache/olingo/odata2/ref/read/EntitySetTest.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-ref/src/test/java/org/apache/olingo/odata2/ref/read/EntitySetTest.java b/odata2-lib/odata-ref/src/test/java/org/apache/olingo/odata2/ref/read/EntitySetTest.java
index 3611f30..53fd6ef 100644
--- a/odata2-lib/odata-ref/src/test/java/org/apache/olingo/odata2/ref/read/EntitySetTest.java
+++ b/odata2-lib/odata-ref/src/test/java/org/apache/olingo/odata2/ref/read/EntitySetTest.java
@@ -38,10 +38,10 @@ import org.apache.olingo.odata2.api.processor.ODataContext;
import org.apache.olingo.odata2.api.processor.ODataResponse;
import org.apache.olingo.odata2.api.uri.PathInfo;
import org.apache.olingo.odata2.api.uri.UriInfo;
+import org.apache.olingo.odata2.core.annotation.ds.BeanPropertyAccess;
+import org.apache.olingo.odata2.core.annotation.processor.ListsProcessor;
import org.apache.olingo.odata2.core.commons.ContentType;
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.ScenarioDataSource;
import org.apache.olingo.odata2.testutil.fit.BaseTest;
import org.junit.Before;
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d83070de/odata2-lib/odata-ref/src/test/java/org/apache/olingo/odata2/ref/read/EntityTest.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-ref/src/test/java/org/apache/olingo/odata2/ref/read/EntityTest.java b/odata2-lib/odata-ref/src/test/java/org/apache/olingo/odata2/ref/read/EntityTest.java
index 7df26ee..87593f2 100644
--- a/odata2-lib/odata-ref/src/test/java/org/apache/olingo/odata2/ref/read/EntityTest.java
+++ b/odata2-lib/odata-ref/src/test/java/org/apache/olingo/odata2/ref/read/EntityTest.java
@@ -43,10 +43,10 @@ import org.apache.olingo.odata2.api.processor.ODataResponse;
import org.apache.olingo.odata2.api.uri.KeyPredicate;
import org.apache.olingo.odata2.api.uri.PathInfo;
import org.apache.olingo.odata2.api.uri.UriInfo;
+import org.apache.olingo.odata2.core.annotation.ds.BeanPropertyAccess;
+import org.apache.olingo.odata2.core.annotation.processor.ListsProcessor;
import org.apache.olingo.odata2.core.commons.ContentType;
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.ScenarioDataSource;
import org.apache.olingo.odata2.testutil.fit.BaseTest;
import org.junit.Before;
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d83070de/odata2-processor-jpa/jpa-web/pom.xml
----------------------------------------------------------------------
diff --git a/odata2-processor-jpa/jpa-web/pom.xml b/odata2-processor-jpa/jpa-web/pom.xml
index 18302cb..273aeda 100644
--- a/odata2-processor-jpa/jpa-web/pom.xml
+++ b/odata2-processor-jpa/jpa-web/pom.xml
@@ -102,6 +102,16 @@
<version>3.8.1</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet</artifactId>
+ <version>2.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.core</groupId>
+ <artifactId>jersey-client</artifactId>
+ <version>2.0</version>
+ </dependency>
</dependencies>
<profiles>
[51/52] Renamed project
Posted by mi...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java b/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java
new file mode 100644
index 0000000..97f5b53
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java
@@ -0,0 +1,773 @@
+/*******************************************************************************
+ * 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.core.annotation.edm;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+import org.apache.olingo.odata2.api.annotation.edm.EdmComplexType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
+import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceContent;
+import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmType;
+import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
+import org.apache.olingo.odata2.api.edm.FullQualifiedName;
+import org.apache.olingo.odata2.api.edm.provider.AnnotationAttribute;
+import org.apache.olingo.odata2.api.edm.provider.AnnotationElement;
+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.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.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.Schema;
+import org.apache.olingo.odata2.api.edm.provider.SimpleProperty;
+import org.apache.olingo.odata2.api.edm.provider.Using;
+import org.apache.olingo.odata2.api.exception.ODataException;
+import org.apache.olingo.odata2.core.annotation.util.AnnotationHelper;
+import org.apache.olingo.odata2.core.annotation.util.ClassHelper;
+import org.apache.olingo.odata2.core.exception.ODataRuntimeException;
+
+/**
+ * Provider for the entity data model used in the reference scenario
+ *
+ */
+public class AnnotationEdmProvider extends EdmProvider {
+
+ private static final AnnotationHelper ANNOTATION_HELPER = new AnnotationHelper();
+
+ private final List<Class<?>> annotatedClasses;
+ private final Map<String, EntityContainer> name2Container = new HashMap<String, EntityContainer>();
+ private final Map<String, ContainerBuilder> containerName2ContainerBuilder = new HashMap<String, ContainerBuilder>();
+ private final Map<String, Schema> namespace2Schema = new HashMap<String, Schema>();
+ private EntityContainer defaultContainer;
+
+ public AnnotationEdmProvider(Collection<Class<?>> annotatedClasses) {
+
+ this.annotatedClasses = new ArrayList<Class<?>>(annotatedClasses.size());
+ for (Class<?> aClass : annotatedClasses) {
+ if (ANNOTATION_HELPER.isEdmAnnotated(aClass)) {
+ this.annotatedClasses.add(aClass);
+ }
+ }
+
+ init();
+ }
+
+ public AnnotationEdmProvider(String packageToScan) {
+ this.annotatedClasses = ClassHelper.loadClasses(packageToScan, new ClassHelper.ClassValidator() {
+ @Override
+ public boolean isClassValid(Class<?> c) {
+ return ANNOTATION_HELPER.isEdmAnnotated(c);
+ }
+ });
+
+ init();
+ }
+
+ private void init() {
+ for (Class<?> aClass : annotatedClasses) {
+ updateSchema(aClass);
+ handleEntityContainer(aClass);
+ }
+
+ finish();
+ }
+
+ @Override
+ public Association getAssociation(FullQualifiedName edmFQName) throws ODataException {
+ Schema schema = namespace2Schema.get(edmFQName.getNamespace());
+ if (schema != null) {
+ List<Association> associations = schema.getAssociations();
+ for (Association association : associations) {
+ if (association.getName().equals(edmFQName.getName())) {
+ return association;
+ }
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public AssociationSet getAssociationSet(String entityContainer, FullQualifiedName association,
+ String sourceEntitySetName, String sourceEntitySetRole) throws ODataException {
+ EntityContainer container = name2Container.get(entityContainer);
+ if (container != null) {
+ List<AssociationSet> associations = container.getAssociationSets();
+ for (AssociationSet associationSet : associations) {
+ if (associationSet.getAssociation().equals(association)) {
+ final AssociationSetEnd endOne = associationSet.getEnd1();
+ if (endOne.getRole().equals(sourceEntitySetRole)
+ && endOne.getEntitySet().equals(sourceEntitySetName)) {
+ return associationSet;
+ }
+ final AssociationSetEnd endTwo = associationSet.getEnd2();
+ if (endTwo.getRole().equals(sourceEntitySetRole)
+ && endTwo.getEntitySet().equals(sourceEntitySetName)) {
+ return associationSet;
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public ComplexType getComplexType(FullQualifiedName edmFQName) throws ODataException {
+ Schema schema = namespace2Schema.get(edmFQName.getNamespace());
+ if (schema != null) {
+ List<ComplexType> complexTypes = schema.getComplexTypes();
+ for (ComplexType complexType : complexTypes) {
+ if (complexType.getName().equals(edmFQName.getName())) {
+ return complexType;
+ }
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public EntityContainerInfo getEntityContainerInfo(String name) throws ODataException {
+ EntityContainer container = name2Container.get(name);
+ if (container == null) {
+ // use default container (if set)
+ container = defaultContainer;
+ }
+ if (container != null) {
+ EntityContainerInfo info = new EntityContainerInfo();
+ info.setName(container.getName());
+ info.setDefaultEntityContainer(container.isDefaultEntityContainer());
+ info.setExtendz(container.getExtendz());
+ info.setAnnotationAttributes(container.getAnnotationAttributes());
+ info.setAnnotationElements(container.getAnnotationElements());
+
+ return info;
+ }
+
+ return null;
+ }
+
+ @Override
+ public EntitySet getEntitySet(String entityContainer, String name) throws ODataException {
+ EntityContainer container = name2Container.get(entityContainer);
+ if (container != null) {
+ List<EntitySet> entitySets = container.getEntitySets();
+ for (EntitySet entitySet : entitySets) {
+ if (entitySet.getName().equals(name)) {
+ return entitySet;
+ }
+ }
+ }
+
+ return null;
+ }
+
+ @Override
+ public EntityType getEntityType(FullQualifiedName edmFQName) throws ODataException {
+ Schema schema = namespace2Schema.get(edmFQName.getNamespace());
+ if (schema != null) {
+ List<EntityType> complexTypes = schema.getEntityTypes();
+ for (EntityType complexType : complexTypes) {
+ if (complexType.getName().equals(edmFQName.getName())) {
+ return complexType;
+ }
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public FunctionImport getFunctionImport(String entityContainer, String name) throws ODataException {
+ EntityContainer container = name2Container.get(entityContainer);
+ if (container != null) {
+ List<FunctionImport> functionImports = container.getFunctionImports();
+ for (FunctionImport functionImport : functionImports) {
+ if (functionImport.getName().equals(name)) {
+ return functionImport;
+ }
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public List<Schema> getSchemas() throws ODataException {
+ return new ArrayList<Schema>(namespace2Schema.values());
+ }
+
+ //
+ //
+ //
+ private Map<String, SchemaBuilder> namespace2SchemaBuilder = new HashMap<String, SchemaBuilder>();
+
+ private void updateSchema(Class<?> aClass) {
+ EdmEntityType et = aClass.getAnnotation(EdmEntityType.class);
+ if (et != null) {
+ updateSchema(aClass, et);
+ }
+ EdmComplexType ect = aClass.getAnnotation(EdmComplexType.class);
+ if (ect != null) {
+ updateSchema(aClass, ect);
+ }
+ }
+
+ private void updateSchema(Class<?> aClass, EdmEntityType et) {
+ SchemaBuilder b = getSchemaBuilder(et.namespace(), aClass);
+ TypeBuilder typeBuilder = TypeBuilder.init(et, aClass);
+ b.addEntityType(typeBuilder.buildEntityType());
+ b.addAssociations(typeBuilder.buildAssociations());
+ }
+
+ private SchemaBuilder getSchemaBuilder(String namespace, Class<?> aClass) {
+ String usedNamespace = namespace;
+ if(usedNamespace.isEmpty()) {
+ usedNamespace = ANNOTATION_HELPER.getCanonicalNamespace(aClass);
+ }
+ SchemaBuilder builder = namespace2SchemaBuilder.get(usedNamespace);
+ if (builder == null) {
+ builder = SchemaBuilder.init(usedNamespace);
+ namespace2SchemaBuilder.put(usedNamespace, builder);
+ }
+ return builder;
+ }
+
+ private void updateSchema(Class<?> aClass, EdmComplexType et) {
+ SchemaBuilder b = getSchemaBuilder(et.namespace(), aClass);
+ TypeBuilder typeBuilder = TypeBuilder.init(et, aClass);
+ b.addComplexType(typeBuilder.buildComplexType());
+ }
+
+ private void handleEntityContainer(Class<?> aClass) {
+ EdmEntityType entityType = aClass.getAnnotation(EdmEntityType.class);
+ if (entityType != null) {
+ FullQualifiedName typeName = createFqnForEntityType(aClass, entityType);
+ String containerName = ANNOTATION_HELPER.extractContainerName(aClass);
+ ContainerBuilder builder = containerName2ContainerBuilder.get(containerName);
+ if (builder == null) {
+ builder = ContainerBuilder.init(typeName.getNamespace(), containerName);
+ containerName2ContainerBuilder.put(containerName, builder);
+ }
+ EdmEntitySet entitySet = aClass.getAnnotation(EdmEntitySet.class);
+ if (entitySet != null) {
+ builder.addEntitySet(createEntitySet(typeName, entitySet));
+ }
+ }
+ }
+
+ private EntitySet createEntitySet(FullQualifiedName typeName, EdmEntitySet entitySet) {
+ return new EntitySet().setName(entitySet.name()).setEntityType(typeName);
+ }
+
+ private FullQualifiedName createFqnForEntityType(Class<?> annotatedClass, EdmEntityType entityType) {
+ return ANNOTATION_HELPER.extractEntityTypeFqn(annotatedClass);
+ }
+
+ private void finish() {
+ //
+ Collection<ContainerBuilder> containers = containerName2ContainerBuilder.values();
+ for (ContainerBuilder containerBuilder : containers) {
+ SchemaBuilder schemaBuilder = namespace2SchemaBuilder.get(containerBuilder.getNamespace());
+ containerBuilder.addAssociationSets(schemaBuilder.name2Associations.values());
+ final EntityContainer container = containerBuilder.build();
+ schemaBuilder.addEntityContainer(container);
+ name2Container.put(container.getName(), container);
+ if (container.isDefaultEntityContainer()) {
+ defaultContainer = container;
+ }
+ }
+ //
+ Collection<SchemaBuilder> schemaBuilders = namespace2SchemaBuilder.values();
+ for (SchemaBuilder schemaBuilder : schemaBuilders) {
+ final Schema schema = schemaBuilder.build();
+ namespace2Schema.put(schema.getNamespace(), schema);
+ }
+ }
+
+ //
+ //
+ //
+ static class TypeBuilder {
+
+ final private String namespace;
+ final private String name;
+ private boolean isAbstract = false;
+ private boolean isMediaResource = false;
+ private FullQualifiedName baseEntityType = null;
+ private final List<PropertyRef> keyProperties = new ArrayList<PropertyRef>();
+ private final List<Property> properties = new ArrayList<Property>();
+ private final List<NavigationProperty> navProperties = new ArrayList<NavigationProperty>();
+ private final List<Association> associations = new ArrayList<Association>();
+
+ public TypeBuilder(FullQualifiedName fqn) {
+ this.namespace = fqn.getNamespace();
+ this.name = fqn.getName();
+ }
+
+ public static TypeBuilder init(EdmEntityType entity, Class<?> aClass) {
+ return new TypeBuilder(ANNOTATION_HELPER.extractEntityTypeFqn(entity, aClass)).withClass(aClass);
+ }
+
+ public static TypeBuilder init(EdmComplexType entity, Class<?> aClass) {
+ return new TypeBuilder(ANNOTATION_HELPER.extractComplexTypeFqn(entity, aClass)).withClass(aClass);
+ }
+
+ private TypeBuilder withClass(Class<?> aClass) {
+ baseEntityType = createBaseEntityFqn(aClass);
+
+ if (Modifier.isAbstract(aClass.getModifiers())) {
+ this.isAbstract = true;
+ }
+
+ Field[] fields = aClass.getDeclaredFields();
+ for (Field field : fields) {
+ EdmProperty ep = field.getAnnotation(EdmProperty.class);
+ if (ep != null) {
+ properties.add(createProperty(ep, field, namespace));
+ EdmKey eti = field.getAnnotation(EdmKey.class);
+ if (eti != null) {
+ keyProperties.add(createKeyProperty(ep, field));
+ }
+ }
+ EdmNavigationProperty enp = field.getAnnotation(EdmNavigationProperty.class);
+ if (enp != null) {
+ final NavigationProperty navProperty = createNavigationProperty(namespace, enp, field);
+ navProperties.add(navProperty);
+ Association association = createAssociation(field, navProperty);
+ associations.add(association);
+ }
+ EdmMediaResourceContent emrc = field.getAnnotation(EdmMediaResourceContent.class);
+ if (emrc != null) {
+ isMediaResource = true;
+ }
+ }
+
+ return this;
+ }
+
+ public TypeBuilder addProperty(PropertyRef property) {
+ keyProperties.add(property);
+ return this;
+ }
+
+ public TypeBuilder addProperty(Property property) {
+ properties.add(property);
+ return this;
+ }
+
+ public TypeBuilder addNavigationProperty(NavigationProperty property) {
+ navProperties.add(property);
+ return this;
+ }
+
+ public TypeBuilder setAbstract(boolean isAbstract) {
+ this.isAbstract = isAbstract;
+ return this;
+ }
+
+ public ComplexType buildComplexType() {
+ ComplexType complexType = new ComplexType();
+ if (baseEntityType != null) {
+ complexType.setBaseType(baseEntityType);
+ }
+ return complexType.setName(name).setProperties(properties);
+ }
+
+ public EntityType buildEntityType() {
+ EntityType entityType = new EntityType();
+ if (baseEntityType != null) {
+ entityType.setBaseType(baseEntityType);
+ }
+ if (!keyProperties.isEmpty()) {
+ entityType.setKey(new Key().setKeys(keyProperties));
+ }
+ if (!navProperties.isEmpty()) {
+ entityType.setNavigationProperties(navProperties);
+ }
+ return entityType.setName(name)
+ .setAbstract(isAbstract)
+ .setHasStream(isMediaResource)
+ .setProperties(properties);
+ }
+
+ public Collection<Association> buildAssociations() {
+ return Collections.unmodifiableCollection(associations);
+ }
+
+ private PropertyRef createKeyProperty(EdmProperty et, Field field) {
+ PropertyRef keyProperty = new PropertyRef();
+ String entityName = et.name();
+ if (entityName.isEmpty()) {
+ entityName = getCanonicalName(field);
+ }
+ return keyProperty.setName(entityName);
+ }
+
+ private Property createProperty(EdmProperty ep, Field field, String defaultNamespace) {
+ if (isAnnotatedEntity(field.getType())) {
+ return createComplexProperty(field, defaultNamespace);
+ } else {
+ return createSimpleProperty(ep, field);
+ }
+ }
+
+ private Property createSimpleProperty(EdmProperty ep, Field field) {
+ SimpleProperty sp = new SimpleProperty();
+ String entityName = ANNOTATION_HELPER.getPropertyName(field);
+ sp.setName(entityName);
+ //
+ EdmType type = ep.type();
+ if (type == EdmType.NULL) {
+ type = getEdmType(field.getType());
+ }
+ sp.setType(ANNOTATION_HELPER.mapTypeKind(type));
+
+ return sp;
+ }
+
+ private Property createComplexProperty(Field field, String defaultNamespace) {
+ ComplexProperty cp = new ComplexProperty();
+ // settings from property
+ String entityName = ANNOTATION_HELPER.getPropertyName(field);
+ cp.setName(entityName);
+
+ // settings from related complex entity
+ EdmComplexType ece = field.getType().getAnnotation(EdmComplexType.class);
+ String complexEntityNamespace = ece.namespace();
+ if (complexEntityNamespace.isEmpty()) {
+ complexEntityNamespace = defaultNamespace;
+ }
+ cp.setType(new FullQualifiedName(complexEntityNamespace, ece.name()));
+
+ return cp;
+ }
+
+ private NavigationProperty createNavigationProperty(String namespace, EdmNavigationProperty enp, Field field) {
+ NavigationProperty navProp = new NavigationProperty();
+ navProp.setName(ANNOTATION_HELPER.getPropertyName(field));
+ String fromRole = ANNOTATION_HELPER.extractFromRoleName(enp, field);
+ navProp.setFromRole(fromRole);
+
+ String toRole = ANNOTATION_HELPER.extractToRoleName(enp, field);
+ navProp.setToRole(toRole);
+
+ String relationshipName = ANNOTATION_HELPER.extractRelationshipName(enp, field);
+ navProp.setRelationship(new FullQualifiedName(namespace, relationshipName));
+
+ return navProp;
+ }
+
+// private EdmSimpleTypeKind getEdmSimpleType(Class<?> type) {
+// if (type == String.class) {
+// return EdmType.String;
+// } else if (type == boolean.class || type == Boolean.class) {
+// return EdmType.Boolean;
+// } else if (type == byte.class || type == Byte.class) {
+// return EdmType.SByte;
+// } else if (type == short.class || type == Short.class) {
+// return EdmType.Int16;
+// } else if (type == int.class || type == Integer.class) {
+// return EdmType.Int32;
+// } else if (type == long.class || type == Long.class) {
+// return EdmType.Int64;
+// } else if (type == double.class || type == Double.class) {
+// return EdmType.Double;
+// } else if (type == float.class || type == Float.class) {
+// return EdmType.Single;
+// } else if (type == BigInteger.class || type == BigDecimal.class) {
+// return EdmType.Decimal;
+// } else if (type == Byte[].class || type == byte[].class) {
+// return EdmType.Binary;
+// } else if (type == Date.class) {
+// return EdmType.DateTime;
+// } else if (type == Calendar.class) {
+// return EdmType.DateTimeOffset;
+// } else if (type == UUID.class) {
+// return EdmType.Guid;
+// } else {
+// throw new UnsupportedOperationException("Not yet supported type '" + type + "'.");
+// }
+// }
+
+ private EdmType getEdmType(Class<?> type) {
+ if (type == String.class) {
+ return EdmType.STRING;
+ } else if (type == boolean.class || type == Boolean.class) {
+ return EdmType.BOOLEAN;
+ } else if (type == byte.class || type == Byte.class) {
+ return EdmType.SBYTE;
+ } else if (type == short.class || type == Short.class) {
+ return EdmType.INT16;
+ } else if (type == int.class || type == Integer.class) {
+ return EdmType.INT32;
+ } else if (type == long.class || type == Long.class) {
+ return EdmType.INT64;
+ } else if (type == double.class || type == Double.class) {
+ return EdmType.DOUBLE;
+ } else if (type == float.class || type == Float.class) {
+ return EdmType.SINGLE;
+ } else if (type == BigInteger.class || type == BigDecimal.class) {
+ return EdmType.DECIMAL;
+ } else if (type == Byte[].class || type == byte[].class) {
+ return EdmType.BINARY;
+ } else if (type == Date.class) {
+ return EdmType.DATE_TIME;
+ } else if (type == Calendar.class) {
+ return EdmType.DATE_TIME_OFFSET;
+ } else if (type == UUID.class) {
+ return EdmType.GUID;
+ } else {
+ throw new UnsupportedOperationException("Not yet supported type '" + type + "'.");
+ }
+ }
+
+
+ private Class<?> checkForBaseEntityClass(Class<?> aClass) {
+ Class<?> superClass = aClass.getSuperclass();
+ if (superClass == Object.class) {
+ return null;
+ } else {
+ EdmEntityType edmEntity = superClass.getAnnotation(EdmEntityType.class);
+ if (edmEntity == null) {
+ return checkForBaseEntityClass(superClass);
+ } else {
+ return superClass;
+ }
+ }
+ }
+
+ private FullQualifiedName createBaseEntityFqn(Class<?> aClass) {
+ Class<?> baseEntityClass = checkForBaseEntityClass(aClass);
+ if (baseEntityClass == null) {
+ return null;
+ }
+ return ANNOTATION_HELPER.extractEntityTypeFqn(baseEntityClass);
+ }
+
+ private Association createAssociation(Field field, NavigationProperty navProperty) {
+ Association association = new Association();
+ EdmNavigationProperty navigation = field.getAnnotation(EdmNavigationProperty.class);
+
+ AssociationEnd fromEnd = new AssociationEnd();
+ fromEnd.setRole(navProperty.getFromRole());
+ String typeName = ANNOTATION_HELPER.extractEntityTypeName(field.getDeclaringClass());
+ fromEnd.setType(new FullQualifiedName(namespace, typeName));
+ fromEnd.setMultiplicity(EdmMultiplicity.ONE);
+ association.setEnd1(fromEnd);
+
+ AssociationEnd toEnd = new AssociationEnd();
+ toEnd.setRole(navProperty.getToRole());
+ String toTypeName = ANNOTATION_HELPER.extractEntitTypeName(navigation, field);
+ toEnd.setType(new FullQualifiedName(namespace, toTypeName));
+ toEnd.setMultiplicity(ANNOTATION_HELPER.getMultiplicity(navigation, field));
+ association.setEnd2(toEnd);
+
+ String associationName = navProperty.getRelationship().getName();
+ association.setName(associationName);
+ return association;
+ }
+
+ private String getCanonicalName(Field field) {
+ return ANNOTATION_HELPER.getCanonicalName(field);
+ }
+
+ private boolean isAnnotatedEntity(Class<?> clazz) {
+ return ANNOTATION_HELPER.isEdmTypeAnnotated(clazz);
+ }
+ }
+
+ static class SchemaBuilder {
+
+ final private String namespace;
+ // private String alias;
+ private final List<Using> usings = new ArrayList<Using>();
+ private final List<EntityType> entityTypes = new ArrayList<EntityType>();
+ private final List<ComplexType> complexTypes = new ArrayList<ComplexType>();
+ private final Map<String, Association> name2Associations = new HashMap<String, Association>();
+ private final List<EntityContainer> entityContainers = new ArrayList<EntityContainer>();
+ private final List<AnnotationAttribute> annotationAttributes = new ArrayList<AnnotationAttribute>();
+ private final List<AnnotationElement> annotationElements = new ArrayList<AnnotationElement>();
+
+ private SchemaBuilder(String namespace) {
+ this.namespace = namespace;
+ }
+
+ public static SchemaBuilder init(String namespace) {
+ return new SchemaBuilder(namespace);
+ }
+
+ public SchemaBuilder addEntityType(EntityType type) {
+ entityTypes.add(type);
+ return this;
+ }
+
+ public SchemaBuilder addEntityContainer(EntityContainer container) {
+ entityContainers.add(container);
+ return this;
+ }
+
+ public SchemaBuilder addComplexType(ComplexType createEntityType) {
+ complexTypes.add(createEntityType);
+ return this;
+ }
+
+ public void addAssociations(Collection<Association> associations) {
+ for (Association association : associations) {
+ final String relationshipName = association.getName();
+ if (name2Associations.containsKey(relationshipName)) {
+ association = mergeAssociations(name2Associations.get(relationshipName), association);
+ }
+ name2Associations.put(relationshipName, association);
+ }
+ }
+
+ private Association mergeAssociations(Association associationOne, Association associationTwo) {
+ AssociationEnd oneEnd1 = associationOne.getEnd1();
+ AssociationEnd oneEnd2 = associationOne.getEnd2();
+ AssociationEnd twoEnd1 = associationTwo.getEnd1();
+ AssociationEnd twoEnd2 = associationTwo.getEnd2();
+ AssociationEnd[] oneEnds = new AssociationEnd[] { oneEnd1, oneEnd2 };
+
+ for (AssociationEnd associationEnd : oneEnds) {
+ if (associationEnd.getRole().equals(twoEnd1.getRole())) {
+ if (twoEnd1.getMultiplicity() == EdmMultiplicity.MANY) {
+ associationEnd.setMultiplicity(EdmMultiplicity.MANY);
+ }
+ } else if (associationEnd.getRole().equals(twoEnd2.getRole())) {
+ if (twoEnd2.getMultiplicity() == EdmMultiplicity.MANY) {
+ associationEnd.setMultiplicity(EdmMultiplicity.MANY);
+ }
+ }
+ }
+
+ return associationOne;
+ }
+
+ public Schema build() {
+ Schema s = new Schema();
+ s.setUsings(usings);
+ s.setEntityTypes(entityTypes);
+ s.setComplexTypes(complexTypes);
+ s.setAssociations(new ArrayList<Association>(name2Associations.values()));
+ s.setEntityContainers(entityContainers);
+ s.setAnnotationAttributes(annotationAttributes);
+ s.setAnnotationElements(annotationElements);
+ s.setNamespace(namespace);
+ return s;
+ }
+ }
+
+ private static class ContainerBuilder {
+
+ final private String name;
+ final private String namespace;
+ private boolean defaultContainer = true;
+ private final List<EntitySet> entitySets = new ArrayList<EntitySet>();
+ private final List<AssociationSet> associationSets = new ArrayList<AssociationSet>();
+ private final List<FunctionImport> functionImports = new ArrayList<FunctionImport>();
+
+ // private Documentation documentation;
+
+ private ContainerBuilder(String namespace, String containerName) {
+ this.namespace = namespace;
+ name = containerName;
+ }
+
+ public String getNamespace() {
+ return namespace;
+ }
+
+ public static ContainerBuilder init(String namespace, String containerName) {
+ return new ContainerBuilder(namespace, containerName);
+ }
+
+ public ContainerBuilder setDefaultContainer(boolean isDefault) {
+ defaultContainer = isDefault;
+ return this;
+ }
+
+ public ContainerBuilder addEntitySet(EntitySet entitySet) {
+ entitySets.add(entitySet);
+ return this;
+ }
+
+ public void addAssociationSets(Collection<Association> associations) {
+ for (Association association : associations) {
+ AssociationSet as = new AssociationSet();
+ as.setName(association.getName());
+ FullQualifiedName asAssociationFqn = new FullQualifiedName(namespace, association.getName());
+ as.setAssociation(asAssociationFqn);
+
+ AssociationSetEnd asEnd1 = new AssociationSetEnd();
+ asEnd1.setEntitySet(getEntitySetName(association.getEnd1()));
+ asEnd1.setRole(association.getEnd1().getRole());
+ as.setEnd1(asEnd1);
+
+ AssociationSetEnd asEnd2 = new AssociationSetEnd();
+ asEnd2.setEntitySet(getEntitySetName(association.getEnd2()));
+ asEnd2.setRole(association.getEnd2().getRole());
+ as.setEnd2(asEnd2);
+
+ associationSets.add(as);
+ }
+ }
+
+ public EntityContainer build() {
+ EntityContainer ec = new EntityContainer();
+ ec.setName(name);
+ ec.setDefaultEntityContainer(defaultContainer);
+ ec.setEntitySets(entitySets);
+ ec.setAssociationSets(associationSets);
+ ec.setFunctionImports(functionImports);
+ return ec;
+ }
+
+ private String getEntitySetName(AssociationEnd end) {
+ for (EntitySet entitySet : entitySets) {
+ if (entitySet.getEntityType().equals(end.getType())) {
+ return entitySet.getName();
+ }
+ }
+ throw new ODataRuntimeException("No entity set found for " + end.getType());
+ }
+ }
+}
[36/52] git commit: Removed dependcy from 'api-annotations' to 'api'
Posted by mi...@apache.org.
Removed dependcy from 'api-annotations' to 'api'
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/09344a5b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/09344a5b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/09344a5b
Branch: refs/heads/master
Commit: 09344a5bc0f2c370a44aec218c1d9ea0bfae10a9
Parents: 7030c24
Author: Michael Bolz <mi...@apache.org>
Authored: Tue Dec 3 14:18:12 2013 +0100
Committer: Michael Bolz <mi...@apache.org>
Committed: Tue Dec 3 14:18:12 2013 +0100
----------------------------------------------------------------------
.../annotation/edm/AnnotationEdmProvider.java | 71 ++++++++++++++------
.../core/annotation/edm/AnnotationHelper.java | 31 ++++++++-
.../processor/json/EdmAnnotationSerializer.java | 12 ++--
.../odata2/core/annotation/model/Building.java | 6 +-
.../odata2/core/annotation/model/Employee.java | 7 +-
.../odata2/core/annotation/model/Photo.java | 4 +-
.../odata2/core/annotation/model/RefBase.java | 4 +-
.../odata2/core/annotation/model/Team.java | 4 +-
.../odata2/ref/annotation/model/Building.java | 7 +-
.../odata2/ref/annotation/model/Employee.java | 7 +-
.../odata2/ref/annotation/model/Photo.java | 5 +-
.../odata2/ref/annotation/model/RefBase.java | 6 +-
.../odata2/ref/annotation/model/Team.java | 4 +-
.../edm/EdmFunctionImportParameter.java | 12 ++--
.../odata2/api/annotation/edm/EdmProperty.java | 13 ++--
.../odata2/api/annotation/edm/EdmType.java | 31 +++++++++
16 files changed, 163 insertions(+), 61 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/09344a5b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java
index 7dfbd0e..1b53d58 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java
@@ -39,8 +39,8 @@ import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceContent;
import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmType;
import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
-import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
import org.apache.olingo.odata2.api.edm.FullQualifiedName;
import org.apache.olingo.odata2.api.edm.provider.AnnotationAttribute;
import org.apache.olingo.odata2.api.edm.provider.AnnotationElement;
@@ -453,11 +453,11 @@ public class AnnotationEdmProvider extends EdmProvider {
String entityName = ANNOTATION_HELPER.getPropertyName(field);
sp.setName(entityName);
//
- EdmSimpleTypeKind type = ep.type();
- if (type == EdmSimpleTypeKind.Null) {
- type = getEdmSimpleType(field.getType());
+ EdmType type = ep.type();
+ if (type == EdmType.NULL) {
+ type = getEdmType(field.getType());
}
- sp.setType(type);
+ sp.setType(ANNOTATION_HELPER.mapTypeKind(type));
return sp;
}
@@ -494,38 +494,71 @@ public class AnnotationEdmProvider extends EdmProvider {
return navProp;
}
- private EdmSimpleTypeKind getEdmSimpleType(Class<?> type) {
+// private EdmSimpleTypeKind getEdmSimpleType(Class<?> type) {
+// if (type == String.class) {
+// return EdmType.String;
+// } else if (type == boolean.class || type == Boolean.class) {
+// return EdmType.Boolean;
+// } else if (type == byte.class || type == Byte.class) {
+// return EdmType.SByte;
+// } else if (type == short.class || type == Short.class) {
+// return EdmType.Int16;
+// } else if (type == int.class || type == Integer.class) {
+// return EdmType.Int32;
+// } else if (type == long.class || type == Long.class) {
+// return EdmType.Int64;
+// } else if (type == double.class || type == Double.class) {
+// return EdmType.Double;
+// } else if (type == float.class || type == Float.class) {
+// return EdmType.Single;
+// } else if (type == BigInteger.class || type == BigDecimal.class) {
+// return EdmType.Decimal;
+// } else if (type == Byte[].class || type == byte[].class) {
+// return EdmType.Binary;
+// } else if (type == Date.class) {
+// return EdmType.DateTime;
+// } else if (type == Calendar.class) {
+// return EdmType.DateTimeOffset;
+// } else if (type == UUID.class) {
+// return EdmType.Guid;
+// } else {
+// throw new UnsupportedOperationException("Not yet supported type '" + type + "'.");
+// }
+// }
+
+ private EdmType getEdmType(Class<?> type) {
if (type == String.class) {
- return EdmSimpleTypeKind.String;
+ return EdmType.STRING;
} else if (type == boolean.class || type == Boolean.class) {
- return EdmSimpleTypeKind.Boolean;
+ return EdmType.BOOLEAN;
} else if (type == byte.class || type == Byte.class) {
- return EdmSimpleTypeKind.SByte;
+ return EdmType.SBYTE;
} else if (type == short.class || type == Short.class) {
- return EdmSimpleTypeKind.Int16;
+ return EdmType.INT16;
} else if (type == int.class || type == Integer.class) {
- return EdmSimpleTypeKind.Int32;
+ return EdmType.INT32;
} else if (type == long.class || type == Long.class) {
- return EdmSimpleTypeKind.Int64;
+ return EdmType.INT64;
} else if (type == double.class || type == Double.class) {
- return EdmSimpleTypeKind.Double;
+ return EdmType.DOUBLE;
} else if (type == float.class || type == Float.class) {
- return EdmSimpleTypeKind.Single;
+ return EdmType.SINGLE;
} else if (type == BigInteger.class || type == BigDecimal.class) {
- return EdmSimpleTypeKind.Decimal;
+ return EdmType.DECIMAL;
} else if (type == Byte[].class || type == byte[].class) {
- return EdmSimpleTypeKind.Binary;
+ return EdmType.BINARY;
} else if (type == Date.class) {
- return EdmSimpleTypeKind.DateTime;
+ return EdmType.DATE_TIME;
} else if (type == Calendar.class) {
- return EdmSimpleTypeKind.DateTimeOffset;
+ return EdmType.DATE_TIME_OFFSET;
} else if (type == UUID.class) {
- return EdmSimpleTypeKind.Guid;
+ return EdmType.GUID;
} else {
throw new UnsupportedOperationException("Not yet supported type '" + type + "'.");
}
}
+
private Class<?> checkForBaseEntityClass(Class<?> aClass) {
Class<?> superClass = aClass.getSuperclass();
if (superClass == Object.class) {
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/09344a5b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java
index f25d9b9..94edb0a 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java
@@ -615,7 +615,7 @@ public class AnnotationHelper {
Class<?> fieldClass = field.getType();
try {
EdmProperty property = field.getAnnotation(EdmProperty.class);
- EdmSimpleTypeKind type = property.type();
+ EdmSimpleTypeKind type = mapTypeKind(property.type());
return type.getEdmSimpleTypeInstance().valueOfString(propertyValue,
EdmLiteralKind.DEFAULT, null, fieldClass);
} catch (EdmSimpleTypeException ex) {
@@ -663,8 +663,37 @@ public class AnnotationHelper {
return content.substring(0, 1).toUpperCase(Locale.ENGLISH) + content.substring(1);
}
+ public EdmSimpleTypeKind mapTypeKind(org.apache.olingo.odata2.api.annotation.edm.EdmType type) {
+ switch (type) {
+ case BINARY: return EdmSimpleTypeKind.Binary;
+ case BOOLEAN: return EdmSimpleTypeKind.Boolean;
+ case BYTE: return EdmSimpleTypeKind.Byte;
+ case COMPLEX: return EdmSimpleTypeKind.Null;
+ case DATE_TIME: return EdmSimpleTypeKind.DateTime;
+ case DATE_TIME_OFFSET: return EdmSimpleTypeKind.DateTimeOffset;
+ case DECIMAL: return EdmSimpleTypeKind.Decimal;
+ case DOUBLE: return EdmSimpleTypeKind.Double;
+ case GUID: return EdmSimpleTypeKind.Guid;
+ case INT16: return EdmSimpleTypeKind.Int16;
+ case INT32: return EdmSimpleTypeKind.Int32;
+ case INT64: return EdmSimpleTypeKind.Int64;
+ case NULL: return EdmSimpleTypeKind.Null;
+ case SBYTE: return EdmSimpleTypeKind.SByte;
+ case SINGLE: return EdmSimpleTypeKind.Single;
+ case STRING: return EdmSimpleTypeKind.String;
+ case TIME: return EdmSimpleTypeKind.Time;
+ default: throw new ODataRuntimeException("Unknown type '" + type
+ + "' for mapping to EdmSimpleTypeKind.");
+ }
+ }
+
+ /**
+ *
+ */
private static class EdmAnnotationException extends RuntimeException {
+ private static final long serialVersionUID = 42L;
+
public EdmAnnotationException(String message) {
super(message);
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/09344a5b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/json/EdmAnnotationSerializer.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/json/EdmAnnotationSerializer.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/json/EdmAnnotationSerializer.java
index 6e1d8ea..7ae9971 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/json/EdmAnnotationSerializer.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/json/EdmAnnotationSerializer.java
@@ -25,11 +25,12 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmType;
import org.apache.olingo.odata2.api.edm.EdmLiteralKind;
import org.apache.olingo.odata2.api.edm.EdmSimpleTypeException;
import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
@@ -178,8 +179,8 @@ public class EdmAnnotationSerializer {
}
private EdmSimpleTypeKind getDefaultSimpleTypeKind(Field field, EdmProperty property) {
- final EdmSimpleTypeKind type = property.type();
- if (type == EdmSimpleTypeKind.Null) {
+ final EdmType type = property.type();
+ if (type == EdmType.NULL) {
Class<?> fieldType = field.getType();
if (fieldType == String.class) {
return EdmSimpleTypeKind.String;
@@ -189,11 +190,12 @@ public class EdmAnnotationSerializer {
return EdmSimpleTypeKind.Int32;
}
}
- return type;
+ return ANNOTATION_HELPER.mapTypeKind(type);
}
private Class<?> getType(EdmProperty property) {
- Class<?> defaultType = property.type().getEdmSimpleTypeInstance().getDefaultType();
+ EdmSimpleTypeKind type = ANNOTATION_HELPER.mapTypeKind(property.type());
+ Class<?> defaultType = type.getEdmSimpleTypeInstance().getDefaultType();
return defaultType;
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/09344a5b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Building.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Building.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Building.java
index 15cd3ae..bf43580 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Building.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Building.java
@@ -27,8 +27,8 @@ import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmType;
import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
-import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
/**
*
@@ -37,11 +37,11 @@ import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
@EdmEntitySet(name = "Buildings")
public class Building {
@EdmKey
- @EdmProperty(type = EdmSimpleTypeKind.Int32)
+ @EdmProperty(type = EdmType.INT32)
private String id;
@EdmProperty
private String name;
- @EdmProperty(name = "Image", type = EdmSimpleTypeKind.Binary)
+ @EdmProperty(name = "Image", type = EdmType.BINARY)
private byte[] image;
@EdmNavigationProperty(name = "nb_Rooms", toType = Room.class,
association = "BuildingRooms", toMultiplicity = EdmMultiplicity.MANY)
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/09344a5b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Employee.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Employee.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Employee.java
index dc97c68..63b8a76 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Employee.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Employee.java
@@ -28,7 +28,7 @@ import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceContent;
import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceMimeType;
import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
-import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
+import org.apache.olingo.odata2.api.annotation.edm.EdmType;
/**
*
@@ -36,9 +36,8 @@ import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
@EdmEntityType(name = "Employee", namespace = ModelSharedConstants.NAMESPACE_1)
@EdmEntitySet(name = "Employees")
public class Employee {
- private static int counter = 1;
@EdmKey
- @EdmProperty(name = "EmployeeId", type = EdmSimpleTypeKind.String)
+ @EdmProperty(name = "EmployeeId", type = EdmType.STRING)
private String employeeId;
@EdmProperty(name = "EmployeeName")
private String employeeName;
@@ -56,7 +55,7 @@ public class Employee {
private byte[] image;
@EdmProperty(name = "ImageUrl")
private String imageUrl;
- @EdmProperty(name = "EntryDate", type = EdmSimpleTypeKind.DateTime)
+ @EdmProperty(name = "EntryDate", type = EdmType.DATE_TIME)
private Calendar entryDate;
@EdmProperty(name = "Location")
private Location location;
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/09344a5b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Photo.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Photo.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Photo.java
index df7d687..520216a 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Photo.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Photo.java
@@ -27,7 +27,7 @@ import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceContent;
import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceMimeType;
import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceSource;
import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
-import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
+import org.apache.olingo.odata2.api.annotation.edm.EdmType;
/**
*
@@ -47,7 +47,7 @@ public class Photo {
@EdmProperty
@EdmMediaResourceSource
private String imageUrl = "http://localhost/someResource.png";
- @EdmProperty(type = EdmSimpleTypeKind.Binary)
+ @EdmProperty(type = EdmType.BINARY)
@EdmMediaResourceContent
private byte[] image = ResourceHelper.generateImage();
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/09344a5b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/RefBase.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/RefBase.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/RefBase.java
index c38a506..6f3002f 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/RefBase.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/RefBase.java
@@ -19,7 +19,7 @@ package org.apache.olingo.odata2.core.annotation.model;
import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
-import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
+import org.apache.olingo.odata2.api.annotation.edm.EdmType;
/**
*
@@ -28,7 +28,7 @@ import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
public abstract class RefBase {
@EdmProperty(name="Name")
protected String name;
- @EdmProperty(name="Id", type = EdmSimpleTypeKind.String)
+ @EdmProperty(name="Id", type = EdmType.STRING)
@EdmKey
protected int id;
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/09344a5b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Team.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Team.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Team.java
index 6e3463b..23ad181 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Team.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Team.java
@@ -25,8 +25,8 @@ import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmType;
import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
-import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
/**
*
@@ -34,7 +34,7 @@ import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
@EdmEntityType(name = "Team", namespace = ModelSharedConstants.NAMESPACE_1)
@EdmEntitySet(name = "Teams")
public class Team extends RefBase {
- @EdmProperty(type = EdmSimpleTypeKind.Boolean)
+ @EdmProperty(type = EdmType.BOOLEAN)
private Boolean isScrumTeam;
@EdmNavigationProperty(name = "nt_Employees", association = "TeamEmployees", toMultiplicity = EdmMultiplicity.MANY)
private List<Employee> employees = new ArrayList<Employee>();
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/09344a5b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Building.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Building.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Building.java
index bb50759..503ccfd 100644
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Building.java
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Building.java
@@ -21,13 +21,14 @@ package org.apache.olingo.odata2.ref.annotation.model;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+
import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmType;
import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
-import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
/**
*
@@ -36,11 +37,11 @@ import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
@EdmEntitySet(name = "Buildings")
public class Building {
@EdmKey
- @EdmProperty(type = EdmSimpleTypeKind.Int32)
+ @EdmProperty(type = EdmType.INT32)
private int id;
@EdmProperty
private String name;
- @EdmProperty(name = "Image", type = EdmSimpleTypeKind.Binary)
+ @EdmProperty(name = "Image", type = EdmType.BINARY)
private byte[] image;
@EdmNavigationProperty(name = "nb_Rooms", toType = Room.class,
association = "BuildingRooms", toMultiplicity = EdmMultiplicity.MANY)
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/09344a5b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Employee.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Employee.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Employee.java
index 2975d1b..2204ee8 100644
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Employee.java
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Employee.java
@@ -29,7 +29,7 @@ import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceContent;
import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceMimeType;
import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
-import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
+import org.apache.olingo.odata2.api.annotation.edm.EdmType;
/**
*
@@ -37,9 +37,8 @@ import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
@EdmEntityType(name = "Employee", namespace = ModelSharedConstants.NAMESPACE_1)
@EdmEntitySet(name = "Employees")
public class Employee {
- private static int counter = 1;
@EdmKey
- @EdmProperty(name = "EmployeeId", type = EdmSimpleTypeKind.String)
+ @EdmProperty(name = "EmployeeId", type = EdmType.STRING)
private String employeeId;
@EdmProperty(name = "EmployeeName")
private String employeeName;
@@ -57,7 +56,7 @@ public class Employee {
private byte[] image;
@EdmProperty(name = "ImageUrl")
private String imageUrl;
- @EdmProperty(name = "EntryDate", type = EdmSimpleTypeKind.DateTime,
+ @EdmProperty(name = "EntryDate", type = EdmType.DATE_TIME,
facets = @EdmFacets(nullable = true))
private Calendar entryDate;
@EdmProperty(name = "Location", facets = @EdmFacets(nullable = false))
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/09344a5b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Photo.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Photo.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Photo.java
index eafee7b..52971cd 100644
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Photo.java
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Photo.java
@@ -19,6 +19,7 @@
package org.apache.olingo.odata2.ref.annotation.model;
import java.util.Arrays;
+
import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
@@ -26,7 +27,7 @@ import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceContent;
import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceMimeType;
import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceSource;
import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
-import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
+import org.apache.olingo.odata2.api.annotation.edm.EdmType;
/**
*
@@ -46,7 +47,7 @@ public class Photo {
@EdmProperty
@EdmMediaResourceSource
private String imageUrl = "http://localhost/someResource.png";
- @EdmProperty(type = EdmSimpleTypeKind.Binary)
+ @EdmProperty(type = EdmType.BINARY)
@EdmMediaResourceContent
private byte[] image = ResourceHelper.generateImage();
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/09344a5b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/RefBase.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/RefBase.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/RefBase.java
index 5f40d1e..727b8c3 100644
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/RefBase.java
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/RefBase.java
@@ -19,9 +19,9 @@
package org.apache.olingo.odata2.ref.annotation.model;
import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
-import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
+import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmType;
/**
*
@@ -30,7 +30,7 @@ import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
public abstract class RefBase {
@EdmProperty(name="Name")
protected String name;
- @EdmProperty(name="Id", type = EdmSimpleTypeKind.String)
+ @EdmProperty(name="Id", type = EdmType.STRING)
@EdmKey
protected String id;
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/09344a5b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Team.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Team.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Team.java
index 7cbe321..8320c54 100644
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Team.java
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Team.java
@@ -25,8 +25,8 @@ import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmType;
import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
-import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
/**
*
@@ -34,7 +34,7 @@ import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
@EdmEntityType(name = "Team", namespace = ModelSharedConstants.NAMESPACE_1)
@EdmEntitySet(name = "Teams")
public class Team extends RefBase {
- @EdmProperty(type = EdmSimpleTypeKind.Boolean)
+ @EdmProperty(type = EdmType.BOOLEAN)
private Boolean isScrumTeam;
@EdmNavigationProperty(name = "nt_Employees", association = "TeamEmployees", toMultiplicity = EdmMultiplicity.MANY)
private List<Employee> employees = new ArrayList<Employee>();
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/09344a5b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmFunctionImportParameter.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmFunctionImportParameter.java b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmFunctionImportParameter.java
index 74d1072..dca3d44 100644
--- a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmFunctionImportParameter.java
+++ b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmFunctionImportParameter.java
@@ -23,8 +23,6 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
-import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
-
/**
* <p>Annotation for definition of an {@link EdmFunctionImportParameter} for an {@link EdmFunctionImport}
* which contains the {@link EdmFunctionImportParameter} as a parameter.</p>
@@ -42,12 +40,18 @@ public @interface EdmFunctionImportParameter {
String name();
/**
* Define the EdmSimpleType which is used for the Function Import Parameter in the EDM.
- * If not set a default value has to be generated by the EDM provider (which should be compatible to the
+ * <p>
+ * If not explicit set a default value has to be generated by the EDM provider (which should be compatible to the
* java type of the annotated field).
+ * <p>
+ * If the property is a simple property a EdmSimpleType must be used which can be mapped to the
+ * java type of the annotated field. Which mappings are available depends on the used implementation.
+ * <p>
+ * If the property is a EdmComplexType (and no EdmSimpleType) the type <code>COMPLEX</code> must be used.
*
* @return type for the Function Import Parameter as used in the EDM
*/
- EdmSimpleTypeKind type() default EdmSimpleTypeKind.Null;
+ EdmType type() default EdmType.NULL;
/**
* Define the EdmFacets for the Function Import Parameter in the EDM.
* If not set the default EdmFacet values are used (see {@link EdmFacets}).
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/09344a5b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmProperty.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmProperty.java b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmProperty.java
index 6e45598..cc6fbba 100644
--- a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmProperty.java
+++ b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmProperty.java
@@ -23,8 +23,6 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
-import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
-
/**
* <p>Annotation for definition of an EdmProperty for an EdmEntityType or EdmComplexType
* which contains the EdmProperty as a field.</p>
@@ -35,13 +33,18 @@ import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
public @interface EdmProperty {
/**
* Define the EdmSimpleType which is used for the Property in the EDM.
- * If not set a default value has to be generated by the EDM provider (which should be compatible to the
+ * <p>
+ * If not explicit set a default value has to be generated by the EDM provider (which should be compatible to the
* java type of the annotated field).
- * If the property is a EdmComplexType (and no EdmSimpleType) the default value has to be used.
+ * <p>
+ * If the property is a simple property a EdmSimpleType must be used which can be mapped to the
+ * java type of the annotated field. Which mappings are available depends on the used implementation.
+ * <p>
+ * If the property is a EdmComplexType (and no EdmSimpleType) the type <code>COMPLEX</code> must be used.
*
* @return type for the Property as used in the EDM
*/
- EdmSimpleTypeKind type() default EdmSimpleTypeKind.Null;
+ EdmType type() default EdmType.NULL;
/**
* Define the name for the Property.
* If not set a default value has to be generated by the EDM provider.
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/09344a5b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmType.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmType.java b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmType.java
new file mode 100644
index 0000000..1b7b4a3
--- /dev/null
+++ b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmType.java
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * 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.api.annotation.edm;
+
+/**
+ * <p>The EdmTypes which can be used for property definition in the EDM.</p>
+ * The available values are based on <code>EdmSimpleTypeKind</code> values with the additional type
+ * <code>COMPLEX</code> which can be used to explicit define a EdmProperty as complex.
+ */
+public enum EdmType {
+ BINARY, BOOLEAN, BYTE, DATE_TIME, DATE_TIME_OFFSET, DECIMAL, DOUBLE,
+ GUID, INT16, INT32, INT64, SBYTE, SINGLE, STRING, TIME, NULL,
+ /** Only for explicit definition of a complex property. Not mappable to <code>EdmSimpleTypeKind</code> */
+ COMPLEX;
+}
[10/52] git commit: Merge branch 'master' of
https://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2 into
PocEdmAnnotationsExtension
Posted by mi...@apache.org.
Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2 into PocEdmAnnotationsExtension
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/4e6734d4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/4e6734d4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/4e6734d4
Branch: refs/heads/master
Commit: 4e6734d4b223289a2dd960578cd39399e977fc4a
Parents: 5af5559 5c3319b
Author: Michael Bolz <mi...@sap.com>
Authored: Tue Oct 15 22:02:07 2013 +0200
Committer: Michael Bolz <mi...@sap.com>
Committed: Tue Oct 15 22:32:56 2013 +0200
----------------------------------------------------------------------
.../ref/annotation/model/ResourceHelper.java | 57 +++++++-------------
1 file changed, 18 insertions(+), 39 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/4e6734d4/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ResourceHelper.java
----------------------------------------------------------------------
diff --cc odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ResourceHelper.java
index 07ee5b4,0000000..bba1c6b
mode 100644,000000..100644
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ResourceHelper.java
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ResourceHelper.java
@@@ -1,107 -1,0 +1,86 @@@
+/*******************************************************************************
+ * 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.ref.annotation.model;
+
+import java.awt.image.BufferedImage;
+import java.awt.image.WritableRaster;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
- import java.nio.ByteBuffer;
- import java.util.logging.Level;
- import java.util.logging.Logger;
+import javax.imageio.ImageIO;
- import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
+
+/**
+ *
+ */
+class ResourceHelper {
+
+ public static byte[] loadAsByte(String resource) {
+ return load(resource, new byte[0]);
+ }
+
+ public static byte[] load(String resource, byte[] defaultResult) {
+ InputStream instream = null;
+ try {
+ instream = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource);
+ if (instream == null) {
+ return defaultResult;
+ }
+ ByteArrayOutputStream stream = new ByteArrayOutputStream();
+ int b = 0;
+ while ((b = instream.read()) != -1) {
+ stream.write(b);
+ }
+
+ return stream.toByteArray();
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ } finally {
+ if(instream != null) {
+ try {
+ instream.close();
+ } catch (IOException ex) { }
+ }
+ }
+ }
+
- static byte[] generateImage() {
++ public static byte[] generateImage() {
+ try {
- // ByteArrayOutputStream outStream = new ByteArrayOutputStream();
- // String format = "PNG";
- // int width = 200;
- // int height = 200;
- // int imageType = BufferedImage.TYPE_BYTE_BINARY;
- // BufferedImage image = new BufferedImage(width, height, imageType);
- // ImageIO.write(image, format, outStream);
- // return null;
++ int width = 320;
++ int height = 320;
++ BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_BINARY);
++ WritableRaster raster = image.getRaster();
+
- return test();
- } catch (IOException ex) {
- return new byte[0];
- }
- }
-
- private static byte[] test() throws IOException {
- int width = 400; // Dimensions of the image
- int height = 400;
- // Let's create a BufferedImage for a binary image.
- BufferedImage im = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_BINARY);
- // We need its raster to set the pixels' values.
- WritableRaster raster = im.getRaster();
- // Put the pixels on the raster. Note that only values 0 and 1 are used for the pixels.
- // You could even use other values: in this type of image, even values are black and odd
- // values are white.
- for (int h = 0; h < height; h++) {
- for (int w = 0; w < width; w++) {
- if (((h / 50) + (w / 50)) % 2 == 0) {
- raster.setSample(w, h, 0, 0); // checkerboard pattern.
- } else {
- raster.setSample(w, h, 0, 1);
++ for (int h = 0; h < height; h++) {
++ for (int w = 0; w < width; w++) {
++ if (((h / 32) + (w / 32)) % 2 == 0) {
++ raster.setSample(w, h, 0, 0);
++ } else {
++ raster.setSample(w, h, 0, 1);
++ }
+ }
+ }
++
++ ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
++ ImageIO.write(image, "PNG", out);
++ return out.toByteArray();
++ } catch (IOException ex) {
++ return new byte[0];
+ }
- // Store the image using the PNG format.
- ByteArrayOutputStream out = new ByteArrayOutputStream(1024*10);
- ImageIO.write(im, "PNG", out);
- return out.toByteArray();
+ }
+}
[35/52] git commit: Added support for write binary
Posted by mi...@apache.org.
Added support for write binary
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/7030c241
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/7030c241
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/7030c241
Branch: refs/heads/master
Commit: 7030c241b2c78de83a178f9096df28ee047095d3
Parents: e39b0b9
Author: Michael Bolz <mi...@apache.org>
Authored: Tue Dec 3 09:46:16 2013 +0100
Committer: Michael Bolz <mi...@apache.org>
Committed: Tue Dec 3 09:47:26 2013 +0100
----------------------------------------------------------------------
.../annotation/data/AnnotationInMemoryDs.java | 15 +++++++--
.../annotation/data/AnnotationValueAccess.java | 4 ++-
.../odata2/core/annotation/data/DataStore.java | 3 +-
.../core/annotation/edm/AnnotationHelper.java | 34 +++++++++++++++-----
4 files changed, 43 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/7030c241/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationInMemoryDs.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationInMemoryDs.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationInMemoryDs.java
index 938a0d2..3389140 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationInMemoryDs.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationInMemoryDs.java
@@ -34,6 +34,7 @@ import org.apache.olingo.odata2.api.exception.ODataNotFoundException;
import org.apache.olingo.odata2.api.exception.ODataNotImplementedException;
import org.apache.olingo.odata2.core.annotation.edm.AnnotationHelper;
import org.apache.olingo.odata2.core.annotation.edm.AnnotationHelper.AnnotatedNavInfo;
+import org.apache.olingo.odata2.core.annotation.edm.AnnotationHelper.ODataAnnotationException;
import org.apache.olingo.odata2.core.annotation.edm.ClassHelper;
import org.apache.olingo.odata2.core.exception.ODataRuntimeException;
@@ -173,14 +174,22 @@ public class AnnotationInMemoryDs implements ListsDataSource {
return dataStore.createInstance();
}
- throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
+ throw new ODataRuntimeException("No DataStore found for entitySet with name: " + entitySet.getName());
}
@Override
- public void writeBinaryData(EdmEntitySet entitySet, Object mediaLinkEntryData, BinaryData binaryData)
+ public void writeBinaryData(EdmEntitySet entitySet, Object mediaEntityInstance, BinaryData binaryData)
throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException {
- throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
+ try {
+ ANNOTATION_HELPER.setValueForAnnotatedField(
+ mediaEntityInstance, EdmMediaResourceContent.class, binaryData.getData());
+ ANNOTATION_HELPER.setValueForAnnotatedField(
+ mediaEntityInstance, EdmMediaResourceMimeType.class, binaryData.getMimeType());
+ } catch (ODataAnnotationException e) {
+ throw new ODataRuntimeException("Invalid media resource annotation at entity set '" + entitySet.getName()
+ + "' with message '" + e.getMessage() + "'.", e);
+ }
}
/**
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/7030c241/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationValueAccess.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationValueAccess.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationValueAccess.java
index 3408c84..c29ac39 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationValueAccess.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationValueAccess.java
@@ -39,7 +39,9 @@ public class AnnotationValueAccess implements ValueAccess {
*/
@Override
public <T> Object getPropertyValue(final T data, final EdmProperty property) throws ODataException {
- if (annotationHelper.isEdmAnnotated(data)) {
+ if(data == null) {
+ return null;
+ } else if (annotationHelper.isEdmAnnotated(data)) {
return annotationHelper.getValueForProperty(data, property.getName());
}
throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/7030c241/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/DataStore.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/DataStore.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/DataStore.java
index f52e023..4e43db4 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/DataStore.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/DataStore.java
@@ -146,7 +146,7 @@ public class DataStore<T> {
fieldName2KeyValue.put(ANNOTATION_HELPER.getCanonicalName(field), key);
}
- ANNOTATION_HELPER.setValuesToAnnotatedFields(fieldName2KeyValue, object, EdmKey.class);
+ ANNOTATION_HELPER.setValuesToAnnotatedFields(object, EdmKey.class, fieldName2KeyValue);
return object;
}
@@ -167,6 +167,7 @@ public class DataStore<T> {
}
public static class DataStoreException extends ODataApplicationException {
+ private static final long serialVersionUID = 42L;
public DataStoreException(String message) {
this(message, null);
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/7030c241/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java
index 08699fa..f25d9b9 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java
@@ -298,6 +298,8 @@ public class AnnotationHelper {
}
public static final class ODataAnnotationException extends ODataException {
+ private static final long serialVersionUID = 1L;
+
public ODataAnnotationException(String message) {
super(message);
}
@@ -482,8 +484,23 @@ public class AnnotationHelper {
return fieldName2Value;
}
- public void setValuesToAnnotatedFields(Map<String, Object> fieldName2Value, Object instance,
- Class<? extends Annotation> annotation) {
+ public void setValueForAnnotatedField(Object instance, Class<? extends Annotation> annotation, Object value)
+ throws ODataAnnotationException {
+ List<Field> fields = getAnnotatedFields(instance, annotation);
+
+ if(fields.isEmpty()) {
+ throw new ODataAnnotationException("No field found for annotation '" + annotation
+ + "' on instance '" + instance + "'.");
+ } else if(fields.size() > 1) {
+ throw new ODataAnnotationException("More then one field found for annotation '" + annotation
+ + "' on instance '" + instance + "'.");
+ }
+
+ setFieldValue(instance, fields.get(0), value);
+ }
+
+ public void setValuesToAnnotatedFields(Object instance,
+ Class<? extends Annotation> annotation, Map<String, Object> fieldName2Value) {
List<Field> fields = getAnnotatedFields(instance, annotation);
// XXX: refactore
@@ -575,16 +592,17 @@ public class AnnotationHelper {
}
}
- private void setFieldValue(Object instance, Field field, Object propertyValue) {
+ private void setFieldValue(Object instance, Field field, Object value) {
try {
- if (propertyValue != null
- && field.getType() != propertyValue.getClass()
- && propertyValue.getClass() == String.class) {
- propertyValue = convert(field, (String) propertyValue);
+ Object usedValue = value;
+ if (value != null
+ && field.getType() != value.getClass()
+ && value.getClass() == String.class) {
+ usedValue = convert(field, (String) value);
}
boolean access = field.isAccessible();
field.setAccessible(true);
- field.set(instance, propertyValue);
+ field.set(instance, usedValue);
field.setAccessible(access);
} catch (IllegalArgumentException ex) { // should never happen
throw new ODataRuntimeException(ex);
[34/52] git commit: Added support for write relations
Posted by mi...@apache.org.
Added support for write relations
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/e39b0b95
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/e39b0b95
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/e39b0b95
Branch: refs/heads/master
Commit: e39b0b9586aa1c64034fc23d245bbce55d84a63b
Parents: 49786b4
Author: Michael Bolz <mi...@apache.org>
Authored: Tue Dec 3 05:28:05 2013 +0100
Committer: Michael Bolz <mi...@apache.org>
Committed: Tue Dec 3 08:14:21 2013 +0100
----------------------------------------------------------------------
.../annotation/data/AnnotationInMemoryDs.java | 85 +++++++++++++++++---
.../core/annotation/edm/AnnotationHelper.java | 31 ++++++-
.../data/AnnotationsInMemoryDsTest.java | 8 --
3 files changed, 101 insertions(+), 23 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/e39b0b95/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationInMemoryDs.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationInMemoryDs.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationInMemoryDs.java
index d7c7f59..938a0d2 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationInMemoryDs.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationInMemoryDs.java
@@ -33,6 +33,7 @@ import org.apache.olingo.odata2.api.exception.ODataApplicationException;
import org.apache.olingo.odata2.api.exception.ODataNotFoundException;
import org.apache.olingo.odata2.api.exception.ODataNotImplementedException;
import org.apache.olingo.odata2.core.annotation.edm.AnnotationHelper;
+import org.apache.olingo.odata2.core.annotation.edm.AnnotationHelper.AnnotatedNavInfo;
import org.apache.olingo.odata2.core.annotation.edm.ClassHelper;
import org.apache.olingo.odata2.core.exception.ODataRuntimeException;
@@ -111,7 +112,9 @@ public class AnnotationInMemoryDs implements ListsDataSource {
DataStore<?> sourceStore = dataStores.get(sourceEntitySet.getName());
DataStore<?> targetStore = dataStores.get(targetEntitySet.getName());
- Field sourceField = extractSourceField(sourceStore, targetStore);
+ AnnotatedNavInfo navInfo = ANNOTATION_HELPER.getCommonNavigationInfo(
+ sourceStore.getDataTypeClass(), targetStore.getDataTypeClass());
+ Field sourceField = navInfo.getFromField();
if (sourceField == null) {
throw new ODataRuntimeException("Missing source field for related data (sourceStore='" + sourceStore
+ "', targetStore='" + targetStore + "').");
@@ -131,8 +134,7 @@ public class AnnotationInMemoryDs implements ListsDataSource {
}
}
- EdmNavigationProperty navProperty = sourceField.getAnnotation(EdmNavigationProperty.class);
- if (navProperty.toMultiplicity() == EdmMultiplicity.MANY) {
+ if (navInfo.getToMultiplicity() == EdmMultiplicity.MANY) {
if (targetKeys.isEmpty()) {
return resultData;
} else {
@@ -223,10 +225,63 @@ public class AnnotationInMemoryDs implements ListsDataSource {
}
@Override
- public void writeRelation(EdmEntitySet sourceEntitySet, Object sourceData, EdmEntitySet targetEntitySet,
- Map<String, Object> targetKeys)
+ public void writeRelation(EdmEntitySet sourceEntitySet, Object sourceEntity, EdmEntitySet targetEntitySet,
+ Map<String, Object> targetEntityValues)
throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException {
- throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
+ // get common data
+ DataStore<Object> sourceStore = dataStores.get(sourceEntitySet.getName());
+ DataStore<Object> targetStore = dataStores.get(targetEntitySet.getName());
+
+ AnnotatedNavInfo commonNavInfo = ANNOTATION_HELPER.getCommonNavigationInfo(
+ sourceStore.getDataTypeClass(), targetStore.getDataTypeClass());
+
+ // get and validate source fields
+ Field sourceField = commonNavInfo.getFromField();
+ if (sourceField == null) {
+ throw new ODataRuntimeException("Missing source field for related data (sourceStore='" + sourceStore
+ + "', targetStore='" + targetStore + "').");
+ }
+
+ // get related target entity
+ Object targetEntity = targetStore.createInstance();
+ ANNOTATION_HELPER.setKeyFields(targetEntity, targetEntityValues);
+ targetEntity = targetStore.read(targetEntity);
+
+ // set at source
+ setValueAtNavigationField(sourceEntity, sourceField, targetEntity);
+ // set at target
+ Field targetField = commonNavInfo.getToField();
+ if(targetField != null) {
+ setValueAtNavigationField(targetEntity, targetField, sourceEntity);
+ }
+ }
+
+ /**
+ * Set (Multiplicity != *) or add (Multiplicity == *) <code>value</code> at <code>field</code>
+ * of <code>instance</code>.
+ *
+ * @param instance
+ * @param field
+ * @param value
+ * @throws EdmException
+ */
+ private void setValueAtNavigationField(Object instance, Field field, Object value)
+ throws EdmException {
+ Class<?> fieldTypeClass = field.getType();
+ if (Collection.class.isAssignableFrom(fieldTypeClass)) {
+ @SuppressWarnings("unchecked")
+ Collection<Object> collection = (Collection<Object>) ANNOTATION_HELPER.getValueForField(
+ instance, field.getName(), EdmNavigationProperty.class);
+ if(collection == null) {
+ collection = new ArrayList<Object>();
+ setValue(instance, field, collection);
+ }
+ collection.add(value);
+ } else if(fieldTypeClass.isArray()) {
+ throw new ODataRuntimeException("Write relations for internal used arrays is not supported.");
+ } else {
+ setValue(instance, field, value);
+ }
}
/**
@@ -264,10 +319,18 @@ public class AnnotationInMemoryDs implements ListsDataSource {
}
}
- private Field extractSourceField(DataStore<?> sourceStore, DataStore<?> targetStore) {
- Class<?> sourceDataTypeClass = sourceStore.getDataTypeClass();
- Class<?> targetDataTypeClass = targetStore.getDataTypeClass();
-
- return ANNOTATION_HELPER.getCommonNavigationInfo(sourceDataTypeClass, targetDataTypeClass).getFromField();
+ private void setValue(Object instance, Field field, Object value) {
+ try {
+ boolean access = field.isAccessible();
+ field.setAccessible(true);
+ field.set(instance, value);
+ field.setAccessible(access);
+ } catch (IllegalArgumentException e) {
+ throw new ODataRuntimeException("Error for setting value of field: '"
+ + field + "' at instance: '" + instance + "'.", e);
+ } catch (IllegalAccessException e) {
+ throw new ODataRuntimeException("Error for setting value of field: '"
+ + field + "' at instance: '" + instance + "'.", e);
+ }
}
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/e39b0b95/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java
index 462a0bc..08699fa 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java
@@ -275,12 +275,18 @@ public class AnnotationHelper {
return multiplicity;
}
+
+ /**
+ * Set key fields based on values in map.
+ * If an key field is not available or <code>NULL</code> in the map
+ * it will be not set as <code>NULL</code> at the instance object.
+ *
+ * @param instance
+ * @param keys
+ * @return
+ */
public <T> T setKeyFields(T instance, Map<String, Object> keys) {
List<Field> fields = getAnnotatedFields(instance, EdmKey.class);
- if (fields.size() != keys.size()) {
- throw new IllegalStateException("Wrong amount of key properties. Expected read keys = "
- + fields + " given key predicates = " + keys);
- }
for (Field field : fields) {
String propertyName = getPropertyName(field);
@@ -327,12 +333,17 @@ public class AnnotationHelper {
public EdmMultiplicity getToMultiplicity() {
return getMultiplicity(fromNavigation, fromField);
}
+
+ public boolean isBiDirectional() {
+ return toNavigation != null;
+ }
}
public AnnotatedNavInfo getCommonNavigationInfo(Class<?> sourceClass, Class<?> targetClass) {
List<Field> sourceFields = getAnnotatedFields(sourceClass, EdmNavigationProperty.class);
List<Field> targetFields = getAnnotatedFields(targetClass, EdmNavigationProperty.class);
+ // first try via association name to get full navigation information
for (Field sourceField : sourceFields) {
final EdmNavigationProperty sourceNav = sourceField.getAnnotation(EdmNavigationProperty.class);
final String sourceAssociation = extractRelationshipName(sourceNav, sourceField);
@@ -344,6 +355,18 @@ public class AnnotationHelper {
}
}
}
+
+ // if nothing was found assume none bi-directinal navigation
+ String targetEntityTypeName = extractEntityTypeName(targetClass);
+ for (Field sourceField : sourceFields) {
+ final EdmNavigationProperty sourceNav = sourceField.getAnnotation(EdmNavigationProperty.class);
+ final String navTargetEntityName = extractEntitTypeName(sourceNav, sourceField);
+
+ if (navTargetEntityName.equals(targetEntityTypeName)) {
+ return new AnnotatedNavInfo(sourceField, null, sourceNav, null);
+ }
+ }
+
return null;
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/e39b0b95/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/data/AnnotationsInMemoryDsTest.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/data/AnnotationsInMemoryDsTest.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/data/AnnotationsInMemoryDsTest.java
index 3063004..02881f0 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/data/AnnotationsInMemoryDsTest.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/data/AnnotationsInMemoryDsTest.java
@@ -39,20 +39,12 @@ public class AnnotationsInMemoryDsTest {
private final AnnotationInMemoryDs datasource;
private AnnotationEdmProvider edmProvider;
private static final String DEFAULT_CONTAINER = ModelSharedConstants.CONTAINER_1;
- private static final String DEFAULT_NAMESPACE = ModelSharedConstants.NAMESPACE_1;
public AnnotationsInMemoryDsTest() {
datasource = new AnnotationInMemoryDs(Building.class.getPackage().getName());
edmProvider = new AnnotationEdmProvider(Building.class.getPackage().getName());
}
- // @Test(expected = ODataApplicationException.class)
- // public void invalidEntity() throws Exception {
- // EdmEntitySet edmEntitySet = createMockedEdmEntitySet("Buildings");
- //
- // datasource.createData(edmEntitySet, this);
- // }
-
@Test
public void createSimpleEntity() throws Exception {
EdmEntitySet edmEntitySet = createMockedEdmEntitySet("Buildings");
[37/52] git commit: Removed dependcy from 'api-annotations' to 'api'
(missing parts)
Posted by mi...@apache.org.
Removed dependcy from 'api-annotations' to 'api' (missing parts)
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/e19384d6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/e19384d6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/e19384d6
Branch: refs/heads/master
Commit: e19384d6a760f3785e94ff4c73fde61b3f81bb70
Parents: 09344a5
Author: Michael Bolz <mi...@apache.org>
Authored: Wed Dec 4 06:19:17 2013 +0100
Committer: Michael Bolz <mi...@apache.org>
Committed: Wed Dec 4 06:19:17 2013 +0100
----------------------------------------------------------------------
.../core/annotation/edm/AnnotationHelper.java | 12 +++++++++++-
.../odata2/core/annotation/model/Building.java | 4 ++--
.../odata2/core/annotation/model/Manager.java | 4 ++--
.../odata2/core/annotation/model/Team.java | 4 ++--
.../odata2/ref/annotation/model/Building.java | 4 ++--
.../odata2/ref/annotation/model/Manager.java | 4 ++--
.../odata2/ref/annotation/model/Team.java | 4 ++--
odata2-lib/odata-annotation/pom.xml | 8 --------
.../edm/EdmFunctionImportParameter.java | 6 +++---
.../annotation/edm/EdmNavigationProperty.java | 20 +++++++++++++++++---
10 files changed, 43 insertions(+), 27 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/e19384d6/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java
index 94edb0a..d1dd7cc 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java
@@ -30,6 +30,7 @@ import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty.Multiplicity;
import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
import org.apache.olingo.odata2.api.edm.EdmLiteralKind;
import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
@@ -266,7 +267,7 @@ public class AnnotationHelper {
}
public EdmMultiplicity getMultiplicity(EdmNavigationProperty enp, Field field) {
- EdmMultiplicity multiplicity = enp.toMultiplicity();
+ EdmMultiplicity multiplicity = mapMultiplicity(enp.toMultiplicity());
final boolean isCollectionType = field.getType().isArray() || Collection.class.isAssignableFrom(field.getType());
if (multiplicity == EdmMultiplicity.ONE && isCollectionType) {
@@ -686,6 +687,15 @@ public class AnnotationHelper {
+ "' for mapping to EdmSimpleTypeKind.");
}
}
+
+ public EdmMultiplicity mapMultiplicity(Multiplicity multiplicity) {
+ switch (multiplicity) {
+ case ZERO_TO_ONE: return EdmMultiplicity.ZERO_TO_ONE;
+ case ONE: return EdmMultiplicity.ONE;
+ case MANY: return EdmMultiplicity.MANY;
+ default: throw new ODataRuntimeException("Unknown type '" + multiplicity + "' for mapping to EdmMultiplicity.");
+ }
+ }
/**
*
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/e19384d6/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Building.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Building.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Building.java
index bf43580..737b5e2 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Building.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Building.java
@@ -26,9 +26,9 @@ import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty.Multiplicity;
import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
import org.apache.olingo.odata2.api.annotation.edm.EdmType;
-import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
/**
*
@@ -44,7 +44,7 @@ public class Building {
@EdmProperty(name = "Image", type = EdmType.BINARY)
private byte[] image;
@EdmNavigationProperty(name = "nb_Rooms", toType = Room.class,
- association = "BuildingRooms", toMultiplicity = EdmMultiplicity.MANY)
+ association = "BuildingRooms", toMultiplicity = Multiplicity.MANY)
private List<Room> rooms = new ArrayList<Room>();
public Building() {}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/e19384d6/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Manager.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Manager.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Manager.java
index 7785d3c..e3edbd0 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Manager.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Manager.java
@@ -24,7 +24,7 @@ import java.util.List;
import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
-import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
+import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty.Multiplicity;
/**
*
@@ -34,7 +34,7 @@ import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
public class Manager extends Employee {
@EdmNavigationProperty(name = "nm_Employees", association = "ManagerEmployees",
- toMultiplicity = EdmMultiplicity.MANY)
+ toMultiplicity = Multiplicity.MANY)
private List<Employee> employees = new ArrayList<Employee>();
public Manager(final String id, final String name) {
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/e19384d6/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Team.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Team.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Team.java
index 23ad181..e9b296f 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Team.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Team.java
@@ -24,9 +24,9 @@ import java.util.List;
import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty.Multiplicity;
import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
import org.apache.olingo.odata2.api.annotation.edm.EdmType;
-import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
/**
*
@@ -36,7 +36,7 @@ import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
public class Team extends RefBase {
@EdmProperty(type = EdmType.BOOLEAN)
private Boolean isScrumTeam;
- @EdmNavigationProperty(name = "nt_Employees", association = "TeamEmployees", toMultiplicity = EdmMultiplicity.MANY)
+ @EdmNavigationProperty(name = "nt_Employees", association = "TeamEmployees", toMultiplicity = Multiplicity.MANY)
private List<Employee> employees = new ArrayList<Employee>();
public Team() {
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/e19384d6/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Building.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Building.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Building.java
index 503ccfd..668ac86 100644
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Building.java
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Building.java
@@ -26,9 +26,9 @@ import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty.Multiplicity;
import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
import org.apache.olingo.odata2.api.annotation.edm.EdmType;
-import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
/**
*
@@ -44,7 +44,7 @@ public class Building {
@EdmProperty(name = "Image", type = EdmType.BINARY)
private byte[] image;
@EdmNavigationProperty(name = "nb_Rooms", toType = Room.class,
- association = "BuildingRooms", toMultiplicity = EdmMultiplicity.MANY)
+ association = "BuildingRooms", toMultiplicity = Multiplicity.MANY)
private List<Room> rooms = new ArrayList<Room>();
public String getId() {
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/e19384d6/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Manager.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Manager.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Manager.java
index 93974ab..57e6d78 100644
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Manager.java
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Manager.java
@@ -24,7 +24,7 @@ import java.util.List;
import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
-import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
+import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty.Multiplicity;
/**
*
@@ -34,7 +34,7 @@ import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
public class Manager extends Employee {
@EdmNavigationProperty(name = "nm_Employees", association = "ManagerEmployees",
- toMultiplicity = EdmMultiplicity.MANY)
+ toMultiplicity = Multiplicity.MANY)
private List<Employee> employees = new ArrayList<Employee>();
public List<Employee> getEmployees() {
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/e19384d6/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Team.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Team.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Team.java
index 8320c54..50d2ad2 100644
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Team.java
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Team.java
@@ -24,9 +24,9 @@ import java.util.List;
import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty.Multiplicity;
import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
import org.apache.olingo.odata2.api.annotation.edm.EdmType;
-import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
/**
*
@@ -36,7 +36,7 @@ import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
public class Team extends RefBase {
@EdmProperty(type = EdmType.BOOLEAN)
private Boolean isScrumTeam;
- @EdmNavigationProperty(name = "nt_Employees", association = "TeamEmployees", toMultiplicity = EdmMultiplicity.MANY)
+ @EdmNavigationProperty(name = "nt_Employees", association = "TeamEmployees", toMultiplicity = Multiplicity.MANY)
private List<Employee> employees = new ArrayList<Employee>();
public Boolean isScrumTeam() {
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/e19384d6/odata2-lib/odata-annotation/pom.xml
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-annotation/pom.xml b/odata2-lib/odata-annotation/pom.xml
index 689e49e..c943ee1 100644
--- a/odata2-lib/odata-annotation/pom.xml
+++ b/odata2-lib/odata-annotation/pom.xml
@@ -23,12 +23,4 @@
<artifactId>olingo-odata2-api-annotation-incubating</artifactId>
<name>${project.artifactId}</name>
-
- <dependencies>
- <dependency>
- <groupId>org.apache.olingo</groupId>
- <artifactId>olingo-odata2-api-incubating</artifactId>
- <version>${project.version}</version>
- </dependency>
- </dependencies>
</project>
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/e19384d6/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmFunctionImportParameter.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmFunctionImportParameter.java b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmFunctionImportParameter.java
index dca3d44..3301166 100644
--- a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmFunctionImportParameter.java
+++ b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmFunctionImportParameter.java
@@ -24,9 +24,9 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
- * <p>Annotation for definition of an {@link EdmFunctionImportParameter} for an {@link EdmFunctionImport}
- * which contains the {@link EdmFunctionImportParameter} as a parameter.</p>
- * The EdmProperty annotation has to be used on a parameter within a {@link EdmFunctionImport} annotated method.
+ * <p>Annotation for definition of an EdmFunctionImportParameter for an EdmFunctionImport
+ * which contains the EdmFunctionImportParameter as a parameter.</p>
+ * The EdmProperty annotation has to be used on a parameter within a EdmFunctionImport annotated method.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.PARAMETER)
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/e19384d6/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmNavigationProperty.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmNavigationProperty.java b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmNavigationProperty.java
index c193e13..168784c 100644
--- a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmNavigationProperty.java
+++ b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmNavigationProperty.java
@@ -23,8 +23,6 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
-import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
-
/**
* <p>Annotation for definition of an EdmNavigationProperty for an EdmEntityType
* which contains the navigation property as a field.</p>
@@ -34,6 +32,22 @@ import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
@Target(ElementType.FIELD)
public @interface EdmNavigationProperty {
/**
+ * <p>EdmMultiplicity indicates the number of entity type instances
+ * an association end can relate to:
+ * <dl>
+ * <dt>0..1</dt><dd>one or none</dd>
+ * <dt> 1</dt><dd>exactly one</dd>
+ * <dt> *</dt><dd>many</dd>
+ * </dl>
+ * </p>
+ *
+ */
+ public enum Multiplicity {
+ ZERO_TO_ONE, ONE, MANY;
+ }
+
+
+ /**
* Define the name for the Navigation Property.
* If not set a default value has to be generated by the EDM provider.
*
@@ -72,5 +86,5 @@ public @interface EdmNavigationProperty {
*
* @return multiplicity to the target EdmEntity of the Navigation Property.
*/
- EdmMultiplicity toMultiplicity() default EdmMultiplicity.ONE;
+ Multiplicity toMultiplicity() default Multiplicity.ONE;
}
\ No newline at end of file
[25/52] git commit: Merged with current master
Posted by mi...@apache.org.
Merged with current master
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/83c25806
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/83c25806
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/83c25806
Branch: refs/heads/master
Commit: 83c2580617d7845864b97b460cda9425d5331679
Parents: b7e7ee0 3200dbb
Author: Michael Bolz <mi...@apache.org>
Authored: Fri Nov 15 14:06:43 2013 +0100
Committer: Michael Bolz <mi...@apache.org>
Committed: Fri Nov 15 14:06:43 2013 +0100
----------------------------------------------------------------------
.../odata2/api/edm/provider/AliasInfo.java | 61 ++++
.../odata2/api/edm/provider/EdmProvider.java | 11 +
.../odata2/core/ODataExceptionWrapper.java | 354 -------------------
.../olingo/odata2/core/ODataRequestHandler.java | 1 +
.../apache/olingo/odata2/core/edm/EdmImpl.java | 38 +-
.../odata2/core/edm/provider/EdmImplProv.java | 15 +
.../odata2/core/edm/provider/EdmxProvider.java | 16 +
.../core/ep/consumer/XmlMetadataConsumer.java | 2 +-
.../core/rest/ODataExceptionMapperImpl.java | 26 +-
.../odata2/core/rest/ODataExceptionWrapper.java | 328 +++++++++++++++++
.../odata2/core/rest/ODataRootLocator.java | 45 ++-
.../odata2/core/rest/ODataSubLocator.java | 1 -
.../core/rest/app/AbstractODataApplication.java | 27 ++
.../odata2/core/ODataExceptionWrapperTest.java | 1 +
.../olingo/odata2/core/edm/EdmImplTest.java | 7 +
.../core/edm/provider/EdmImplProvTest.java | 68 +++-
.../core/edm/provider/EdmxProviderTest.java | 40 ++-
.../core/rest/ODataExceptionMapperImplTest.java | 15 +-
.../core/rest/ODataServiceFactoryImpl.java | 14 -
.../ODataServiceFactoryWithCallbackImpl.java | 51 +++
.../olingo/odata2/fit/basic/ContextTest.java | 2 +-
.../fit/basic/issues/Service1Factory.java | 76 ----
.../fit/basic/issues/Service2Factory.java | 76 ----
.../basic/issues/TestCxfCacheUriInfoIssue.java | 118 -------
.../basic/issues/TestCxfCacheUriInfoIssue2.java | 75 ----
.../fit/misc/CxfCacheUriInfoIssue2Test.java | 80 +++++
.../CxfCacheUriInfoIssueService1Factory.java | 75 ++++
.../CxfCacheUriInfoIssueService2Factory.java | 75 ++++
.../fit/misc/CxfCacheUriInfoIssueTest.java | 118 +++++++
.../fit/misc/ODataApplicationFactory.java | 42 +++
.../odata2/fit/misc/ODataApplicationTest.java | 79 +++++
.../odata2/fit/misc/ODataApplication_.java | 31 ++
.../odata2/testutil/mock/EdmTestProvider.java | 10 +
.../core/jpa/ODataJPAResponseBuilder.java | 6 +-
34 files changed, 1206 insertions(+), 778 deletions(-)
----------------------------------------------------------------------
[05/52] git commit: Simplified annotations
Posted by mi...@apache.org.
Simplified annotations
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/648d0b40
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/648d0b40
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/648d0b40
Branch: refs/heads/master
Commit: 648d0b409fbe5380fdf46fe7980bd3cb6e55fd24
Parents: ae0d7d1
Author: Michael Bolz <mi...@sap.com>
Authored: Fri Oct 11 20:59:39 2013 +0200
Committer: Michael Bolz <mi...@sap.com>
Committed: Fri Oct 11 20:59:39 2013 +0200
----------------------------------------------------------------------
.../api/annotation/edm/EdmComplexProperty.java | 32 ---------------
.../odata2/api/annotation/edm/EdmEntitySet.java | 31 ---------------
.../api/annotation/edm/EdmEntityType.java | 3 ++
.../odata2/api/annotation/edm/EdmFacets.java | 33 +++++++++++++++
.../odata2/api/annotation/edm/EdmProperty.java | 5 ++-
.../odata2/api/annotation/edm/Facets.java | 36 -----------------
.../api/annotation/edm/ds/EntityDataSource.java | 1 -
.../annotation/edm/AnnotationEdmProvider.java | 42 ++++++++++++--------
.../odata2/core/annotation/edm/ClassHelper.java | 1 -
.../processor/AnnotationProcessor.java | 4 ++
.../processor/json/EdmAnnotationSerializer.java | 7 ++--
.../odata2/core/annotation/model/Building.java | 5 +--
.../odata2/core/annotation/model/Employee.java | 10 ++---
.../odata2/core/annotation/model/Location.java | 3 +-
.../odata2/core/annotation/model/Manager.java | 5 +--
.../odata2/core/annotation/model/Room.java | 5 +--
.../odata2/core/annotation/model/Team.java | 5 +--
.../odata2/ref/annotation/model/Building.java | 7 ++--
.../odata2/ref/annotation/model/Employee.java | 10 ++---
.../odata2/ref/annotation/model/Location.java | 3 +-
.../odata2/ref/annotation/model/Manager.java | 5 +--
.../odata2/ref/annotation/model/Photo.java | 6 +--
.../odata2/ref/annotation/model/Room.java | 6 +--
.../odata2/ref/annotation/model/Team.java | 5 +--
24 files changed, 102 insertions(+), 168 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/648d0b40/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmComplexProperty.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmComplexProperty.java b/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmComplexProperty.java
deleted file mode 100644
index 3af0227..0000000
--- a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmComplexProperty.java
+++ /dev/null
@@ -1,32 +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.api.annotation.edm;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-@Retention(RetentionPolicy.RUNTIME)
-@Target(ElementType.FIELD)
-public @interface EdmComplexProperty {
- String name() default "";
- String namespace() default "";
- String facet() default "";
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/648d0b40/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmEntitySet.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmEntitySet.java b/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmEntitySet.java
deleted file mode 100644
index b62d986..0000000
--- a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmEntitySet.java
+++ /dev/null
@@ -1,31 +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.api.annotation.edm;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-@Retention(RetentionPolicy.RUNTIME)
-@Target(ElementType.TYPE)
-public @interface EdmEntitySet {
- String name();
- String container();
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/648d0b40/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmEntityType.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmEntityType.java b/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmEntityType.java
index 67a363d..ed5d802 100644
--- a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmEntityType.java
+++ b/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmEntityType.java
@@ -28,4 +28,7 @@ import java.lang.annotation.Target;
public @interface EdmEntityType {
String name() default "";
String namespace();
+ /* If set this entity is exposed as entity set with given name. If not set theire will be no entity set generated. */
+ String entitySetName() default "";
+ String container() default "";
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/648d0b40/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmFacets.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmFacets.java b/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmFacets.java
new file mode 100644
index 0000000..4ea2bd5
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmFacets.java
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * 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.api.annotation.edm;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.ANNOTATION_TYPE)
+public @interface EdmFacets {
+ int maxLength() default 0;
+ int scale() default -1;
+ int precision() default 0;
+ boolean nullable() default false;
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/648d0b40/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmProperty.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmProperty.java b/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmProperty.java
index 68c411b..66c5282 100644
--- a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmProperty.java
+++ b/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmProperty.java
@@ -29,5 +29,8 @@ import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
public @interface EdmProperty {
EdmSimpleTypeKind type() default EdmSimpleTypeKind.Null;
String name() default "";
- String facet() default "";
+ /* only for complex property */
+ String namespace() default "";
+ EdmFacets facets() default @EdmFacets;
+
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/648d0b40/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/Facets.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/Facets.java b/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/Facets.java
deleted file mode 100644
index 24a3be6..0000000
--- a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/Facets.java
+++ /dev/null
@@ -1,36 +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.api.annotation.edm;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-@Retention(RetentionPolicy.RUNTIME)
-@Target(ElementType.ANNOTATION_TYPE)
-public @interface Facets {
- int maxLength() default 0;
-
- int scale() default -1;
-
- int precision() default 0;
-
- boolean nullable() default false;
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/648d0b40/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/ds/EntityDataSource.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/ds/EntityDataSource.java b/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/ds/EntityDataSource.java
index aa2aff6..e21c81f 100644
--- a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/ds/EntityDataSource.java
+++ b/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/ds/EntityDataSource.java
@@ -27,6 +27,5 @@ import java.lang.annotation.Target;
@Target(ElementType.TYPE)
public @interface EntityDataSource {
String name() default "";
- Class<?> entityClass() default Object.class;
Class<?> entityType();
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/648d0b40/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java
index 419eedd..8bd80ad 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java
@@ -27,13 +27,12 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.olingo.odata2.api.annotation.edm.EdmComplexEntity;
-import org.apache.olingo.odata2.api.annotation.edm.EdmComplexProperty;
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
import org.apache.olingo.odata2.api.annotation.edm.NavigationEnd;
+import org.apache.olingo.odata2.api.edm.EdmEntitySet;
import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
import org.apache.olingo.odata2.api.edm.FullQualifiedName;
@@ -270,24 +269,22 @@ public class AnnotationEdmProvider extends EdmProvider {
}
private void handleEntityContainer(Class<?> aClass) {
- EdmEntitySet entitySet = aClass.getAnnotation(EdmEntitySet.class);
- if (entitySet != null) {
- EdmEntityType entity = aClass.getAnnotation(EdmEntityType.class);
- String containerName = entitySet.container();
+ EdmEntityType entity = aClass.getAnnotation(EdmEntityType.class);
+ if (entity != null && !entity.entitySetName().isEmpty()) {
+ String containerName = entity.container();
ContainerBuilder builder = containerName2ContainerBuilder.get(containerName);
if (builder == null) {
builder = ContainerBuilder.init(entity.namespace(), containerName);
containerName2ContainerBuilder.put(containerName, builder);
}
- builder.addEntitySet(createEntitySet(entitySet, entity));
+ builder.addEntitySet(createEntitySet(entity));
}
}
- private EntitySet createEntitySet(EdmEntitySet et, EdmEntityType entity) {
- String name = et.name();
+ private EntitySet createEntitySet(EdmEntityType entity) {
FullQualifiedName typeName = new FullQualifiedName(entity.namespace(), entity.name());
- return new EntitySet().setName(name).setEntityType(typeName);
+ return new EntitySet().setName(entity.entitySetName()).setEntityType(typeName);
}
private void finish() {
@@ -349,16 +346,12 @@ public class AnnotationEdmProvider extends EdmProvider {
for (Field field : fields) {
EdmProperty ep = field.getAnnotation(EdmProperty.class);
if (ep != null) {
- properties.add(createProperty(ep, field));
+ properties.add(createProperty(ep, field, namespace));
EdmKey eti = field.getAnnotation(EdmKey.class);
if (eti != null) {
keyProperties.add(createKeyProperty(ep, field));
}
}
- EdmComplexProperty ecp = field.getAnnotation(EdmComplexProperty.class);
- if (ecp != null) {
- properties.add(createComplexProperty(ecp, field, namespace));
- }
EdmNavigationProperty enp = field.getAnnotation(EdmNavigationProperty.class);
if (enp != null) {
final NavigationProperty navProperty = createNavigationProperty(namespace, enp, field);
@@ -429,7 +422,16 @@ public class AnnotationEdmProvider extends EdmProvider {
return keyProperty.setName(entityName);
}
- private Property createProperty(EdmProperty ep, Field field) {
+ private Property createProperty(EdmProperty ep, Field field, String defaultNamespace) {
+ if(isAnnotatedEntity(field.getType())) {
+ return createComplexProperty(ep, field, defaultNamespace);
+ } else {
+ return createSimpleProperty(ep, field);
+ }
+ }
+
+
+ private Property createSimpleProperty(EdmProperty ep, Field field) {
SimpleProperty sp = new SimpleProperty();
String entityName = ep.name();
if (entityName.isEmpty()) {
@@ -446,7 +448,7 @@ public class AnnotationEdmProvider extends EdmProvider {
return sp;
}
- private Property createComplexProperty(EdmComplexProperty ep, Field field, String defaultNamespace) {
+ private Property createComplexProperty(EdmProperty ep, Field field, String defaultNamespace) {
ComplexProperty cp = new ComplexProperty();
String entityName = ep.name();
if (entityName.isEmpty()) {
@@ -578,6 +580,12 @@ public class AnnotationEdmProvider extends EdmProvider {
private String getCanonicalName(Field field) {
return ANNOTATION_HELPER.getCanonicalName(field);
}
+
+ private boolean isAnnotatedEntity(Class<?> clazz) {
+ boolean isComplexEntity = clazz.getAnnotation(EdmComplexEntity.class) != null;
+ boolean isEntity = clazz.getAnnotation(EdmEntityType.class) != null;
+ return isComplexEntity || isEntity;
+ }
}
static class SchemaBuilder {
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/648d0b40/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/ClassHelper.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/ClassHelper.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/ClassHelper.java
index baf4626..2094591 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/ClassHelper.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/ClassHelper.java
@@ -23,7 +23,6 @@ import java.io.FileFilter;
import java.io.FilenameFilter;
import java.net.URL;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.List;
/**
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/648d0b40/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/AnnotationProcessor.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/AnnotationProcessor.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/AnnotationProcessor.java
index b97d897..faf129c 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/AnnotationProcessor.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/AnnotationProcessor.java
@@ -58,6 +58,7 @@ import org.apache.olingo.odata2.core.annotation.processor.json.JsonConsumer;
*/
public class AnnotationProcessor extends ODataSingleProcessor {
+ private static final Object[] EMPTY_ARRAY = new Object[0];
private static final AnnotationHelper ANNOTATION_HELPER = new AnnotationHelper();
private final List<Class<?>> foundClasses;
@@ -368,6 +369,9 @@ public class AnnotationProcessor extends ODataSingleProcessor {
}
private Object[] mapParameterKeys(Method method, List<KeyPredicate> keys) throws IllegalStateException {
+ if(method == null) {
+ return EMPTY_ARRAY;
+ }
Class<?>[] pTypes = method.getParameterTypes();
if (pTypes.length != keys.size()) {
throw new IllegalStateException("Wrong amount of key properties. Expected read keys = "
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/648d0b40/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/json/EdmAnnotationSerializer.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/json/EdmAnnotationSerializer.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/json/EdmAnnotationSerializer.java
index 310e197..01ccf2c 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/json/EdmAnnotationSerializer.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/json/EdmAnnotationSerializer.java
@@ -29,13 +29,12 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
import org.apache.olingo.odata2.core.annotation.edm.AnnotationHelper;
-import org.apache.olingo.odata2.core.annotation.edm.ClassHelper;
import org.apache.olingo.odata2.core.exception.ODataRuntimeException;
public class EdmAnnotationSerializer {
@@ -124,11 +123,11 @@ public class EdmAnnotationSerializer {
private boolean writeEdmNavigationProperty(Object entity, JsonWriter json, Field field)
throws IllegalArgumentException, IllegalAccessException {
EdmNavigationProperty navProperty = field.getAnnotation(EdmNavigationProperty.class);
- EdmEntitySet property = entity.getClass().getAnnotation(EdmEntitySet.class);
+ EdmEntityType entityType = entity.getClass().getAnnotation(EdmEntityType.class);
if (navProperty != null) {
field.setAccessible(true);
Object keyValue = extractEdmKey(entity);
- json.writeProperty("uri", baseUri + property.name() + "('" + keyValue.toString() + "')"
+ json.writeProperty("uri", baseUri + entityType.entitySetName() + "('" + keyValue.toString() + "')"
+ "/" + navProperty.relationship());
return true;
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/648d0b40/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Building.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Building.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Building.java
index 1da4bdb..9889c2e 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Building.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Building.java
@@ -24,7 +24,6 @@ import java.util.List;
import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
import org.apache.olingo.odata2.api.annotation.edm.NavigationEnd;
import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
@@ -33,8 +32,8 @@ import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
/**
*
*/
-@EdmEntityType(name="Building", namespace=ModelSharedConstants.NAMESPACE_1)
-@EdmEntitySet(name="Buildings", container="Container1")
+@EdmEntityType(name="Building", namespace=ModelSharedConstants.NAMESPACE_1,
+ entitySetName = "Buildings", container="Container1")
public class Building {
@EdmKey
@EdmProperty(type = EdmSimpleTypeKind.String)
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/648d0b40/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Employee.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Employee.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Employee.java
index 0323ecc..5247448 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Employee.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Employee.java
@@ -20,9 +20,7 @@ package org.apache.olingo.odata2.core.annotation.model;
import java.text.DateFormat;
import java.util.Calendar;
-import org.apache.olingo.odata2.api.annotation.edm.EdmComplexProperty;
import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
@@ -33,12 +31,12 @@ import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
/**
*
*/
-@EdmEntityType(name="Employee", namespace=ModelSharedConstants.NAMESPACE_1)
-@EdmEntitySet(name="Employees", container=ModelSharedConstants.CONTAINER_1)
+@EdmEntityType(name="Employee", namespace=ModelSharedConstants.NAMESPACE_1,
+ entitySetName = "Employees", container=ModelSharedConstants.CONTAINER_1)
public class Employee {
private static int counter = 1;
- @EdmProperty(name="EmployeeId", type = EdmSimpleTypeKind.Int32)
@EdmKey
+ @EdmProperty(name="EmployeeId", type = EdmSimpleTypeKind.Int32)
private int employeeId;
@EdmProperty(name="EmployeeName")
private String employeeName;
@@ -54,7 +52,7 @@ public class Employee {
private byte[] image;
private String imageUrl;
private Calendar entryDate;
- @EdmComplexProperty(name="Location")
+ @EdmProperty(name="Location")
private Location location;
public Employee(final int employeeId, final String name) {
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/648d0b40/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Location.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Location.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Location.java
index 3b74c30..b8b9725 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Location.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Location.java
@@ -19,7 +19,6 @@
package org.apache.olingo.odata2.core.annotation.model;
import org.apache.olingo.odata2.api.annotation.edm.EdmComplexEntity;
-import org.apache.olingo.odata2.api.annotation.edm.EdmComplexProperty;
import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
/**
@@ -29,7 +28,7 @@ import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
public class Location {
@EdmProperty
private String country;
- @EdmComplexProperty
+ @EdmProperty
private City city;
public Location(final String country, final String postalCode, final String cityName) {
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/648d0b40/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Manager.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Manager.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Manager.java
index 1408c9c..1000822 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Manager.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Manager.java
@@ -21,15 +21,14 @@ package org.apache.olingo.odata2.core.annotation.model;
import java.util.ArrayList;
import java.util.List;
import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
import org.apache.olingo.odata2.api.annotation.edm.NavigationEnd;
/**
*
*/
-@EdmEntityType(name = "Manager", namespace = ModelSharedConstants.NAMESPACE_1)
-@EdmEntitySet(name = "Managers", container = ModelSharedConstants.CONTAINER_1)
+@EdmEntityType(name = "Manager", namespace = ModelSharedConstants.NAMESPACE_1,
+ entitySetName = "Managers", container = ModelSharedConstants.CONTAINER_1)
public class Manager extends Employee {
@EdmNavigationProperty(name = "nm_Employees", relationship = "ManagerEmployees",
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/648d0b40/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Room.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Room.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Room.java
index 8c8a62d..e1c55ed 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Room.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Room.java
@@ -17,7 +17,6 @@ package org.apache.olingo.odata2.core.annotation.model;
import java.util.ArrayList;
import java.util.List;
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
@@ -27,8 +26,8 @@ import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
/**
*
*/
-@EdmEntityType(name = "Room", namespace = ModelSharedConstants.NAMESPACE_1)
-@EdmEntitySet(name = "Rooms", container = ModelSharedConstants.CONTAINER_1)
+@EdmEntityType(name = "Room", namespace = ModelSharedConstants.NAMESPACE_1,
+ entitySetName = "Rooms", container = ModelSharedConstants.CONTAINER_1)
public class Room extends RefBase {
@EdmProperty
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/648d0b40/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Team.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Team.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Team.java
index 363ad7a..529ed5a 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Team.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Team.java
@@ -21,7 +21,6 @@ package org.apache.olingo.odata2.core.annotation.model;
import java.util.ArrayList;
import java.util.List;
import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
import org.apache.olingo.odata2.api.annotation.edm.NavigationEnd;
@@ -31,8 +30,8 @@ import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
/**
*
*/
-@EdmEntityType(name="Team", namespace = ModelSharedConstants.NAMESPACE_1)
-@EdmEntitySet(name="Teams", container = ModelSharedConstants.CONTAINER_1)
+@EdmEntityType(name="Team", namespace = ModelSharedConstants.NAMESPACE_1,
+ entitySetName = "Teams", container = ModelSharedConstants.CONTAINER_1)
public class Team extends RefBase {
@EdmProperty(type = EdmSimpleTypeKind.Boolean)
private Boolean isScrumTeam;
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/648d0b40/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Building.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Building.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Building.java
index 4035b24..5dca34d 100644
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Building.java
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Building.java
@@ -24,7 +24,6 @@ import java.util.List;
import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
import org.apache.olingo.odata2.api.annotation.edm.NavigationEnd;
import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
@@ -33,11 +32,11 @@ import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
/**
*
*/
-@EdmEntityType(name="Building", namespace=ModelSharedConstants.NAMESPACE_1)
-@EdmEntitySet(name="Buildings", container="Container1")
+@EdmEntityType(name="Building", namespace=ModelSharedConstants.NAMESPACE_1,
+ entitySetName = "Buildings", container="Container1")
public class Building {
@EdmKey
- @EdmProperty(type = EdmSimpleTypeKind.String)
+ @EdmProperty(type = EdmSimpleTypeKind.Int32)
private int id;
@EdmProperty
private String name;
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/648d0b40/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Employee.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Employee.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Employee.java
index 0ef9e3b..02a1530 100644
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Employee.java
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Employee.java
@@ -20,9 +20,7 @@ package org.apache.olingo.odata2.ref.annotation.model;
import java.text.DateFormat;
import java.util.Calendar;
-import org.apache.olingo.odata2.api.annotation.edm.EdmComplexProperty;
import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
@@ -33,12 +31,12 @@ import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
/**
*
*/
-@EdmEntityType(name="Employee", namespace=ModelSharedConstants.NAMESPACE_1)
-@EdmEntitySet(name="Employees", container=ModelSharedConstants.CONTAINER_1)
+@EdmEntityType(name="Employee", namespace=ModelSharedConstants.NAMESPACE_1,
+ entitySetName = "Employees", container=ModelSharedConstants.CONTAINER_1)
public class Employee {
private static int counter = 1;
- @EdmProperty(name="EmployeeId", type = EdmSimpleTypeKind.Int32)
@EdmKey
+ @EdmProperty(name="EmployeeId", type = EdmSimpleTypeKind.Int32)
private int employeeId;
@EdmProperty(name="EmployeeName")
private String employeeName;
@@ -54,7 +52,7 @@ public class Employee {
private byte[] image;
private String imageUrl;
private Calendar entryDate;
- @EdmComplexProperty(name="Location")
+ @EdmProperty(name="Location")
private Location location;
public Employee(final int employeeId, final String name) {
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/648d0b40/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Location.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Location.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Location.java
index f63e8a4..809accf 100644
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Location.java
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Location.java
@@ -19,7 +19,6 @@
package org.apache.olingo.odata2.ref.annotation.model;
import org.apache.olingo.odata2.api.annotation.edm.EdmComplexEntity;
-import org.apache.olingo.odata2.api.annotation.edm.EdmComplexProperty;
import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
/**
@@ -29,7 +28,7 @@ import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
public class Location {
@EdmProperty
private String country;
- @EdmComplexProperty
+ @EdmProperty
private City city;
public Location(final String country, final String postalCode, final String cityName) {
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/648d0b40/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Manager.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Manager.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Manager.java
index 521c43d..e3b2631 100644
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Manager.java
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Manager.java
@@ -21,15 +21,14 @@ package org.apache.olingo.odata2.ref.annotation.model;
import java.util.ArrayList;
import java.util.List;
import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
import org.apache.olingo.odata2.api.annotation.edm.NavigationEnd;
/**
*
*/
-@EdmEntityType(name = "Manager", namespace = ModelSharedConstants.NAMESPACE_1)
-@EdmEntitySet(name = "Managers", container = ModelSharedConstants.CONTAINER_1)
+@EdmEntityType(name = "Manager", namespace = ModelSharedConstants.NAMESPACE_1,
+ entitySetName = "Managers", container = ModelSharedConstants.CONTAINER_1)
public class Manager extends Employee {
@EdmNavigationProperty(name = "nm_Employees", relationship = "ManagerEmployees",
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/648d0b40/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Photo.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Photo.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Photo.java
index 92d1ac6..fd74c30 100644
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Photo.java
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Photo.java
@@ -27,7 +27,7 @@ public class Photo {
private static final String RESOURCE = "/male_1_WinterW.jpg";
private static byte[] defaultImage = ResourceHelper.loadAsByte(RESOURCE);
- private final int id;
+ private int id;
private String name;
private String type = "image/jpeg";
private String imageUrl = "http://localhost" + RESOURCE;
@@ -38,8 +38,8 @@ public class Photo {
public Photo(final int id, final String name, final String type) {
this.id = id;
- setName(name);
- setType(type);
+ this.name = name;
+ this.type = type;
}
public int getId() {
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/648d0b40/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Room.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Room.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Room.java
index 2feb5cd..28373b9 100644
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Room.java
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Room.java
@@ -21,18 +21,16 @@ package org.apache.olingo.odata2.ref.annotation.model;
import java.util.ArrayList;
import java.util.List;
import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
-import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
import org.apache.olingo.odata2.api.annotation.edm.NavigationEnd;
import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
/**
*
*/
-@EdmEntityType(name = "Room", namespace = ModelSharedConstants.NAMESPACE_1)
-@EdmEntitySet(name = "Rooms", container = ModelSharedConstants.CONTAINER_1)
+@EdmEntityType(name = "Room", namespace = ModelSharedConstants.NAMESPACE_1,
+ entitySetName = "Rooms", container = ModelSharedConstants.CONTAINER_1)
public class Room extends RefBase {
@EdmProperty
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/648d0b40/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Team.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Team.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Team.java
index b805b77..2bf6701 100644
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Team.java
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Team.java
@@ -21,7 +21,6 @@ package org.apache.olingo.odata2.ref.annotation.model;
import java.util.ArrayList;
import java.util.List;
import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
import org.apache.olingo.odata2.api.annotation.edm.NavigationEnd;
@@ -31,8 +30,8 @@ import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
/**
*
*/
-@EdmEntityType(name="Team", namespace = ModelSharedConstants.NAMESPACE_1)
-@EdmEntitySet(name="Teams", container = ModelSharedConstants.CONTAINER_1)
+@EdmEntityType(name="Team", namespace = ModelSharedConstants.NAMESPACE_1,
+ entitySetName = "Teams", container = ModelSharedConstants.CONTAINER_1)
public class Team extends RefBase {
@EdmProperty(type = EdmSimpleTypeKind.Boolean)
private Boolean isScrumTeam;
[02/52] Initial EdmAnnotation contribution
Posted by mi...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ae7c1f52/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/AnnotationProcessor.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/AnnotationProcessor.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/AnnotationProcessor.java
new file mode 100644
index 0000000..b97d897
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/AnnotationProcessor.java
@@ -0,0 +1,439 @@
+/*******************************************************************************
+ * 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.core.annotation.processor;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
+import org.apache.olingo.odata2.api.commons.HttpStatusCodes;
+import org.apache.olingo.odata2.api.exception.ODataException;
+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.DeleteUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetEntitySetUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetEntityUriInfo;
+import org.apache.olingo.odata2.api.uri.info.PostUriInfo;
+import org.apache.olingo.odata2.api.uri.info.PutMergePatchUriInfo;
+import org.apache.olingo.odata2.api.annotation.edm.ds.EntityCreate;
+import org.apache.olingo.odata2.api.annotation.edm.ds.EntityDataSource;
+import org.apache.olingo.odata2.api.annotation.edm.ds.EntityDelete;
+import org.apache.olingo.odata2.api.annotation.edm.ds.EntityRead;
+import org.apache.olingo.odata2.api.annotation.edm.ds.EntitySetRead;
+import org.apache.olingo.odata2.api.annotation.edm.ds.EntityUpdate;
+import org.apache.olingo.odata2.api.processor.ODataContext;
+import org.apache.olingo.odata2.core.exception.ODataRuntimeException;
+import org.apache.olingo.odata2.core.annotation.edm.AnnotationHelper;
+import org.apache.olingo.odata2.core.annotation.edm.ClassHelper;
+import org.apache.olingo.odata2.core.annotation.processor.json.EdmAnnotationSerializer;
+import org.apache.olingo.odata2.core.annotation.processor.json.JsonConsumer;
+
+/**
+ *
+ */
+public class AnnotationProcessor extends ODataSingleProcessor {
+
+ private static final AnnotationHelper ANNOTATION_HELPER = new AnnotationHelper();
+
+ private final List<Class<?>> foundClasses;
+
+ private final Map<String, DataSourceHolder> dataSources = new HashMap<String, DataSourceHolder>();
+ private ODataContext odataContext;
+
+ public AnnotationProcessor(ODataContext context, String packageToScan) {
+ odataContext = context;
+
+ foundClasses = ClassHelper.loadClasses(packageToScan, new ClassHelper.ClassValidator() {
+ @Override
+ public boolean isClassValid(Class<?> c) {
+ return null != c.getAnnotation(EntityDataSource.class);
+ }
+ });
+
+ init();
+ }
+
+ private void init() {
+ for (Class<?> clz : foundClasses) {
+ DataSourceHolder dhs = new DataSourceHolder(clz);
+ dataSources.put(dhs.getEntityName(), dhs);
+ }
+ }
+
+ @Override
+ public ODataResponse readEntity(GetEntityUriInfo uriInfo, String contentType) throws ODataException {
+ final String name = uriInfo.getTargetType().getName();
+
+ List<KeyPredicate> keys = uriInfo.getKeyPredicates();
+ DataSourceHolder holder = dataSources.get(name);
+ if (holder != null) {
+ Object result = holder.readEntity(keys);
+ if (result != null) {
+ return createODataResponse(result, HttpStatusCodes.OK);
+ }
+ }
+
+ return ODataResponse.status(HttpStatusCodes.NOT_FOUND).build();
+ }
+
+ @Override
+ public ODataResponse readEntitySet(GetEntitySetUriInfo uriInfo, String contentType) throws ODataException {
+ final String name = uriInfo.getTargetType().getName();
+
+ DataSourceHolder holder = dataSources.get(name);
+ if (holder != null) {
+ Object result = holder.readEntitySet();
+ if (result != null) {
+ return createODataResponse(result, HttpStatusCodes.OK);
+ }
+ }
+
+ return ODataResponse.status(HttpStatusCodes.NOT_FOUND).build();
+ }
+
+ @Override
+ public ODataResponse createEntity(PostUriInfo uriInfo, InputStream content,
+ String requestContentType, String contentType) throws ODataException {
+ final String name = uriInfo.getTargetType().getName();
+
+ DataSourceHolder dataSource = dataSources.get(name);
+ if (dataSource != null) {
+ Object instance = createInstanceFromContent(dataSource, content);
+
+ Object result = dataSource.createEntity(instance);
+ return createODataResponse(result, HttpStatusCodes.CREATED);
+ }
+
+ return ODataResponse.status(HttpStatusCodes.BAD_REQUEST).build();
+ }
+
+ @Override
+ public ODataResponse deleteEntity(DeleteUriInfo uriInfo, String contentType) throws ODataException {
+ final String name = uriInfo.getTargetType().getName();
+
+ DataSourceHolder holder = dataSources.get(name);
+ if (holder != null) {
+ List<KeyPredicate> keys = uriInfo.getKeyPredicates();
+ Object result = holder.deleteEntity(keys);
+ if (result != null) {
+ return ODataResponse.status(HttpStatusCodes.NO_CONTENT).build();
+ }
+ }
+
+ return ODataResponse.status(HttpStatusCodes.NOT_FOUND).build();
+ }
+
+ private ODataResponse createODataResponse(Object result, HttpStatusCodes statusCode) throws ODataException {
+// StringBuilder resultAsString = new StringBuilder("{\"d\":");
+// if (result != null) {
+// resultAsString.append(result.toString());
+// } else {
+// resultAsString.append("NULL");
+// }
+// resultAsString.append("}");
+ EdmAnnotationSerializer jsonSerializer =
+ new EdmAnnotationSerializer(odataContext.getPathInfo().getServiceRoot().toASCIIString());
+ InputStream resultAsString = jsonSerializer.serialize(result);
+ return ODataResponse.status(statusCode)
+ .contentHeader("application/json")
+ .entity(resultAsString).build();
+ }
+
+ private Object createInstanceFromContent(DataSourceHolder dataSource, InputStream content)
+ throws ODataException {
+ try {
+ Object instance = dataSource.createEntityInstance();
+ Map<String, FieldHolder> propName2Field = extractPropertyFields(dataSource.entityTypeClass);
+ Map<String, String> contentAsMap = JsonConsumer.readContent(content);
+ Set<Map.Entry<String, String>> contentEntries = contentAsMap.entrySet();
+ for (Map.Entry<String, String> entry : contentEntries) {
+ FieldHolder fh = propName2Field.get(entry.getKey());
+ if (fh != null) {
+ fh.set(instance, entry.getValue());
+ }
+ }
+ return instance;
+ } catch (IOException e) {
+ throw new ODataRuntimeException("Unexpected IOException with message: " + e.getMessage());
+ }
+ }
+
+ @Override
+ public ODataResponse updateEntity(PutMergePatchUriInfo uriInfo, InputStream content,
+ String requestContentType, boolean merge, String contentType) throws ODataException {
+ final String name = uriInfo.getTargetType().getName();
+
+ DataSourceHolder dataSource = dataSources.get(name);
+ if (dataSource != null) {
+ Object instance = createInstanceFromContent(dataSource, content);
+
+ Object result = dataSource.updateEntity(instance);
+ return createODataResponse(result, HttpStatusCodes.OK);
+ }
+
+ return ODataResponse.status(HttpStatusCodes.BAD_REQUEST).build();
+ }
+
+ private Map<String, FieldHolder> extractPropertyFields(Class<?> typeClass) {
+ if (typeClass == null) {
+ return Collections.emptyMap();
+ }
+ EdmEntityType type = typeClass.getAnnotation(EdmEntityType.class);
+ if (type == null) {
+ return Collections.emptyMap();
+ }
+
+ //
+ Map<String, FieldHolder> name2Fields = new HashMap<String, FieldHolder>();
+ Field[] fields = typeClass.getDeclaredFields();
+ for (Field field : fields) {
+ FieldHolder fh = FieldHolder.create(field);
+ name2Fields.put(fh.propertyName, fh);
+ }
+
+ //
+ Class<?> superClass = typeClass.getSuperclass();
+ if (superClass != null && superClass.getAnnotation(EdmEntityType.class) != null) {
+ name2Fields.putAll(extractPropertyFields(superClass));
+ }
+ //
+
+ return name2Fields;
+ }
+
+ /**
+ *
+ */
+ static final class FieldHolder {
+
+ final String propertyName;
+ final Field propertyField;
+
+ public FieldHolder(String propertyName, Field propertyField) {
+ this.propertyName = propertyName;
+ this.propertyField = propertyField;
+ }
+
+ public static FieldHolder create(Field field) {
+ EdmProperty ep = field.getAnnotation(EdmProperty.class);
+ String name;
+ if (ep != null && !ep.name().isEmpty()) {
+ name = ep.name();
+ } else {
+ name = ANNOTATION_HELPER.getCanonicalName(field);
+ }
+ return new FieldHolder(name, field);
+ }
+
+ public void set(Object instance, Object value) {
+ set(instance, String.valueOf(value));
+ }
+
+ public void set(Object instance, String value) {
+ try {
+ boolean accessible = propertyField.isAccessible();
+ if (!accessible) {
+ propertyField.setAccessible(true);
+ }
+
+ //
+ Class<?> type = propertyField.getType();
+ if (type == Boolean.class || type == boolean.class) {
+ propertyField.set(instance, Boolean.valueOf(value));
+ } else if (type == Integer.class || type == int.class) {
+ propertyField.set(instance, Integer.valueOf(value));
+ } else if (type == Long.class || type == long.class) {
+ propertyField.set(instance, Integer.valueOf(value));
+ } else {
+ propertyField.set(instance, value);
+ }
+ //
+
+ if (!accessible) {
+ propertyField.setAccessible(false);
+ }
+ } catch (Exception ex) {
+ }
+ }
+
+ @Override
+ public String toString() {
+ return "FieldHolder{" + "propertyName=" + propertyName + ", propertyField=" + propertyField + '}';
+ }
+ }
+
+ /**
+ *
+ */
+ static final class DataSourceHolder {
+
+ private final String name;
+ private final Object dataSourceInstance;
+ private final Class<?> entityTypeClass;
+ private Method readMethod;
+ private Method createMethod;
+ private Method updateMethod;
+ private Method deleteMethod;
+ private Method setReadMethod;
+
+ public DataSourceHolder(Class<?> clz) {
+ EntityDataSource eds = clz.getAnnotation(EntityDataSource.class);
+ entityTypeClass = eds.entityType();
+ EdmEntityType entityType = entityTypeClass.getAnnotation(EdmEntityType.class);
+ if (entityType == null) {
+ throw new IllegalArgumentException("Missing EdmEntityType Annotation at class " + clz);
+ }
+
+ if (entityType.name().isEmpty()) {
+ name = ANNOTATION_HELPER.getCanonicalName(entityTypeClass);
+ } else {
+ name = entityType.name();
+ }
+ dataSourceInstance = createInstance(clz);
+ initMethods(clz);
+ }
+
+ private void initMethods(Class<?> clz) throws IllegalArgumentException, SecurityException {
+ Method[] methods = clz.getDeclaredMethods();
+ for (Method method : methods) {
+ EntityRead ec = method.getAnnotation(EntityRead.class);
+ if (ec != null) {
+ readMethod = method;
+ }
+ EntityCreate ep = method.getAnnotation(EntityCreate.class);
+ if (ep != null) {
+ createMethod = method;
+ }
+ EntityUpdate update = method.getAnnotation(EntityUpdate.class);
+ if (update != null) {
+ updateMethod = method;
+ }
+ EntityDelete delete = method.getAnnotation(EntityDelete.class);
+ if (delete != null) {
+ deleteMethod = method;
+ }
+ EntitySetRead readSet = method.getAnnotation(EntitySetRead.class);
+ if (readSet != null) {
+ setReadMethod = method;
+ }
+ }
+
+ validateMethods(clz);
+ }
+
+ private void validateMethods(Class<?> clz) throws IllegalArgumentException {
+ //
+ if (readMethod == null) {
+ throw new IllegalArgumentException("Missing " + EntityRead.class
+ + " annotation at " + EntityDataSource.class + " annotated class " + clz);
+ }
+ if (updateMethod == null) {
+ throw new IllegalArgumentException("Missing " + EntityUpdate.class
+ + " annotation at " + EntityDataSource.class + " annotated class " + clz);
+ }
+ if (createMethod == null) {
+ throw new IllegalArgumentException("Missing " + EntityCreate.class
+ + " annotation at " + EntityDataSource.class + " annotated class " + clz);
+ }
+ }
+
+ public Object readEntity(List<KeyPredicate> keys) {
+ Object[] parameterKeys = mapParameterKeys(readMethod, keys);
+ return invoke(readMethod, parameterKeys);
+ }
+
+ private Object[] mapParameterKeys(Method method, List<KeyPredicate> keys) throws IllegalStateException {
+ Class<?>[] pTypes = method.getParameterTypes();
+ if (pTypes.length != keys.size()) {
+ throw new IllegalStateException("Wrong amount of key properties. Expected read keys = "
+ + Arrays.toString(pTypes) + " given key predicates = " + keys);
+ }
+ Object[] parameterKeys = new Object[pTypes.length];
+ int i = 0;
+ for (KeyPredicate keyPredicate : keys) {
+ if (matches(pTypes[i], keyPredicate)) {
+ parameterKeys[i] = keyPredicate.getLiteral();
+ }
+ i++;
+ }
+ return parameterKeys;
+ }
+
+ public Object createEntity(Object key) {
+ return invoke(createMethod, new Object[]{key});
+ }
+
+ public Object updateEntity(Object key) {
+ return invoke(updateMethod, new Object[]{key});
+ }
+
+ public Object deleteEntity(List<KeyPredicate> keys) {
+ Object[] parameterKeys = mapParameterKeys(deleteMethod, keys);
+ return invoke(deleteMethod, parameterKeys);
+ }
+
+ public Object readEntitySet() {
+ return invoke(setReadMethod, new Object[0]);
+ }
+
+ private Object invoke(Method m, Object[] objs) {
+ try {
+ return m.invoke(dataSourceInstance, objs);
+ } catch (Exception ex) {
+ return null;
+ }
+ }
+
+ public Object createEntityInstance() {
+ return createInstance(this.entityTypeClass);
+ }
+
+ private static Object createInstance(Class<?> clz) {
+ try {
+ return clz.newInstance();
+ } catch (Exception ex) {
+ return null;
+ }
+ }
+
+ public String getEntityName() {
+ return this.name;
+ }
+
+ @Override
+ public String toString() {
+ return "DataSourceHolder{" + "name=" + name + ", dataSourceInstance=" + dataSourceInstance +
+ ", entityTypeClass=" + entityTypeClass + ", consumerMethod=" + readMethod +
+ ", createMethod=" + createMethod + ", updateMethod=" + updateMethod + '}';
+ }
+
+ private boolean matches(Class<?> aClass, KeyPredicate type) {
+ return true;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ae7c1f52/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/json/EdmAnnotationSerializer.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/json/EdmAnnotationSerializer.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/json/EdmAnnotationSerializer.java
new file mode 100644
index 0000000..310e197
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/json/EdmAnnotationSerializer.java
@@ -0,0 +1,215 @@
+/*******************************************************************************
+ * 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.core.annotation.processor.json;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
+
+import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
+import org.apache.olingo.odata2.core.annotation.edm.AnnotationHelper;
+import org.apache.olingo.odata2.core.annotation.edm.ClassHelper;
+import org.apache.olingo.odata2.core.exception.ODataRuntimeException;
+
+public class EdmAnnotationSerializer {
+
+ private final String baseUri;
+ private static final AnnotationHelper ANNOTATION_HELPER = new AnnotationHelper();
+
+ public EdmAnnotationSerializer(String baseUri) {
+ this.baseUri = baseUri;
+ }
+
+ public InputStream serialize(Object obj) {
+ byte[] buf = getContent(obj).getBytes();
+ InputStream stream = new ByteArrayInputStream(buf);
+ return stream;
+ }
+
+ private String getContent(Object entity) {
+ if (entity == null) {
+ return "NULL";
+ } else if (isConsumable(entity)) {
+ try {
+ return handleEdmAnnotations(entity);
+ } catch (Exception e) {
+ throw new ODataRuntimeException("Exception with following message occured: " + e.getMessage(), e);
+ }
+ } else {
+ return entity.toString();
+ }
+ }
+
+ private String handleEdmAnnotations(Object entity)
+ throws IllegalArgumentException, IllegalAccessException, IOException {
+ //
+ Writer writer = new StringWriter();
+ JsonWriter json = new JsonWriter(writer);
+ json.start();
+ writeObject(entity, json);
+ json.finish();
+ writer.close();
+ //
+ return writer.toString();
+ }
+
+ private void writeObject(Object entity, JsonWriter json) throws IllegalAccessException {
+ if(entity.getClass().isArray()) {
+ List<Object> entities = Arrays.asList(entity);
+ writeCollection(entities, json);
+ } else if(Collection.class.isAssignableFrom(entity.getClass())) {
+ Collection<Object> entities = (Collection<Object>) entity;
+ writeCollection(entities, json);
+ } else {
+ writeSingleObject(entity, json);
+ }
+ }
+
+ private void writeCollection(Collection<Object> entities, JsonWriter json) throws IllegalAccessException {
+ json.startObject();
+ json.writeName("results");
+ json.startArray();
+ boolean writeSeperator = false;
+ for (Object object : entities) {
+ if(writeSeperator) {
+ json.writeSeparator();
+ } else {
+ writeSeperator = true;
+ }
+ writeSingleObject(object, json);
+ }
+ json.endArray();
+ json.endObject();
+ }
+
+ private void writeSingleObject(Object entity, JsonWriter json) throws IllegalAccessException {
+ List<Field> fields = getAllFields(entity.getClass());
+ json.startObject();
+ for (Field field : fields) {
+ boolean written = writeEdmProperty(entity, json, field);
+ if (!written) {
+ writeEdmNavigationProperty(entity, json, field);
+ }
+ }
+ json.endObject();
+ }
+
+ private boolean writeEdmNavigationProperty(Object entity, JsonWriter json, Field field)
+ throws IllegalArgumentException, IllegalAccessException {
+ EdmNavigationProperty navProperty = field.getAnnotation(EdmNavigationProperty.class);
+ EdmEntitySet property = entity.getClass().getAnnotation(EdmEntitySet.class);
+ if (navProperty != null) {
+ field.setAccessible(true);
+ Object keyValue = extractEdmKey(entity);
+ json.writeProperty("uri", baseUri + property.name() + "('" + keyValue.toString() + "')"
+ + "/" + navProperty.relationship());
+ return true;
+ }
+ return false;
+ }
+
+ private boolean writeEdmProperty(Object entity, JsonWriter json, Field field) throws IllegalAccessException {
+ EdmProperty property = field.getAnnotation(EdmProperty.class);
+ if (property != null) {
+ field.setAccessible(true);
+ Object fieldValue = field.get(entity);
+ String name = getName(property, field);
+ Class<?> defaultType = getType(property);
+ json.writeProperty(name, fieldValue, defaultType);
+ return true;
+ }
+ return false;
+ }
+
+ private Class<?> getType(EdmProperty property) {
+ Class<?> defaultType = property.type().getEdmSimpleTypeInstance().getDefaultType();
+ return defaultType;
+ }
+
+
+ private Object extractEdmKey(Object value) throws IllegalArgumentException, IllegalAccessException {
+ Field idField = getFieldWithAnnotation(value.getClass(), EdmKey.class);
+ if (idField == null) {
+ return "NULL";
+ }
+ idField.setAccessible(true);
+ return idField.get(value);
+ }
+
+ private Field getFieldWithAnnotation(Class<?> clazz, Class<? extends Annotation> annotationClazz) {
+
+ Field[] fields = clazz.getDeclaredFields();
+ for (Field field : fields) {
+ if (field.getAnnotation(annotationClazz) != null) {
+ return field;
+ }
+ }
+
+ Class<?> superclass = clazz.getSuperclass();
+ if (superclass != Object.class) {
+ return getFieldWithAnnotation(superclass, annotationClazz);
+ }
+
+ return null;
+ }
+
+ private List<Field> getAllFields(Class<?> clazz) {
+ Field[] fields = clazz.getDeclaredFields();
+ List<Field> allFields = new ArrayList<Field>(Arrays.asList(fields));
+
+ final Class<?> superclass = clazz.getSuperclass();
+ if (superclass != Object.class) {
+ allFields.addAll(getAllFields(superclass));
+ }
+
+ return allFields;
+ }
+
+ private boolean isConsumable(Object entity) {
+ if(entity == null) {
+ return false;
+ } else if(ANNOTATION_HELPER.isEdmAnnotated(entity)) {
+ return true;
+ } else if(entity.getClass().isArray() || entity.getClass().isAssignableFrom(Collection.class)) {
+ return true;
+ } else if(Collection.class.isAssignableFrom(entity.getClass())) {
+ return true;
+ }
+ return false;
+ }
+
+ private String getName(EdmProperty property, Field field) {
+ String name = property.name();
+ if(name.isEmpty()) {
+ name = ANNOTATION_HELPER.getCanonicalName(field);
+ }
+ return name;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ae7c1f52/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/json/JsonConsumer.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/json/JsonConsumer.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/json/JsonConsumer.java
new file mode 100644
index 0000000..4a6d9ad
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/json/JsonConsumer.java
@@ -0,0 +1,136 @@
+/*******************************************************************************
+ * 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.core.annotation.processor.json;
+
+import com.google.gson.stream.JsonReader;
+import com.google.gson.stream.JsonToken;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.olingo.odata2.core.ep.util.FormatJson;
+
+/**
+ *
+ */
+public class JsonConsumer {
+
+ private final JsonReader reader;
+ private final Map<String, String> properties;
+
+ public JsonConsumer(InputStream content) {
+ reader = new JsonReader(new InputStreamReader(content));
+ properties = new HashMap<String, String>();
+ }
+
+ public static Map<String, String> readContent(InputStream content) throws IOException {
+ JsonConsumer jc = new JsonConsumer(content);
+ return jc.read();
+ }
+
+ public Map<String, String> read() throws IOException {
+
+ reader.beginObject();
+ String nextName = reader.nextName();
+ if (FormatJson.D.equals(nextName)) {
+ reader.beginObject();
+ readEntryContent();
+ reader.endObject();
+ } else {
+ handleName(nextName);
+ readEntryContent();
+ }
+ reader.endObject();
+
+ return properties;
+ }
+
+ private void readEntryContent() throws IOException {
+ while (reader.hasNext()) {
+ final String name = reader.nextName();
+ handleName(name);
+ }
+ }
+
+ private void handleName(final String name) throws IOException {
+ if (FormatJson.METADATA.equals(name)) {
+ readMetadata();
+ } else {
+ readPropertyValue(name);
+ }
+ }
+
+ private void readPropertyValue(final String name) throws IOException {
+ final JsonToken tokenType = reader.peek();
+ final String value;
+
+ switch (tokenType) {
+ case STRING:
+ value = reader.nextString();
+ break;
+ case BOOLEAN:
+ value = String.valueOf(reader.nextBoolean());
+ break;
+ case NULL:
+ reader.nextNull();
+ default:
+ value = null;
+ }
+
+ properties.put(name, value);
+ }
+
+ private void readMetadata() throws IOException {
+ reader.beginObject();
+
+ while (reader.hasNext()) {
+ String name = reader.nextName();
+
+ if (FormatJson.PROPERTIES.equals(name)) {
+ reader.skipValue();
+ continue;
+ }
+
+ String value = reader.nextString();
+ if (FormatJson.ID.equals(name)) {
+ properties.put("md_" + name, value);
+ } else if (FormatJson.URI.equals(name)) {
+ properties.put("md_" + name, value);
+ } else if (FormatJson.TYPE.equals(name)) {
+ properties.put("md_" + name, value);
+ } else if (FormatJson.ETAG.equals(name)) {
+ properties.put("md_" + name, value);
+ } else if (FormatJson.EDIT_MEDIA.equals(name)) {
+ properties.put("md_" + name, value);
+ } else if (FormatJson.MEDIA_SRC.equals(name)) {
+ properties.put("md_" + name, value);
+ } else if (FormatJson.MEDIA_ETAG.equals(name)) {
+ properties.put("md_" + name, value);
+ } else if (FormatJson.CONTENT_TYPE.equals(name)) {
+ properties.put("md_" + name, value);
+ } else {
+ throw new IllegalStateException("Unknown metadata");
+ }
+ }
+
+ reader.endObject();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ae7c1f52/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/json/JsonWriter.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/json/JsonWriter.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/json/JsonWriter.java
new file mode 100644
index 0000000..1c1cc21
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/json/JsonWriter.java
@@ -0,0 +1,256 @@
+/*******************************************************************************
+ * 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.core.annotation.processor.json;
+
+import java.io.IOException;
+import java.io.Writer;
+import org.apache.olingo.odata2.core.exception.ODataRuntimeException;
+
+public class JsonWriter {
+
+ private final Writer writer;
+ private boolean firstProperty = true;
+
+ public JsonWriter(Writer writer) {
+ this.writer = writer;
+ }
+
+ public void startCallback(String functionName) {
+ try {
+ writer.write(encode(functionName) + "(");
+ } catch (IOException e) {
+ throw new ODataRuntimeException(e.getMessage(), e);
+ }
+ }
+
+ public void endCallback() {
+ try {
+ writer.write(");");
+ } catch (IOException e) {
+ throw new ODataRuntimeException(e.getMessage(), e);
+ }
+ }
+
+ public void startObject() {
+ try {
+ firstProperty = true;
+ writer.write("{\n");
+ } catch (IOException e) {
+ throw new ODataRuntimeException(e.getMessage(), e);
+ }
+ }
+
+ public void endObject() {
+ try {
+ firstProperty = false;
+ writer.write("\n}");
+ } catch (IOException e) {
+ throw new ODataRuntimeException(e.getMessage(), e);
+ }
+ }
+
+ public void writeName(String name) {
+ try {
+ writer.write("\"" + encode(name) + "\" : ");
+ } catch (IOException e) {
+ throw new ODataRuntimeException(e.getMessage(), e);
+ }
+ }
+
+ public void startArray() {
+ try {
+ writer.write("[\n");
+ } catch (IOException e) {
+ throw new ODataRuntimeException(e.getMessage(), e);
+ }
+ }
+
+ public void endArray() {
+ try {
+ writer.write("\n]");
+ } catch (IOException e) {
+ throw new ODataRuntimeException(e.getMessage(), e);
+ }
+ }
+
+ public void writeSeparator() {
+ try {
+ writer.write(", ");
+ } catch (IOException e) {
+ throw new ODataRuntimeException(e.getMessage(), e);
+ }
+ }
+
+ public void writeString(String value) {
+ try {
+ writer.write("\"" + encode(value) + "\"");
+ } catch (IOException e) {
+ throw new ODataRuntimeException(e.getMessage(), e);
+ }
+ }
+
+ public void writeNull() {
+ try {
+ writer.write("null");
+ } catch (IOException e) {
+ throw new ODataRuntimeException(e.getMessage(), e);
+ }
+ }
+
+ public void writeNumber(int value) {
+ try {
+ writer.write(Integer.toString(value));
+ } catch (IOException e) {
+ throw new ODataRuntimeException(e.getMessage(), e);
+ }
+ }
+
+ public void writeNumber(float value) {
+ try {
+ String fvalue = Float.toString(value);
+ while (fvalue.contains(".") && fvalue.endsWith("0")) {
+ fvalue = fvalue.substring(0, fvalue.length() - 1);
+ }
+ if (fvalue.endsWith(".")) {
+ fvalue = fvalue.substring(0, fvalue.length() - 1);
+ }
+ writer.write(fvalue);
+ } catch (IOException e) {
+ throw new ODataRuntimeException(e.getMessage(), e);
+ }
+ }
+
+ public void writeNumber(double value) {
+ try {
+ String fvalue = Double.toString(value);
+ while (fvalue.contains(".") && fvalue.endsWith("0")) {
+ fvalue = fvalue.substring(0, fvalue.length() - 1);
+ }
+ if (fvalue.endsWith(".")) {
+ fvalue = fvalue.substring(0, fvalue.length() - 1);
+ }
+ writer.write(fvalue);
+ } catch (IOException e) {
+ throw new ODataRuntimeException(e.getMessage(), e);
+ }
+ }
+
+ public void writeBoolean(boolean value) {
+ try {
+ writer.write(value ? "true" : "false");
+ } catch (IOException e) {
+ throw new ODataRuntimeException(e.getMessage(), e);
+ }
+ }
+
+ public void writeProperty(String name, Object value) {
+ if(value == null) {
+ writeProperty(name, value, null);
+ } else {
+ writeProperty(name, value, value.getClass());
+ }
+ }
+
+
+ void writeProperty(String name, Object value, Class<?> defaultType) {
+ if (firstProperty) {
+ firstProperty = false;
+ } else {
+ writeSeparator();
+ }
+
+ // write content
+ this.writeName(name);
+ if (value == null) {
+ writeNull();
+ } else {
+ try {
+ if(defaultType == null) {
+ writeValue(value);
+ } else {
+ writeValueAs(value, defaultType);
+ }
+ } catch (Exception e) {
+ writeString("exception for property with name '" + name
+ + "' with message '" + e.getMessage()
+ + "' and toString '" + value.toString() + "'.");
+ }
+ }
+ }
+
+
+ public void writeRaw(String value) {
+ try {
+ writer.write(value);
+ } catch (IOException e) {
+ throw new ODataRuntimeException(e.getMessage(), e);
+ }
+ }
+
+ private String encode(String unencoded) {
+ StringBuilder sb = new StringBuilder();
+ for (int i = 0; i < unencoded.length(); i++) {
+ char c = unencoded.charAt(i);
+ if (c == '\\') {
+ sb.append("\\\\");
+ } else if (c == '"') {
+ sb.append("\\\"");
+ } else if (c == '\n') {
+ sb.append("\\n");
+ } else if (c == '\r') {
+ sb.append("\\r");
+ } else if (c == '\f') {
+ sb.append("\\f");
+ } else if (c == '\b') {
+ sb.append("\\b");
+ } else if (c == '\t') {
+ sb.append("\\t");
+ } else {
+ sb.append(c);
+ }
+ }
+ return sb.toString();
+ }
+
+ void start() {
+ writeRaw("{\n\"d\":");
+ }
+
+ void finish() {
+ writeRaw("\n}");
+ }
+
+ private void writeValueAs(Object value, Class<?> clazz) {
+ if(clazz.isAssignableFrom(String.class)) {
+ writeString(String.valueOf(value));
+ } else if(clazz.isAssignableFrom(Float.class)) {
+ writeNumber((Float) value);
+ } else if(clazz.isAssignableFrom(Double.class)) {
+ writeNumber((Double) value);
+ } else if(clazz.isAssignableFrom(Integer.class)) {
+ writeNumber((Integer) value);
+ } else {
+ writeString(value.toString());
+ }
+ }
+
+ private void writeValue(Object value) {
+ writeValueAs(value, value.getClass());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ae7c1f52/odata2-edm-annotation/edm-annotation-core/src/main/resources/log4j.xml
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/resources/log4j.xml b/odata2-edm-annotation/edm-annotation-core/src/main/resources/log4j.xml
new file mode 100644
index 0000000..90a4706
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/resources/log4j.xml
@@ -0,0 +1,39 @@
+<?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>
+
+ <logger name="org.apache.olingo.odata2.ref" additivity="false">
+ <level value="trace" />
+ <appender-ref ref="console" />
+ </logger>
+
+ <root>
+ <priority value="error" />
+ <appender-ref ref="console" />
+ </root>
+</log4j:configuration>
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ae7c1f52/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProviderTest.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProviderTest.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProviderTest.java
new file mode 100644
index 0000000..509303c
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProviderTest.java
@@ -0,0 +1,318 @@
+/*
+ * Copyright 2013 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * 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.core.annotation.edm;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
+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.ComplexType;
+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.FunctionImport;
+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.Schema;
+import org.apache.olingo.odata2.core.annotation.model.Building;
+import org.apache.olingo.odata2.core.annotation.model.City;
+import org.apache.olingo.odata2.core.annotation.model.Employee;
+import org.apache.olingo.odata2.core.annotation.model.Location;
+import org.apache.olingo.odata2.core.annotation.model.Manager;
+import org.apache.olingo.odata2.core.annotation.model.ModelSharedConstants;
+import org.apache.olingo.odata2.core.annotation.model.Photo;
+import org.apache.olingo.odata2.core.annotation.model.RefBase;
+import org.apache.olingo.odata2.core.annotation.model.Room;
+import org.apache.olingo.odata2.core.annotation.model.Team;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import org.junit.Test;
+
+/**
+ *
+ * @author d046871
+ */
+public class AnnotationEdmProviderTest {
+
+ private final Collection<Class<?>> annotatedClasses = new ArrayList<Class<?>>();
+ private final AnnotationEdmProvider aep;
+
+ public AnnotationEdmProviderTest() {
+ annotatedClasses.add(RefBase.class);
+ annotatedClasses.add(Building.class);
+ annotatedClasses.add(City.class);
+ annotatedClasses.add(Employee.class);
+ annotatedClasses.add(Location.class);
+ annotatedClasses.add(Manager.class);
+ annotatedClasses.add(Photo.class);
+ annotatedClasses.add(Room.class);
+ annotatedClasses.add(Team.class);
+
+ aep = new AnnotationEdmProvider(annotatedClasses);
+ }
+
+ @Test
+ public void loadAnnotatedClassesFromPackage() throws Exception {
+ AnnotationEdmProvider localAep = new AnnotationEdmProvider("org.apache.olingo.odata2.core.annotation.model");
+
+ // validate employee
+ EntityType employee = localAep.getEntityType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "Employee"));
+ assertEquals("Employee", employee.getName());
+ final List<PropertyRef> employeeKeys = employee.getKey().getKeys();
+ assertEquals(1, employeeKeys.size());
+ assertEquals("EmployeeId", employeeKeys.get(0).getName());
+ assertEquals(4, employee.getProperties().size());
+ assertEquals(1, employee.getNavigationProperties().size());
+
+ List<Schema> schemas = localAep.getSchemas();
+ assertEquals(1, schemas.size());
+ EntityContainerInfo info = localAep.getEntityContainerInfo(ModelSharedConstants.CONTAINER_1);
+ assertTrue(info.isDefaultEntityContainer());
+ }
+
+ @Test
+ public void annotationProviderBasic() throws Exception {
+ assertNotNull(aep);
+
+ List<Schema> schemas = aep.getSchemas();
+ assertEquals(1, schemas.size());
+ EntityContainerInfo info = aep.getEntityContainerInfo(ModelSharedConstants.CONTAINER_1);
+ assertTrue(info.isDefaultEntityContainer());
+
+ FunctionImport funImp = aep.getFunctionImport(ModelSharedConstants.CONTAINER_1, "NoImport");
+ assertNull(funImp);
+
+ final FullQualifiedName associationFqn = new FullQualifiedName(
+ ModelSharedConstants.NAMESPACE_1, "NoAssociation");
+ Association noAssociation = aep.getAssociation(associationFqn);
+ assertNull(noAssociation);
+
+ AssociationSet noAssociationSet = aep.getAssociationSet(
+ ModelSharedConstants.CONTAINER_1, associationFqn, "NoSrc", "NoSrcEntity");
+ assertNull(noAssociationSet);
+
+ AssociationSet asBuildingRooms = aep.getAssociationSet(
+ ModelSharedConstants.CONTAINER_1, defaultFqn("BuildingRooms"), "Buildings", "r_Building");
+ assertNotNull(asBuildingRooms);
+ assertEquals("Buildings", asBuildingRooms.getEnd1().getEntitySet());
+ assertEquals("r_Building", asBuildingRooms.getEnd1().getRole());
+ assertEquals("Rooms", asBuildingRooms.getEnd2().getEntitySet());
+ assertEquals("r_Room", asBuildingRooms.getEnd2().getRole());
+ }
+
+ @Test
+ public void annotationProviderGetDefaultContainer() throws Exception {
+ assertNotNull(aep);
+
+ List<Schema> schemas = aep.getSchemas();
+ assertEquals(1, schemas.size());
+ EntityContainerInfo info = aep.getEntityContainerInfo(null);
+ assertTrue(info.isDefaultEntityContainer());
+ assertEquals(ModelSharedConstants.CONTAINER_1, info.getName());
+ }
+
+ @Test
+ public void schemaBasic() throws Exception {
+ assertNotNull(aep);
+
+ List<Schema> schemas = aep.getSchemas();
+ assertEquals(1, schemas.size());
+
+ Schema schema = schemas.get(0);
+ List<EntityContainer> containers = schema.getEntityContainers();
+ assertEquals(1, containers.size());
+ EntityContainer container = containers.get(0);
+ assertEquals(ModelSharedConstants.CONTAINER_1, container.getName());
+ final List<EntitySet> entitySets = container.getEntitySets();
+ assertEquals(5, entitySets.size());
+
+ List<Association> associations = schema.getAssociations();
+ assertEquals(4, associations.size());
+ for (Association association : associations) {
+ assertNotNull(association.getName());
+ validateAssociation(association);
+ }
+ }
+
+ private FullQualifiedName defaultFqn(String name) {
+ return new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, name);
+ }
+
+ private void validateAssociation(Association association) {
+ String name = association.getName();
+ if(name.equals("RoomEmployees")) {
+ validateAssociation(association,
+ "r_Room", EdmMultiplicity.ONE, defaultFqn("Room"),
+ "r_Employees", EdmMultiplicity.MANY, defaultFqn("Employee"));
+ } else if(name.equals("BuildingRooms")) {
+ validateAssociation(association,
+ "r_Building", EdmMultiplicity.ONE, defaultFqn("Building"),
+ "r_Room", EdmMultiplicity.MANY, defaultFqn("Room"));
+ } else if(name.equals("ManagerEmployees")) {
+ validateAssociation(association,
+ "r_Manager", EdmMultiplicity.ONE, defaultFqn("Manager"),
+ "r_Employees", EdmMultiplicity.MANY, defaultFqn("Employee"));
+ } else if(name.equals("TeamEmployees")) {
+ validateAssociation(association,
+ "r_Team", EdmMultiplicity.ONE, defaultFqn("Team"),
+ "r_Employees", EdmMultiplicity.MANY, defaultFqn("Employee"));
+ } else {
+ fail("Got unknown association to validate with name '" + name + "'.");
+ }
+ }
+
+ private void validateAssociation(Association association,
+ String fromRole, EdmMultiplicity fromMulti, FullQualifiedName fromType,
+ String toRole, EdmMultiplicity toMulti, FullQualifiedName toType) {
+
+ AssociationEnd[] ends = new AssociationEnd[]{association.getEnd1(),association.getEnd2()};
+ for (AssociationEnd associationEnd : ends) {
+ if(associationEnd.getRole().equals(fromRole)) {
+ validateAssociationEnd(associationEnd, fromRole, fromMulti, fromType);
+ } else if(associationEnd.getRole().equals(toRole)) {
+ validateAssociationEnd(associationEnd, toRole, toMulti, toType);
+ } else {
+ fail("Unexpected navigation end '" + associationEnd.getRole()
+ + "' for association with name '" + association.getName() + "'.");
+ }
+ }
+ }
+
+ private void validateAssociationEnd(AssociationEnd associationEnd,
+ String role, EdmMultiplicity multiplicity, FullQualifiedName type) {
+ assertEquals(role, associationEnd.getRole());
+ assertEquals(multiplicity, associationEnd.getMultiplicity());
+ assertEquals(type, associationEnd.getType());
+ }
+
+
+ @Test
+ public void entitySetTeams() throws Exception {
+ // validate teams
+ EntitySet teams = aep.getEntitySet(ModelSharedConstants.CONTAINER_1, "Teams");
+ assertEquals(ModelSharedConstants.NAMESPACE_1, teams.getEntityType().getNamespace());
+ assertEquals("Team", teams.getEntityType().getName());
+ }
+
+ @Test
+ public void entityTypeEmployee() throws Exception {
+ // validate employee
+ EntityType employee = aep.getEntityType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "Employee"));
+ assertEquals("Employee", employee.getName());
+ final List<PropertyRef> employeeKeys = employee.getKey().getKeys();
+ assertEquals(1, employeeKeys.size());
+ assertEquals("EmployeeId", employeeKeys.get(0).getName());
+ assertEquals(4, employee.getProperties().size());
+ assertEquals(1, employee.getNavigationProperties().size());
+ }
+
+ @Test
+ public void entityTypeTeam() throws Exception {
+ // validate team
+ EntityType team = aep.getEntityType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "Team"));
+ assertEquals("Team", team.getName());
+ assertEquals("Base", team.getBaseType().getName());
+ assertEquals(ModelSharedConstants.NAMESPACE_1, team.getBaseType().getNamespace());
+
+ assertEquals(1, team.getProperties().size());
+ assertEquals(1, team.getNavigationProperties().size());
+ }
+
+ @Test
+ public void entityTypeAbstractBaseType() throws Exception {
+ // validate employee
+ EntityType baseType = aep.getEntityType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "Base"));
+ assertEquals("Base", baseType.getName());
+ final List<PropertyRef> keys = baseType.getKey().getKeys();
+ assertEquals(1, keys.size());
+ assertEquals("Id", keys.get(0).getName());
+ assertEquals(2, baseType.getProperties().size());
+ assertTrue(baseType.isAbstract());
+
+ // validate base for team
+ EntityType team = aep.getEntityType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "Team"));
+ assertEquals("Team", team.getName());
+ assertEquals("Base", team.getBaseType().getName());
+ assertEquals(ModelSharedConstants.NAMESPACE_1, team.getBaseType().getNamespace());
+ }
+
+ @Test
+ public void complexTypeLocation() throws Exception {
+ // validate employee
+ EntityType employee = aep.getEntityType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "Employee"));
+ final List<Property> properties = employee.getProperties();
+ Property location = null;
+ for (Property property : properties) {
+ if (property.getName().equals("Location")) {
+ location = property;
+ }
+ }
+ assertNotNull(location);
+ assertEquals("Location", location.getName());
+
+ // validate location complex type
+ ComplexType locationType = aep.getComplexType(
+ new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "c_Location"));
+ assertEquals("c_Location", locationType.getName());
+ assertEquals(2, locationType.getProperties().size());
+ }
+
+ @Test
+ public void entityTypeRoomWithNavigation() throws Exception {
+ // validate employee
+ EntityType room = aep.getEntityType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "Room"));
+ assertEquals("Room", room.getName());
+ assertEquals("Base", room.getBaseType().getName());
+ assertEquals(2, room.getProperties().size());
+ final List<NavigationProperty> navigationProperties = room.getNavigationProperties();
+ assertEquals(2, navigationProperties.size());
+
+ for (NavigationProperty navigationProperty : navigationProperties) {
+ if(navigationProperty.getName().equals("nr_Employees")) {
+ validateNavProperty(navigationProperty, "RoomEmployees", "r_Room", "r_Employees");
+ } else if(navigationProperty.getName().equals("nr_Building")) {
+ validateNavProperty(navigationProperty, "BuildingRooms", "r_Room", "r_Building");
+ } else {
+ fail("Got unexpected navigation property with name '" + navigationProperty.getName() + "'.");
+ }
+ }
+ }
+
+ private void validateNavProperty(NavigationProperty navigationProperty, String name,
+ String relationship, String fromRole, String toRole) {
+ if(name != null) {
+ assertEquals(name, navigationProperty.getName());
+ }
+ FullQualifiedName fqn = new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, relationship);
+ assertEquals("Wrong relationship for navigation property.", fqn, navigationProperty.getRelationship());
+ assertEquals("Wrong fromRole for navigation property.", fromRole, navigationProperty.getFromRole());
+ assertEquals("Wrong toRole for navigation property.", toRole, navigationProperty.getToRole());
+ }
+
+ private void validateNavProperty(NavigationProperty navigationProperty,
+ String relationship, String fromRole, String toRole) {
+ validateNavProperty(navigationProperty, null, relationship, fromRole, toRole);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ae7c1f52/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Building.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Building.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Building.java
new file mode 100644
index 0000000..1da4bdb
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Building.java
@@ -0,0 +1,100 @@
+/*******************************************************************************
+ * 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.core.annotation.model;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
+import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
+import org.apache.olingo.odata2.api.annotation.edm.NavigationEnd;
+import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
+import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
+
+/**
+ *
+ */
+@EdmEntityType(name="Building", namespace=ModelSharedConstants.NAMESPACE_1)
+@EdmEntitySet(name="Buildings", container="Container1")
+public class Building {
+ @EdmKey
+ @EdmProperty(type = EdmSimpleTypeKind.String)
+ private int id;
+ @EdmProperty
+ private String name;
+ private byte[] image;
+ @EdmNavigationProperty(name="nb_rooms", relationship="BuildingRooms",
+ to = @NavigationEnd(role = "r_Room", type="Room", multiplicity = EdmMultiplicity.MANY))
+ private List<Room> rooms = new ArrayList<Room>();
+
+ public Building() {
+ }
+
+ public Building(final int id, final String name) {
+ this.id = id;
+ setName(name);
+ }
+
+ public String getId() {
+ return Integer.toString(id);
+ }
+
+ public void setName(final String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setImage(final byte[] byteArray) {
+ image = byteArray;
+ }
+
+ public byte[] getImage() {
+ if (image == null) {
+ return null;
+ } else {
+ return image.clone();
+ }
+ }
+
+ public List<Room> getRooms() {
+ return rooms;
+ }
+
+ @Override
+ public int hashCode() {
+ return id;
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ return this == obj
+ || obj != null && getClass() == obj.getClass() && id == ((Building) obj).id;
+ }
+
+ @Override
+ public String toString() {
+ return "{\"Id\":\"" + id + "\",\"Name\":\"" + name + "\",\"Image\":\"" + Arrays.toString(image) + "\"}";
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ae7c1f52/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/City.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/City.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/City.java
new file mode 100644
index 0000000..6a117db
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/City.java
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ ******************************************************************************/
+package org.apache.olingo.odata2.core.annotation.model;
+
+import org.apache.olingo.odata2.api.annotation.edm.EdmComplexEntity;
+import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
+
+/**
+ *
+ */
+@EdmComplexEntity(name="c_City", namespace = ModelSharedConstants.NAMESPACE_1)
+public class City {
+
+ @EdmProperty
+ private String postalCode;
+ @EdmProperty
+ private String cityName;
+
+ public City(final String postalCode, final String name) {
+ this.postalCode = postalCode;
+ cityName = name;
+ }
+
+ public void setPostalCode(final String postalCode) {
+ this.postalCode = postalCode;
+ }
+
+ public String getPostalCode() {
+ return postalCode;
+ }
+
+ public void setCityName(final String cityName) {
+ this.cityName = cityName;
+ }
+
+ public String getCityName() {
+ return cityName;
+ }
+
+ @Override
+ public String toString() {
+ return String.format("%s, %s", cityName, postalCode);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ae7c1f52/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Employee.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Employee.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Employee.java
new file mode 100644
index 0000000..0323ecc
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Employee.java
@@ -0,0 +1,181 @@
+/*******************************************************************************
+ * 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.core.annotation.model;
+
+import java.text.DateFormat;
+import java.util.Calendar;
+import org.apache.olingo.odata2.api.annotation.edm.EdmComplexProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
+import org.apache.olingo.odata2.api.annotation.edm.NavigationEnd;
+import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
+import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
+
+/**
+ *
+ */
+@EdmEntityType(name="Employee", namespace=ModelSharedConstants.NAMESPACE_1)
+@EdmEntitySet(name="Employees", container=ModelSharedConstants.CONTAINER_1)
+public class Employee {
+ private static int counter = 1;
+ @EdmProperty(name="EmployeeId", type = EdmSimpleTypeKind.Int32)
+ @EdmKey
+ private int employeeId;
+ @EdmProperty(name="EmployeeName")
+ private String employeeName;
+ @EdmProperty
+ private int age;
+ @EdmNavigationProperty(name="ne_Manager", relationship="ManagerEmployees",
+ from = @NavigationEnd(role="r_Employees", multiplicity = EdmMultiplicity.MANY))//,
+// to = @NavigationEnd(type = "Manager"))
+ private Manager manager;
+ private Team team;
+ private Room room;
+ private String imageType;
+ private byte[] image;
+ private String imageUrl;
+ private Calendar entryDate;
+ @EdmComplexProperty(name="Location")
+ private Location location;
+
+ public Employee(final int employeeId, final String name) {
+ this.employeeId = employeeId;
+ setEmployeeName(name);
+ }
+
+ public String getId() {
+ return Integer.toString(employeeId);
+ }
+
+ public void setEmployeeName(final String employeeName) {
+ this.employeeName = employeeName;
+ }
+
+ public String getEmployeeName() {
+ return employeeName;
+ }
+
+ public void setAge(final int age) {
+ this.age = age;
+ }
+
+ public int getAge() {
+ return age;
+ }
+
+ public void setManager(final Manager manager) {
+ this.manager = manager;
+ }
+
+ public Manager getManager() {
+ return manager;
+ }
+
+ public void setTeam(final Team team) {
+ this.team = team;
+ }
+
+ public Team getTeam() {
+ return team;
+ }
+
+ public void setRoom(final Room room) {
+ this.room = room;
+ }
+
+ public Room getRoom() {
+ return room;
+ }
+
+ public void setImageUri(final String imageUri) {
+ imageUrl = imageUri;
+ }
+
+ public String getImageUri() {
+ return imageUrl;
+ }
+
+ public void setLocation(final Location location) {
+ this.location = location;
+ }
+
+ public Location getLocation() {
+ return location;
+ }
+
+ public void setEntryDate(final Calendar date) {
+ entryDate = date;
+ }
+
+ public Calendar getEntryDate() {
+ return entryDate;
+ }
+
+ public void setImageType(final String imageType) {
+ this.imageType = imageType;
+ }
+
+ public String getImageType() {
+ return imageType;
+ }
+
+ public void setImage(final byte[] image) {
+ this.image = image;
+ }
+
+ public byte[] getImage() {
+ if (image == null) {
+ return null;
+ }
+ return image.clone();
+ }
+
+ @Override
+ public int hashCode() {
+ return employeeId;
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ return this == obj
+ || obj != null && getClass() == obj.getClass() && employeeId == ((Employee) obj).employeeId;
+ }
+
+ @Override
+ public String toString() {
+ return "{\"EmployeeId\":\"" + employeeId + "\","
+ + "\"EmployeeName\":\"" + employeeName + "\","
+ + "\"ManagerId\":" + (manager == null ? "null" : "\"" + manager.getId() + "\"") + ","
+ + "\"RoomId\":" + (room == null ? "null" : "\"" + room.getId() + "\"") + ","
+ + "\"TeamId\":" + (team == null ? "null" : "\"" + team.getId() + "\"") + ","
+ + "\"Location\":"
+ + (location == null ? "null" :
+ "{\"City\":" + (location.getCity() == null ? "null" :
+ "{\"PostalCode\":\"" + location.getCity().getPostalCode() + "\","
+ + "\"CityName\":\"" + location.getCity().getCityName() + "\"}") + ","
+ + "\"Country\":\"" + location.getCountry() + "\"}") + ","
+ + "\"Age\":" + age + ","
+ + "\"EntryDate\":"
+ + (entryDate == null ? "null" : "\"" + DateFormat.getInstance().format(entryDate.getTime()) + "\"") + ","
+ + "\"ImageUrl\":\"" + imageUrl + "\"}";
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ae7c1f52/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Location.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Location.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Location.java
new file mode 100644
index 0000000..3b74c30
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Location.java
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ ******************************************************************************/
+package org.apache.olingo.odata2.core.annotation.model;
+
+import org.apache.olingo.odata2.api.annotation.edm.EdmComplexEntity;
+import org.apache.olingo.odata2.api.annotation.edm.EdmComplexProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
+
+/**
+ *
+ */
+@EdmComplexEntity(name = "c_Location", namespace = ModelSharedConstants.NAMESPACE_1)
+public class Location {
+ @EdmProperty
+ private String country;
+ @EdmComplexProperty
+ private City city;
+
+ public Location(final String country, final String postalCode, final String cityName) {
+ this.country = country;
+ city = new City(postalCode, cityName);
+ }
+
+ public void setCountry(final String country) {
+ this.country = country;
+ }
+
+ public String getCountry() {
+ return country;
+ }
+
+ public void setCity(final City city) {
+ this.city = city;
+ }
+
+ public City getCity() {
+ return city;
+ }
+
+ @Override
+ public String toString() {
+ return String.format("%s, %s", country, city.toString());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ae7c1f52/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Manager.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Manager.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Manager.java
new file mode 100644
index 0000000..1408c9c
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Manager.java
@@ -0,0 +1,46 @@
+/*******************************************************************************
+ * 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.core.annotation.model;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
+import org.apache.olingo.odata2.api.annotation.edm.NavigationEnd;
+
+/**
+ *
+ */
+@EdmEntityType(name = "Manager", namespace = ModelSharedConstants.NAMESPACE_1)
+@EdmEntitySet(name = "Managers", container = ModelSharedConstants.CONTAINER_1)
+public class Manager extends Employee {
+
+ @EdmNavigationProperty(name = "nm_Employees", relationship = "ManagerEmployees",
+ to = @NavigationEnd(role = "r_Employees", type = "Employee"))
+ private List<Employee> employees = new ArrayList<Employee>();
+
+ public Manager(final int id, final String name) {
+ super(id, name);
+ }
+
+ public List<Employee> getEmployees() {
+ return employees;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ae7c1f52/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/ModelSharedConstants.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/ModelSharedConstants.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/ModelSharedConstants.java
new file mode 100644
index 0000000..f87165f
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/ModelSharedConstants.java
@@ -0,0 +1,25 @@
+/*******************************************************************************
+ * 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.core.annotation.model;
+
+public interface ModelSharedConstants {
+
+ String NAMESPACE_1 = "RefScenario";
+ String CONTAINER_1 = "Container1";
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ae7c1f52/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Photo.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Photo.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Photo.java
new file mode 100644
index 0000000..6c89654
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Photo.java
@@ -0,0 +1,130 @@
+/*******************************************************************************
+ * 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.core.annotation.model;
+
+import java.util.Arrays;
+
+/**
+ *
+ */
+public class Photo {
+ private static final String RESOURCE = "/male_1_WinterW.jpg";
+
+ private final int id;
+ private String name;
+ private String type = "image/jpeg";
+ private String imageUrl = "http://localhost" + RESOURCE;
+ private byte[] image = new byte[0];
+ private String imageType = type;
+ private byte[] binaryData;
+ private String content;
+
+ public Photo(final int id, final String name, final String type) {
+ this.id = id;
+ setName(name);
+ setType(type);
+ }
+
+ public int getId() {
+ return id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(final String name) {
+ this.name = name;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(final String type) {
+ this.type = type;
+ }
+
+ public String getImageUri() {
+ return imageUrl;
+ }
+
+ public void setImageUri(final String uri) {
+ imageUrl = uri;
+ }
+
+ public byte[] getImage() {
+ return image.clone();
+ }
+
+ public void setImage(final byte[] image) {
+ this.image = image;
+ }
+
+ public String getImageType() {
+ return imageType;
+ }
+
+ public void setImageType(final String imageType) {
+ this.imageType = imageType;
+ }
+
+ public byte[] getBinaryData() {
+ if (binaryData == null) {
+ return null;
+ } else {
+ return binaryData.clone();
+ }
+ }
+
+ public void setBinaryData(final byte[] binaryData) {
+ this.binaryData = binaryData;
+ }
+
+ public void setContent(final String content) {
+ this.content = content;
+ }
+
+ public String getContent() {
+ return content;
+ }
+
+ @Override
+ public int hashCode() {
+ return id;
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ return this == obj
+ || obj != null && getClass() == obj.getClass() && id == ((Photo) obj).id;
+ }
+
+ @Override
+ public String toString() {
+ return "{\"Id\":" + id + ","
+ + "\"Name\":\"" + name + "\","
+ + "\"Type\":\"" + type + "\","
+ + "\"ImageUrl\":\"" + imageUrl + "\","
+ + "\"Image\":\"" + Arrays.toString(image) + "\","
+ + "\"ImageType\":\"" + imageType + "\","
+ + "\"Content:\"" + content + "\","
+ + "\"BinaryData\":\"" + Arrays.toString(binaryData) + "\"}";
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ae7c1f52/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/RefBase.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/RefBase.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/RefBase.java
new file mode 100644
index 0000000..15a7dcc
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/RefBase.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2013 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * 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.core.annotation.model;
+
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
+import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
+
+/**
+ *
+ */
+@EdmEntityType(name="Base", namespace=ModelSharedConstants.NAMESPACE_1)
+public abstract class RefBase {
+ @EdmProperty(name="Name")
+ protected String name;
+ @EdmProperty(name="Id", type = EdmSimpleTypeKind.String)
+ @EdmKey
+ protected int id;
+
+ public RefBase(int id, String name) {
+ this.name = name;
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getId() {
+ return Integer.toString(id);
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ae7c1f52/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Room.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Room.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Room.java
new file mode 100644
index 0000000..8c8a62d
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Room.java
@@ -0,0 +1,93 @@
+/*
+ * Copyright 2013 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * 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.core.annotation.model;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
+import org.apache.olingo.odata2.api.annotation.edm.NavigationEnd;
+import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
+
+/**
+ *
+ */
+@EdmEntityType(name = "Room", namespace = ModelSharedConstants.NAMESPACE_1)
+@EdmEntitySet(name = "Rooms", container = ModelSharedConstants.CONTAINER_1)
+public class Room extends RefBase {
+
+ @EdmProperty
+ private Integer seats;
+ @EdmProperty
+ private Integer version;
+ @EdmNavigationProperty(name = "nr_Building", relationship = "BuildingRooms",
+ from = @NavigationEnd(role = "r_Room", multiplicity = EdmMultiplicity.MANY))
+ private Building building;
+ @EdmNavigationProperty(name = "nr_Employees", relationship = "RoomEmployees",
+ from = @NavigationEnd(role = "r_Room", type = "Room", multiplicity = EdmMultiplicity.ONE),
+ to = @NavigationEnd(role = "r_Employees", type = "Employee", multiplicity = EdmMultiplicity.MANY))
+ private List<Employee> employees = new ArrayList<Employee>();
+
+ public Room(final int id, final String name) {
+ super(id, name);
+ }
+
+ public void setSeats(final int seats) {
+ this.seats = seats;
+ }
+
+ public int getSeats() {
+ return seats;
+ }
+
+ public void setVersion(final int version) {
+ this.version = version;
+ }
+
+ public int getVersion() {
+ return version;
+ }
+
+ public void setBuilding(final Building building) {
+ this.building = building;
+ }
+
+ public Building getBuilding() {
+ return building;
+ }
+
+ public List<Employee> getEmployees() {
+ return employees;
+ }
+
+ @Override
+ public int hashCode() {
+ return id;
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ return this == obj
+ || obj != null && getClass() == obj.getClass() && id == ((Room) obj).id;
+ }
+
+ @Override
+ public String toString() {
+ return "{\"Id\":\"" + id + "\",\"Name\":\"" + name + "\",\"Seats\":" + seats + ",\"Version\":" + version + "}";
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ae7c1f52/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Team.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Team.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Team.java
new file mode 100644
index 0000000..363ad7a
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Team.java
@@ -0,0 +1,83 @@
+/*******************************************************************************
+ * 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.core.annotation.model;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
+import org.apache.olingo.odata2.api.annotation.edm.NavigationEnd;
+import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
+import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
+
+/**
+*
+*/
+@EdmEntityType(name="Team", namespace = ModelSharedConstants.NAMESPACE_1)
+@EdmEntitySet(name="Teams", container = ModelSharedConstants.CONTAINER_1)
+public class Team extends RefBase {
+ @EdmProperty(type = EdmSimpleTypeKind.Boolean)
+ private Boolean isScrumTeam;
+ @EdmNavigationProperty(name = "ne_Teams", relationship="TeamEmployees",
+ from = @NavigationEnd(role = "r_Team", type = "Team"),
+ to = @NavigationEnd(role = "r_Employees", type = "Employee", multiplicity = EdmMultiplicity.MANY))
+ private List<Employee> employees = new ArrayList<Employee>();
+
+ public Team() {
+ super(-1, null);
+ }
+
+ public Team(final int id, final String name) {
+ super(id, name);
+ }
+
+ public Boolean isScrumTeam() {
+ return isScrumTeam;
+ }
+
+ public void setScrumTeam(final Boolean isScrumTeam) {
+ this.isScrumTeam = isScrumTeam;
+ }
+
+ public void addEmployee(Employee e) {
+ this.employees.add(e);
+ }
+
+ public List<Employee> getEmployees() {
+ return employees;
+ }
+
+ @Override
+ public int hashCode() {
+ return id;
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ return this == obj
+ || obj != null && getClass() == obj.getClass() && id == ((Team) obj).id;
+ }
+
+ @Override
+ public String toString() {
+ return "{\"Id\":\"" + id + "\",\"Name\":\"" + name + "\",\"IsScrumTeam\":" + isScrumTeam + "}";
+ }
+}
[48/52] Renamed project
Posted by mi...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/ResourceHelper.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/ResourceHelper.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/ResourceHelper.java
new file mode 100644
index 0000000..73d1218
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/ResourceHelper.java
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * 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.core.annotation.model;
+
+import java.awt.image.BufferedImage;
+import java.awt.image.WritableRaster;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import javax.imageio.ImageIO;
+
+/**
+ *
+ */
+public class ResourceHelper {
+
+ public enum Format {BMP, JPEG, PNG, GIF};
+
+ public static byte[] generateImage() {
+ return generateImage(Format.PNG);
+ }
+
+ public static byte[] generateImage(Format format) {
+ try {
+ int width = 320;
+ int height = 320;
+ BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_BINARY);
+ WritableRaster raster = image.getRaster();
+
+ int mod = format.ordinal() + 2;
+ for (int h = 0; h < height; h++) {
+ for (int w = 0; w < width; w++) {
+ if (((h / 32) + (w / 32)) % mod == 0) {
+ raster.setSample(w, h, 0, 0);
+ } else {
+ raster.setSample(w, h, 0, 1);
+ }
+ }
+ }
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
+ ImageIO.write(image, format.name(), out);
+ return out.toByteArray();
+ } catch (IOException ex) {
+ return new byte[0];
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Room.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Room.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Room.java
new file mode 100644
index 0000000..7c9e486
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Room.java
@@ -0,0 +1,89 @@
+/*
+ * Copyright 2013 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * 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.core.annotation.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
+
+/**
+ *
+ */
+@EdmEntityType(name = "Room", namespace = ModelSharedConstants.NAMESPACE_1)
+@EdmEntitySet(name = "Rooms")
+public class Room extends RefBase {
+
+ @EdmProperty
+ private Integer seats;
+ @EdmProperty
+ private Integer version;
+ @EdmNavigationProperty(name = "nr_Building", association = "BuildingRooms")
+ private Building building;
+ @EdmNavigationProperty(name = "nr_Employees")
+ private List<Employee> employees = new ArrayList<Employee>();
+
+ public Room(final int id, final String name) {
+ super(id, name);
+ }
+
+ public void setSeats(final int seats) {
+ this.seats = seats;
+ }
+
+ public int getSeats() {
+ return seats;
+ }
+
+ public void setVersion(final int version) {
+ this.version = version;
+ }
+
+ public int getVersion() {
+ return version;
+ }
+
+ public void setBuilding(final Building building) {
+ this.building = building;
+ }
+
+ public Building getBuilding() {
+ return building;
+ }
+
+ public List<Employee> getEmployees() {
+ return employees;
+ }
+
+ @Override
+ public int hashCode() {
+ return id;
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ return this == obj
+ || obj != null && getClass() == obj.getClass() && id == ((Room) obj).id;
+ }
+
+ @Override
+ public String toString() {
+ return "{\"Id\":\"" + id + "\",\"Name\":\"" + name + "\",\"Seats\":" + seats + ",\"Version\":" + version + "}";
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Team.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Team.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Team.java
new file mode 100644
index 0000000..e9b296f
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Team.java
@@ -0,0 +1,81 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ ******************************************************************************/
+package org.apache.olingo.odata2.core.annotation.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty.Multiplicity;
+import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmType;
+
+/**
+*
+*/
+@EdmEntityType(name = "Team", namespace = ModelSharedConstants.NAMESPACE_1)
+@EdmEntitySet(name = "Teams")
+public class Team extends RefBase {
+ @EdmProperty(type = EdmType.BOOLEAN)
+ private Boolean isScrumTeam;
+ @EdmNavigationProperty(name = "nt_Employees", association = "TeamEmployees", toMultiplicity = Multiplicity.MANY)
+ private List<Employee> employees = new ArrayList<Employee>();
+
+ public Team() {
+ super(-1, null);
+ }
+
+ public Team(final int id, final String name) {
+ super(id, name);
+ }
+
+ public Boolean isScrumTeam() {
+ return isScrumTeam;
+ }
+
+ public void setScrumTeam(final Boolean isScrumTeam) {
+ this.isScrumTeam = isScrumTeam;
+ }
+
+ public void addEmployee(Employee e) {
+ this.employees.add(e);
+ }
+
+ public List<Employee> getEmployees() {
+ return employees;
+ }
+
+ @Override
+ public int hashCode() {
+ return id;
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ return this == obj
+ || obj != null && getClass() == obj.getClass() && id == ((Team) obj).id;
+ }
+
+ @Override
+ public String toString() {
+ return "{\"Id\":\"" + id + "\",\"Name\":\"" + name + "\",\"IsScrumTeam\":" + isScrumTeam + "}";
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-annotation-processor/annotation-processor-webref/pom.xml
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-webref/pom.xml b/odata2-annotation-processor/annotation-processor-webref/pom.xml
new file mode 100644
index 0000000..9f31106
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-webref/pom.xml
@@ -0,0 +1,120 @@
+<?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-annotation-processor-webref-incubating</artifactId>
+ <packaging>war</packaging>
+ <name>${project.artifactId}</name>
+
+ <parent>
+ <groupId>org.apache.olingo</groupId>
+ <artifactId>olingo-odata2-annotation-processor-incubating</artifactId>
+ <version>1.1.0-SNAPSHOT</version>
+ <relativePath>..</relativePath>
+ </parent>
+
+ <properties>
+ <version.slf4j>1.7.1</version.slf4j>
+ </properties>
+
+ <build>
+ <finalName>${project.artifactId}</finalName>
+ <resources>
+ <resource>
+ <directory>src/main/version</directory>
+ <filtering>true</filtering>
+ <targetPath>../${project.build.finalName}/gen</targetPath>
+ </resource>
+ <resource>
+ <directory>src/main/resources</directory>
+ <filtering>true</filtering>
+ </resource>
+ <resource>
+ <directory>target/maven-shared-archive-resources</directory>
+ </resource>
+ </resources>
+
+ <plugins>
+ <plugin>
+ <groupId>com.sap.research</groupId>
+ <artifactId>nwcloud-maven-plugin</artifactId>
+ <version>1.0.0.RELEASE</version>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-deploy-plugin</artifactId>
+ <configuration>
+ <skip>true</skip>
+ </configuration>
+ </plugin>
+ </plugins>
+
+ </build>
+
+ <dependencies>
+ <dependency>
+ <!-- required because of auto detection of web facet 2.5 -->
+ <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>${cxf.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.olingo</groupId>
+ <artifactId>olingo-odata2-api-incubating</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.olingo</groupId>
+ <artifactId>olingo-odata2-core-incubating</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.olingo</groupId>
+ <artifactId>olingo-odata2-annotation-processor-api-incubating</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.olingo</groupId>
+ <artifactId>olingo-odata2-annotation-processor-core-incubating</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <version>${version.slf4j}</version>
+ </dependency>
+ </dependencies>
+
+ <profiles>
+ <profile>
+ <id>dev</id>
+
+ <build>
+ <defaultGoal>cargo:run</defaultGoal>
+
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.cargo</groupId>
+ <artifactId>cargo-maven2-plugin</artifactId>
+ <version>1.4.2</version>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-annotation-processor/annotation-processor-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Building.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Building.java b/odata2-annotation-processor/annotation-processor-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Building.java
new file mode 100644
index 0000000..668ac86
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Building.java
@@ -0,0 +1,97 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ ******************************************************************************/
+package org.apache.olingo.odata2.ref.annotation.model;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
+import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty.Multiplicity;
+import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmType;
+
+/**
+ *
+ */
+@EdmEntityType(name = "Building", namespace = ModelSharedConstants.NAMESPACE_1)
+@EdmEntitySet(name = "Buildings")
+public class Building {
+ @EdmKey
+ @EdmProperty(type = EdmType.INT32)
+ private int id;
+ @EdmProperty
+ private String name;
+ @EdmProperty(name = "Image", type = EdmType.BINARY)
+ private byte[] image;
+ @EdmNavigationProperty(name = "nb_Rooms", toType = Room.class,
+ association = "BuildingRooms", toMultiplicity = Multiplicity.MANY)
+ private List<Room> rooms = new ArrayList<Room>();
+
+ public String getId() {
+ return Integer.toString(id);
+ }
+
+ public void setName(final String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setImage(final byte[] byteArray) {
+ image = byteArray;
+ }
+
+ public byte[] getImage() {
+ if (image == null) {
+ return null;
+ } else {
+ return image.clone();
+ }
+ }
+
+ public void addRoom(Room room) {
+ rooms.add(room);
+ }
+
+ public List<Room> getRooms() {
+ return rooms;
+ }
+
+ @Override
+ public int hashCode() {
+ return id;
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ return this == obj
+ || obj != null && getClass() == obj.getClass() && id == ((Building) obj).id;
+ }
+
+ @Override
+ public String toString() {
+ return "{\"Id\":\"" + id + "\",\"Name\":\"" + name + "\",\"Image\":\"" + Arrays.toString(image) + "\"}";
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-annotation-processor/annotation-processor-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/City.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/City.java b/odata2-annotation-processor/annotation-processor-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/City.java
new file mode 100644
index 0000000..a4d5a56
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/City.java
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ ******************************************************************************/
+package org.apache.olingo.odata2.ref.annotation.model;
+
+import org.apache.olingo.odata2.api.annotation.edm.EdmComplexType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
+
+/**
+ *
+ */
+@EdmComplexType(name="c_City", namespace = ModelSharedConstants.NAMESPACE_1)
+public class City {
+
+ @EdmProperty
+ private String postalCode;
+ @EdmProperty
+ private String cityName;
+
+ public City(final String postalCode, final String name) {
+ this.postalCode = postalCode;
+ cityName = name;
+ }
+
+ public void setPostalCode(final String postalCode) {
+ this.postalCode = postalCode;
+ }
+
+ public String getPostalCode() {
+ return postalCode;
+ }
+
+ public void setCityName(final String cityName) {
+ this.cityName = cityName;
+ }
+
+ public String getCityName() {
+ return cityName;
+ }
+
+ @Override
+ public String toString() {
+ return String.format("%s, %s", cityName, postalCode);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-annotation-processor/annotation-processor-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Employee.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Employee.java b/odata2-annotation-processor/annotation-processor-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Employee.java
new file mode 100644
index 0000000..2204ee8
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Employee.java
@@ -0,0 +1,192 @@
+/*******************************************************************************
+ * 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.ref.annotation.model;
+
+import java.text.DateFormat;
+import java.util.Calendar;
+
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmFacets;
+import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
+import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceContent;
+import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceMimeType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmType;
+
+/**
+ *
+ */
+@EdmEntityType(name = "Employee", namespace = ModelSharedConstants.NAMESPACE_1)
+@EdmEntitySet(name = "Employees")
+public class Employee {
+ @EdmKey
+ @EdmProperty(name = "EmployeeId", type = EdmType.STRING)
+ private String employeeId;
+ @EdmProperty(name = "EmployeeName")
+ private String employeeName;
+ @EdmProperty
+ private int age;
+ @EdmNavigationProperty(name = "ne_Manager", association = "ManagerEmployees")
+ private Manager manager;
+ @EdmNavigationProperty(name = "ne_Team", association = "TeamEmployees")
+ private Team team;
+ @EdmNavigationProperty(name = "ne_Room")
+ private Room room;
+ @EdmMediaResourceMimeType
+ private String imageType;
+ @EdmMediaResourceContent
+ private byte[] image;
+ @EdmProperty(name = "ImageUrl")
+ private String imageUrl;
+ @EdmProperty(name = "EntryDate", type = EdmType.DATE_TIME,
+ facets = @EdmFacets(nullable = true))
+ private Calendar entryDate;
+ @EdmProperty(name = "Location", facets = @EdmFacets(nullable = false))
+ private Location location;
+
+ public String getId() {
+ return employeeId;
+ }
+
+ public void setEmployeeName(final String employeeName) {
+ this.employeeName = employeeName;
+ }
+
+ public String getEmployeeName() {
+ return employeeName;
+ }
+
+ public void setAge(final int age) {
+ this.age = age;
+ }
+
+ public int getAge() {
+ return age;
+ }
+
+ public void setManager(final Manager manager) {
+ this.manager = manager;
+ }
+
+ public Manager getManager() {
+ return manager;
+ }
+
+ public void setTeam(final Team team) {
+ this.team = team;
+ }
+
+ public Team getTeam() {
+ return team;
+ }
+
+ public void setRoom(final Room room) {
+ this.room = room;
+ }
+
+ public Room getRoom() {
+ return room;
+ }
+
+ public void setImageUri(final String imageUri) {
+ imageUrl = imageUri;
+ }
+
+ public String getImageUri() {
+ return imageUrl;
+ }
+
+ public void setLocation(final Location location) {
+ this.location = location;
+ }
+
+ public Location getLocation() {
+ return location;
+ }
+
+ public void setEntryDate(final Calendar date) {
+ entryDate = date;
+ }
+
+ public Calendar getEntryDate() {
+ return entryDate;
+ }
+
+ public void setImageType(final String imageType) {
+ this.imageType = imageType;
+ }
+
+ public String getImageType() {
+ return imageType;
+ }
+
+ public void setImage(final byte[] image) {
+ this.image = image;
+ }
+
+ public void setImage(final String imageUrl) {
+ image = loadImage(imageUrl);
+ }
+
+ private static byte[] loadImage(final String imageUrl) {
+ return ResourceHelper.loadAsByte(imageUrl);
+ }
+
+ public byte[] getImage() {
+ if (image == null) {
+ return null;
+ }
+ return image.clone();
+ }
+
+ @Override
+ public int hashCode() {
+ if (employeeId == null) {
+ return 0;
+ }
+ return employeeId.hashCode();
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ return this == obj
+ || obj != null && getClass() == obj.getClass() && employeeId == ((Employee) obj).employeeId;
+ }
+
+ @Override
+ public String toString() {
+ return "{\"EmployeeId\":\"" + employeeId + "\","
+ + "\"EmployeeName\":\"" + employeeName + "\","
+ + "\"ManagerId\":" + (manager == null ? "null" : "\"" + manager.getId() + "\"") + ","
+ + "\"RoomId\":" + (room == null ? "null" : "\"" + room.getId() + "\"") + ","
+ + "\"TeamId\":" + (team == null ? "null" : "\"" + team.getId() + "\"") + ","
+ + "\"Location\":"
+ + (location == null ? "null" :
+ "{\"City\":" + (location.getCity() == null ? "null" :
+ "{\"PostalCode\":\"" + location.getCity().getPostalCode() + "\","
+ + "\"CityName\":\"" + location.getCity().getCityName() + "\"}") + ","
+ + "\"Country\":\"" + location.getCountry() + "\"}") + ","
+ + "\"Age\":" + age + ","
+ + "\"EntryDate\":"
+ + (entryDate == null ? "null" : "\"" + DateFormat.getInstance().format(entryDate.getTime()) + "\"") + ","
+ + "\"ImageUrl\":\"" + imageUrl + "\"}";
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-annotation-processor/annotation-processor-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Location.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Location.java b/odata2-annotation-processor/annotation-processor-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Location.java
new file mode 100644
index 0000000..9b0785c
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Location.java
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * 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.ref.annotation.model;
+
+import org.apache.olingo.odata2.api.annotation.edm.EdmComplexType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
+
+/**
+ *
+ */
+@EdmComplexType(name = "c_Location", namespace = ModelSharedConstants.NAMESPACE_1)
+public class Location {
+ @EdmProperty
+ private String country;
+ @EdmProperty
+ private City city;
+
+ public Location(final String country, final String postalCode, final String cityName) {
+ this.country = country;
+ city = new City(postalCode, cityName);
+ }
+
+ public void setCountry(final String country) {
+ this.country = country;
+ }
+
+ public String getCountry() {
+ return country;
+ }
+
+ public void setCity(final City city) {
+ this.city = city;
+ }
+
+ public City getCity() {
+ return city;
+ }
+
+ @Override
+ public String toString() {
+ return String.format("%s, %s", country, city.toString());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-annotation-processor/annotation-processor-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Manager.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Manager.java b/odata2-annotation-processor/annotation-processor-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Manager.java
new file mode 100644
index 0000000..57e6d78
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Manager.java
@@ -0,0 +1,43 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ ******************************************************************************/
+package org.apache.olingo.odata2.ref.annotation.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty.Multiplicity;
+
+/**
+ *
+ */
+@EdmEntityType(name = "Manager", namespace = ModelSharedConstants.NAMESPACE_1)
+@EdmEntitySet(name = "Managers")
+public class Manager extends Employee {
+
+ @EdmNavigationProperty(name = "nm_Employees", association = "ManagerEmployees",
+ toMultiplicity = Multiplicity.MANY)
+ private List<Employee> employees = new ArrayList<Employee>();
+
+ public List<Employee> getEmployees() {
+ return employees;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-annotation-processor/annotation-processor-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ModelSharedConstants.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ModelSharedConstants.java b/odata2-annotation-processor/annotation-processor-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ModelSharedConstants.java
new file mode 100644
index 0000000..ab17fbb
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ModelSharedConstants.java
@@ -0,0 +1,25 @@
+/*******************************************************************************
+ * 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.ref.annotation.model;
+
+public interface ModelSharedConstants {
+
+ String NAMESPACE_1 = "RefScenario";
+ String CONTAINER_1 = "Container1";
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-annotation-processor/annotation-processor-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Photo.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Photo.java b/odata2-annotation-processor/annotation-processor-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Photo.java
new file mode 100644
index 0000000..52971cd
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Photo.java
@@ -0,0 +1,128 @@
+/*******************************************************************************
+ * 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.ref.annotation.model;
+
+import java.util.Arrays;
+
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
+import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceContent;
+import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceMimeType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceSource;
+import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmType;
+
+/**
+ *
+ */
+@EdmEntityType(name = "Photo", namespace = ModelSharedConstants.NAMESPACE_1)
+@EdmEntitySet(name = "Photos")
+public class Photo {
+ @EdmKey
+ @EdmProperty
+ private String name;
+ @EdmKey
+ @EdmProperty
+ private String type;
+ @EdmProperty
+ @EdmMediaResourceMimeType
+ private String mimeType;
+ @EdmProperty
+ @EdmMediaResourceSource
+ private String imageUrl = "http://localhost/someResource.png";
+ @EdmProperty(type = EdmType.BINARY)
+ @EdmMediaResourceContent
+ private byte[] image = ResourceHelper.generateImage();
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(final String name) {
+ this.name = name;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(final String type) {
+ this.type = type;
+ }
+
+ public String getImageUri() {
+ return imageUrl;
+ }
+
+ public void setImageUri(final String uri) {
+ imageUrl = uri;
+ }
+
+ public byte[] getImage() {
+ return image.clone();
+ }
+
+ public void setImage(final byte[] image) {
+ this.image = image;
+ }
+
+ public String getImageType() {
+ return mimeType;
+ }
+
+ public void setImageType(final String imageType) {
+ this.mimeType = imageType;
+ }
+
+ @Override
+ public int hashCode() {
+ int hash = 5;
+ hash = 83 * hash + (this.name != null ? this.name.hashCode() : 0);
+ hash = 83 * hash + (this.type != null ? this.type.hashCode() : 0);
+ return hash;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ final Photo other = (Photo) obj;
+ if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) {
+ return false;
+ }
+ if ((this.type == null) ? (other.type != null) : !this.type.equals(other.type)) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ return "{\"Name\":\"" + name + "\","
+ + "\"Type\":\"" + type + "\","
+ + "\"ImageUrl\":\"" + imageUrl + "\","
+ + "\"Image\":\"" + Arrays.toString(image) + "\","
+ + "\"MimeType\":\"" + mimeType + "\"";
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-annotation-processor/annotation-processor-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/RefBase.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/RefBase.java b/odata2-annotation-processor/annotation-processor-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/RefBase.java
new file mode 100644
index 0000000..727b8c3
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/RefBase.java
@@ -0,0 +1,78 @@
+/*******************************************************************************
+ * 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.ref.annotation.model;
+
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
+import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmType;
+
+/**
+ *
+ */
+@EdmEntityType(name="Base", namespace=ModelSharedConstants.NAMESPACE_1)
+public abstract class RefBase {
+ @EdmProperty(name="Name")
+ protected String name;
+ @EdmProperty(name="Id", type = EdmType.STRING)
+ @EdmKey
+ protected String id;
+
+ public String getName() {
+ return name;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public void setId(int id) {
+ this.id = String.valueOf(id);
+ }
+
+ @Override
+ public int hashCode() {
+ if(id == null) {
+ return -1;
+ }
+ return id.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ final RefBase other = (RefBase) obj;
+ if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) {
+ return false;
+ }
+ if ((this.id == null) ? (other.id != null) : !this.id.equals(other.id)) {
+ return false;
+ }
+ return true;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-annotation-processor/annotation-processor-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ResourceHelper.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ResourceHelper.java b/odata2-annotation-processor/annotation-processor-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ResourceHelper.java
new file mode 100644
index 0000000..3d2bb88
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ResourceHelper.java
@@ -0,0 +1,93 @@
+/*******************************************************************************
+ * 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.ref.annotation.model;
+
+import java.awt.image.BufferedImage;
+import java.awt.image.WritableRaster;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import javax.imageio.ImageIO;
+
+/**
+ *
+ */
+public class ResourceHelper {
+
+ public static byte[] loadAsByte(String resource) {
+ return load(resource, new byte[0]);
+ }
+
+ public static byte[] load(String resource, byte[] defaultResult) {
+ InputStream instream = null;
+ try {
+ instream = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource);
+ if (instream == null) {
+ return defaultResult;
+ }
+ ByteArrayOutputStream stream = new ByteArrayOutputStream();
+ int b = 0;
+ while ((b = instream.read()) != -1) {
+ stream.write(b);
+ }
+
+ return stream.toByteArray();
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ } finally {
+ if(instream != null) {
+ try {
+ instream.close();
+ } catch (IOException ex) { }
+ }
+ }
+ }
+
+ public enum Format {BMP, JPEG, PNG, GIF};
+
+ public static byte[] generateImage() {
+ return generateImage(Format.PNG);
+ }
+
+ public static byte[] generateImage(Format format) {
+ try {
+ int width = 320;
+ int height = 320;
+ BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_BINARY);
+ WritableRaster raster = image.getRaster();
+
+ int mod = format.ordinal() + 2;
+ for (int h = 0; h < height; h++) {
+ for (int w = 0; w < width; w++) {
+ if (((h / 32) + (w / 32)) % mod == 0) {
+ raster.setSample(w, h, 0, 0);
+ } else {
+ raster.setSample(w, h, 0, 1);
+ }
+ }
+ }
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
+ ImageIO.write(image, format.name(), out);
+ return out.toByteArray();
+ } catch (IOException ex) {
+ return new byte[0];
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-annotation-processor/annotation-processor-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Room.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Room.java b/odata2-annotation-processor/annotation-processor-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Room.java
new file mode 100644
index 0000000..2d9f48e
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Room.java
@@ -0,0 +1,88 @@
+/*******************************************************************************
+ * 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.ref.annotation.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
+
+/**
+ *
+ */
+@EdmEntityType(name = "Room", namespace = ModelSharedConstants.NAMESPACE_1)
+@EdmEntitySet(name = "Rooms")
+public class Room extends RefBase {
+
+ @EdmProperty
+ private Integer seats;
+ @EdmProperty
+ private Integer version;
+ @EdmNavigationProperty(name = "nr_Building", association = "BuildingRooms")
+ private Building building;
+ @EdmNavigationProperty(name = "nr_Employees")
+ private List<Employee> employees = new ArrayList<Employee>();
+
+ public void setSeats(final int seats) {
+ this.seats = seats;
+ }
+
+ public int getSeats() {
+ return seats;
+ }
+
+ public void setVersion(final int version) {
+ this.version = version;
+ }
+
+ public int getVersion() {
+ return version;
+ }
+
+ public void setBuilding(final Building building) {
+ this.building = building;
+ }
+
+ public Building getBuilding() {
+ return building;
+ }
+
+ public List<Employee> getEmployees() {
+ return employees;
+ }
+
+ @Override
+ public int hashCode() {
+ return super.hashCode();
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ return this == obj
+ || obj != null && getClass() == obj.getClass() && id == ((Room) obj).id;
+ }
+
+ @Override
+ public String toString() {
+ return "{\"Id\":\"" + id + "\",\"Name\":\"" + name + "\",\"Seats\":" + seats + ",\"Version\":" + version + "}";
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-annotation-processor/annotation-processor-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Team.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Team.java b/odata2-annotation-processor/annotation-processor-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Team.java
new file mode 100644
index 0000000..50d2ad2
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Team.java
@@ -0,0 +1,73 @@
+/*******************************************************************************
+ * 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.ref.annotation.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty.Multiplicity;
+import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmType;
+
+/**
+*
+*/
+@EdmEntityType(name = "Team", namespace = ModelSharedConstants.NAMESPACE_1)
+@EdmEntitySet(name = "Teams")
+public class Team extends RefBase {
+ @EdmProperty(type = EdmType.BOOLEAN)
+ private Boolean isScrumTeam;
+ @EdmNavigationProperty(name = "nt_Employees", association = "TeamEmployees", toMultiplicity = Multiplicity.MANY)
+ private List<Employee> employees = new ArrayList<Employee>();
+
+ public Boolean isScrumTeam() {
+ return isScrumTeam;
+ }
+
+ public void setScrumTeam(final Boolean isScrumTeam) {
+ this.isScrumTeam = isScrumTeam;
+ }
+
+ public void addEmployee(Employee e) {
+ this.employees.add(e);
+ }
+
+ public List<Employee> getEmployees() {
+ return employees;
+ }
+
+ @Override
+ public int hashCode() {
+ return super.hashCode();
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ return this == obj
+ || obj != null && getClass() == obj.getClass() && id == ((Team) obj).id;
+ }
+
+ @Override
+ public String toString() {
+ return "{\"Id\":\"" + id + "\",\"Name\":\"" + name + "\",\"IsScrumTeam\":" + isScrumTeam + "}";
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-annotation-processor/annotation-processor-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/processor/AnnotationPocServiceFactory.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/processor/AnnotationPocServiceFactory.java b/odata2-annotation-processor/annotation-processor-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/processor/AnnotationPocServiceFactory.java
new file mode 100644
index 0000000..3870119
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/processor/AnnotationPocServiceFactory.java
@@ -0,0 +1,202 @@
+/**
+ * *****************************************************************************
+ * 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.ref.annotation.processor;
+
+import java.util.Calendar;
+
+import org.apache.olingo.odata2.api.ODataCallback;
+import org.apache.olingo.odata2.api.ODataDebugCallback;
+import org.apache.olingo.odata2.api.ODataService;
+import org.apache.olingo.odata2.api.ODataServiceFactory;
+import org.apache.olingo.odata2.api.commons.HttpStatusCodes;
+import org.apache.olingo.odata2.api.ep.EntityProvider;
+import org.apache.olingo.odata2.api.exception.ODataApplicationException;
+import org.apache.olingo.odata2.api.exception.ODataException;
+import org.apache.olingo.odata2.api.processor.ODataContext;
+import org.apache.olingo.odata2.api.processor.ODataErrorCallback;
+import org.apache.olingo.odata2.api.processor.ODataErrorContext;
+import org.apache.olingo.odata2.api.processor.ODataResponse;
+import org.apache.olingo.odata2.core.annotation.data.AnnotationInMemoryDs;
+import org.apache.olingo.odata2.core.annotation.data.AnnotationValueAccess;
+import org.apache.olingo.odata2.core.annotation.data.DataStore;
+import org.apache.olingo.odata2.core.annotation.edm.AnnotationEdmProvider;
+import org.apache.olingo.odata2.core.annotation.processor.ListsProcessor;
+import org.apache.olingo.odata2.ref.annotation.model.Building;
+import org.apache.olingo.odata2.ref.annotation.model.Employee;
+import org.apache.olingo.odata2.ref.annotation.model.Location;
+import org.apache.olingo.odata2.ref.annotation.model.Manager;
+import org.apache.olingo.odata2.ref.annotation.model.Photo;
+import org.apache.olingo.odata2.ref.annotation.model.ResourceHelper;
+import org.apache.olingo.odata2.ref.annotation.model.Room;
+import org.apache.olingo.odata2.ref.annotation.model.Team;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ *
+ */
+public class AnnotationPocServiceFactory extends ODataServiceFactory {
+
+ private static boolean isInitialized = false;
+
+ @Override
+ public ODataService createService(final ODataContext context) throws ODataException {
+
+ String modelPackage = "org.apache.olingo.odata2.ref.annotation.model";
+ AnnotationEdmProvider annotationEdmProvider = new AnnotationEdmProvider(modelPackage);
+ AnnotationInMemoryDs annotationScenarioDs = new AnnotationInMemoryDs(modelPackage);
+ AnnotationValueAccess annotationValueAccess = new AnnotationValueAccess();
+
+ if (!isInitialized) {
+ initializeSampleData(annotationScenarioDs);
+ isInitialized = true;
+ }
+
+ // Edm via Annotations and ListProcessor via AnnotationDS with AnnotationsValueAccess
+ return createODataSingleProcessorService(annotationEdmProvider,
+ new ListsProcessor(annotationScenarioDs, annotationValueAccess));
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public <T extends ODataCallback> T getCallback(final Class<? extends ODataCallback> callbackInterface) {
+ return (T) (callbackInterface.isAssignableFrom(ScenarioErrorCallback.class)
+ ? new ScenarioErrorCallback() : callbackInterface.isAssignableFrom(ODataDebugCallback.class)
+ ? new ScenarioDebugCallback() : super.getCallback(callbackInterface));
+ }
+
+ /*
+ * Helper classes and methods
+ */
+
+ /**
+ *
+ */
+ private final class ScenarioDebugCallback implements ODataDebugCallback {
+
+ @Override
+ public boolean isDebugEnabled() {
+ return true;
+ }
+ }
+
+ private class ScenarioErrorCallback implements ODataErrorCallback {
+
+ private final Logger LOG = LoggerFactory.getLogger(ScenarioErrorCallback.class);
+
+ @Override
+ public ODataResponse handleError(final ODataErrorContext context) throws ODataApplicationException {
+ if (context.getHttpStatus() == HttpStatusCodes.INTERNAL_SERVER_ERROR) {
+ LOG.error("Internal Server Error", context.getException());
+ }
+
+ return EntityProvider.writeErrorDocument(context);
+ }
+
+ }
+
+ private void initializeSampleData(AnnotationInMemoryDs dataSource) throws ODataApplicationException {
+ DataStore<Team> teamDs = dataSource.getDataStore(Team.class);
+ teamDs.create(createTeam("Team Alpha", true));
+ teamDs.create(createTeam("Team Beta", false));
+ teamDs.create(createTeam("Team Gamma", false));
+ teamDs.create(createTeam("Team Omega", true));
+ teamDs.create(createTeam("Team Zeta", true));
+
+ DataStore<Building> buildingsDs = dataSource.getDataStore(Building.class);
+ Building redBuilding = createBuilding("Red Building");
+ buildingsDs.create(redBuilding);
+ Building greenBuilding = createBuilding("Green Building");
+ buildingsDs.create(greenBuilding);
+ Building blueBuilding = createBuilding("Blue Building");
+ buildingsDs.create(blueBuilding);
+ Building yellowBuilding = createBuilding("Yellow Building");
+ buildingsDs.create(yellowBuilding);
+
+ DataStore<Photo> photoDs = dataSource.getDataStore(Photo.class);
+ photoDs.create(createPhoto("Small picture", ResourceHelper.Format.GIF));
+ photoDs.create(createPhoto("Medium picture", ResourceHelper.Format.PNG));
+ photoDs.create(createPhoto("Big picture", ResourceHelper.Format.JPEG));
+ photoDs.create(createPhoto("Huge picture", ResourceHelper.Format.BMP));
+
+ DataStore<Room> roomDs = dataSource.getDataStore(Room.class);
+ roomDs.create(createRoom("Tiny red room", 5, 1, redBuilding));
+ roomDs.create(createRoom("Small red room", 20, 1, redBuilding));
+ roomDs.create(createRoom("Small green room", 20, 1, greenBuilding));
+ roomDs.create(createRoom("Big blue room", 40, 1, blueBuilding));
+ roomDs.create(createRoom("Huge blue room", 120, 1, blueBuilding));
+ roomDs.create(createRoom("Huge yellow room", 120, 1, yellowBuilding));
+
+ DataStore<Employee> employeeDataStore = dataSource.getDataStore(Employee.class);
+ employeeDataStore.create(createEmployee("first Employee",
+ new Location("Norge", "8392", "Ä"), 42, null,
+ photoDs.read().iterator().next().getImage(), photoDs.read().iterator().next().getImageType(),
+ "http://localhost/image/first.png",
+ null, teamDs.read().iterator().next(), roomDs.read().iterator().next()));
+ }
+
+ private Employee createEmployee(final String name,
+ Location location, final int age, final Calendar date,
+ final byte[] image, final String imageType, final String imageUrl,
+ Manager manager, Team team, Room room) {
+ Employee employee = new Employee();
+ employee.setEmployeeName(name);
+ employee.setLocation(location);
+ employee.setAge(age);
+ employee.setEntryDate(date);
+ employee.setImage(image);
+ employee.setImageType(imageType);
+ employee.setImageUri(imageUrl);
+ employee.setManager(manager);
+ employee.setTeam(team);
+ employee.setRoom(room);
+ return employee;
+ }
+
+ private Team createTeam(String teamName, boolean isScrumTeam) {
+ Team team = new Team();
+ team.setName(teamName);
+ team.setScrumTeam(isScrumTeam);
+ return team;
+ }
+
+ private Building createBuilding(String buildingName) {
+ Building b = new Building();
+ b.setName(buildingName);
+ return b;
+ }
+
+ private Photo createPhoto(String name, ResourceHelper.Format format) {
+ Photo p = new Photo();
+ p.setName(name);
+ p.setImageUri("http://localhost/image/" + name);
+ p.setType(format.name());
+ p.setImageType("image/" + format.name().toLowerCase());
+ p.setImage(ResourceHelper.generateImage(format));
+ return p;
+ }
+
+ private Room createRoom(String name, int seats, int version, Building building) {
+ Room r = new Room();
+ r.setName(name);
+ r.setSeats(seats);
+ r.setVersion(version);
+ r.setBuilding(building);
+
+ building.addRoom(r);
+
+ return r;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-annotation-processor/annotation-processor-webref/src/main/resources/log4j.xml
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-webref/src/main/resources/log4j.xml b/odata2-annotation-processor/annotation-processor-webref/src/main/resources/log4j.xml
new file mode 100644
index 0000000..90a4706
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-webref/src/main/resources/log4j.xml
@@ -0,0 +1,39 @@
+<?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>
+
+ <logger name="org.apache.olingo.odata2.ref" additivity="false">
+ <level value="trace" />
+ <appender-ref ref="console" />
+ </logger>
+
+ <root>
+ <priority value="error" />
+ <appender-ref ref="console" />
+ </root>
+</log4j:configuration>
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-annotation-processor/annotation-processor-webref/src/main/version/version.html
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-webref/src/main/version/version.html b/odata2-annotation-processor/annotation-processor-webref/src/main/version/version.html
new file mode 100644
index 0000000..6d76d0b
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-webref/src/main/version/version.html
@@ -0,0 +1,27 @@
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+
+-->
+
+<table border="1">
+<tr><td>name</td><td>${name}</td></tr>
+<tr><td>version</td><td>${version}</td></tr>
+<tr><td>timestamp</td><td>${timestamp}</td></tr>
+<tr><td>project.build.finalName</td><td>${project.build.finalName}</td></tr>
+</table>
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-annotation-processor/annotation-processor-webref/src/main/webapp/WEB-INF/web.xml
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-webref/src/main/webapp/WEB-INF/web.xml b/odata2-annotation-processor/annotation-processor-webref/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..5f7264c
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-webref/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,48 @@
+<?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.ref.annotations.web</display-name>
+ <welcome-file-list>
+ <welcome-file>index.jsp</welcome-file>
+ </welcome-file-list>
+
+ <servlet>
+ <servlet-name>ReferenceScenarioServlet</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.ref.annotation.processor.AnnotationPocServiceFactory</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>ReferenceScenarioServlet</servlet-name>
+ <url-pattern>/ReferenceScenario.svc/*</url-pattern>
+ </servlet-mapping>
+
+</web-app>
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-annotation-processor/annotation-processor-webref/src/main/webapp/index.jsp
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-webref/src/main/webapp/index.jsp b/odata2-annotation-processor/annotation-processor-webref/src/main/webapp/index.jsp
new file mode 100644
index 0000000..49cf364
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-webref/src/main/webapp/index.jsp
@@ -0,0 +1,116 @@
+<%@ page language="java" contentType="text/html; UTF-8" pageEncoding="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 html>
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+<title>Apache Olingo - OData2 Library</title>
+<style type="text/css">
+body { font-family: Arial, sans-serif; font-size: 13px; line-height: 18px;
+ color: blue; background-color: #ffffff; }
+a { color: blue; text-decoration: none; }
+a:focus { outline: thin dotted #4076cb; outline-offset: -1px; }
+a:hover, a:active { outline: 0; }
+a:hover { color: #404a7e; text-decoration: underline; }
+h1, h2, h3, h4, h5, h6 { margin: 9px 0; font-family: inherit; font-weight: bold;
+ line-height: 1; color: blue; }
+h1 { font-size: 36px; line-height: 40px; }
+h2 { font-size: 30px; line-height: 40px; }
+h3 { font-size: 24px; line-height: 40px; }
+h4 { font-size: 18px; line-height: 20px; }
+h5 { font-size: 14px; line-height: 20px; }
+h6 { font-size: 12px; line-height: 20px; }
+.logo { float: right; }
+ul { padding: 0; margin: 0 0 9px 25px; }
+ul ul { margin-bottom: 0; }
+li { line-height: 18px; }
+hr { margin: 18px 0;
+ border: 0; border-top: 1px solid #cccccc; border-bottom: 1px solid #ffffff; }
+table { border-collapse: collapse; border-spacing: 10px; }
+th, td { border: 1px solid; padding: 20px; }
+.code { font-family: "Courier New", monospace; font-size: 13px; line-height: 18px; }
+</style>
+</head>
+<body>
+ <h1>Apache Olingo - OData2 Library</h1>
+ <hr />
+ <h2>Reference Scenario</h2>
+ <table>
+ <tr>
+ <td valign="top">
+ <h3>Service Document and Metadata</h3>
+ <ul>
+ <li><a href="ReferenceScenario.svc?_wadl" target="_blank">wadl</a></li>
+ <li><a href="ReferenceScenario.svc/" target="_blank">service
+ document</a></li>
+ <li><a href="ReferenceScenario.svc/$metadata" target="_blank">metadata</a></li>
+ </ul>
+ <h3>EntitySets</h3>
+ <ul>
+ <li><a href="ReferenceScenario.svc/Employees" target="_blank">Employees</a></li>
+ <li><a href="ReferenceScenario.svc/Managers" target="_blank">Managers</a></li>
+ <li><a href="ReferenceScenario.svc/Buildings" target="_blank">Buildings</a></li>
+ <li><a href="ReferenceScenario.svc/Buildings/?$expand=nb_Rooms"
+ target="_blank">Buildings/?$expand=nb_Rooms</a></li>
+ <li><a href="ReferenceScenario.svc/Rooms" target="_blank">Rooms</a></li>
+ <li><a href="ReferenceScenario.svc/Rooms/?$orderby=Name" target="_blank">Rooms/?$orderby=Name</a></li>
+ <li><a href="ReferenceScenario.svc/Photos" target="_blank">Photos</a></li>
+ <li><a href="ReferenceScenario.svc/Photos/?$filter=Type%20eq%20'PNG'"
+ target="_blank">Photos/?$filter=Type eq 'PNG'</a></li>
+ </ul>
+ <h3>Entities</h3>
+ <ul>
+ <li><a href="ReferenceScenario.svc/Employees('1')" target="_blank">Employees('1')</a></li>
+ <li><a href="ReferenceScenario.svc/Managers('1')" target="_blank">Managers('1')</a></li>
+ <li><a href="ReferenceScenario.svc/Buildings(1)" target="_blank">Buildings(1)</a></li>
+ <li><a href="ReferenceScenario.svc/Buildings(1)/nb_Rooms" target="_blank">Buildings(1)/nb_Rooms</a></li>
+ <li><a href="ReferenceScenario.svc/Rooms('1')" target="_blank">Rooms('1')</a></li>
+ <li><a href="ReferenceScenario.svc/Rooms('1')/nr_Building" target="_blank">Rooms('1')/nr_Building</a></li>
+ <li><a href="ReferenceScenario.svc/Photos(Name='Small%20picture',Type='GIF')"
+ target="_blank">Photos(Name='Small%20picture',Type='GIF')</a></li>
+ <li><a href="ReferenceScenario.svc/Photos(Name='Big%20picture',Type='JPEG')/$value"
+ target="_blank">Photos(Name='Big%20picture',Type='JPEG')/$value</a></li>
+ </ul>
+ </td>
+ <td valign="top">
+
+ </td>
+ <td valign="bottom">
+ <div class="code">
+ <%
+ String version = "gen/version.html";
+ %>
+ <%
+ try {
+ %>
+ <jsp:include page='<%=version%>' />
+ <%
+ } catch (Exception e) {
+ %>
+ <p>IDE Build</p>
+ <%
+ }
+ %>
+ </div>
+ </td>
+ </tr>
+ </table>
+</body>
+</html>
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-annotation-processor/pom.xml
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/pom.xml b/odata2-annotation-processor/pom.xml
new file mode 100644
index 0000000..d763047
--- /dev/null
+++ b/odata2-annotation-processor/pom.xml
@@ -0,0 +1,30 @@
+<?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-annotation-processor-incubating</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>annotation-processor-api</module>
+ <module>annotation-processor-core</module>
+ <module>annotation-processor-webref</module>
+ </modules>
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-edm-annotation/edm-annotation-api/pom.xml
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-api/pom.xml b/odata2-edm-annotation/edm-annotation-api/pom.xml
deleted file mode 100644
index 5d697f2..0000000
--- a/odata2-edm-annotation/edm-annotation-api/pom.xml
+++ /dev/null
@@ -1,42 +0,0 @@
-<?xml version="1.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.
--->
-<project
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
- xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
- <modelVersion>4.0.0</modelVersion>
-
- <parent>
- <groupId>org.apache.olingo</groupId>
- <artifactId>olingo-odata2-edm-annotation-incubating</artifactId>
- <version>1.1.0-SNAPSHOT</version>
- <relativePath>..</relativePath>
- </parent>
-
- <artifactId>olingo-odata2-edm-annotation-api-incubating</artifactId>
- <name>${project.artifactId}</name>
-
- <dependencies>
- <dependency>
- <groupId>org.apache.olingo</groupId>
- <artifactId>olingo-odata2-api-incubating</artifactId>
- <version>${project.version}</version>
- </dependency>
- </dependencies>
-</project>
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/data/DataSource.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/data/DataSource.java b/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/data/DataSource.java
deleted file mode 100644
index 694f199..0000000
--- a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/data/DataSource.java
+++ /dev/null
@@ -1,200 +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.api.data;
-
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.olingo.odata2.api.edm.EdmEntitySet;
-import org.apache.olingo.odata2.api.edm.EdmException;
-import org.apache.olingo.odata2.api.edm.EdmFunctionImport;
-import org.apache.olingo.odata2.api.exception.ODataApplicationException;
-import org.apache.olingo.odata2.api.exception.ODataNotFoundException;
-import org.apache.olingo.odata2.api.exception.ODataNotImplementedException;
-
-/**
- * <p>This interface is intended to make it easier to implement an OData
- * service in cases where all data for each entity set can be provided as a {@link List} of objects from which all
- * properties described in the
- * Entity Data Model can be retrieved and set.</p>
- * <p>By obeying these restrictions, data-source implementations get the
- * following advantages:
- * <ul>
- * <li>All system query options can be handled centrally.</li>
- * <li>Following navigation paths must only be done step by step.</li>
- * </ul>
- * </p>
- *
- */
-public interface DataSource {
-
- /**
- * Retrieves the whole data list for the specified entity set.
- * @param entitySet the requested {@link EdmEntitySet}
- * @return the requested data list
- */
- List<?> readData(EdmEntitySet entitySet) throws ODataNotImplementedException, ODataNotFoundException, EdmException,
- ODataApplicationException;
-
- /**
- * Retrieves a single data object for the specified entity set and key.
- * @param entitySet the requested {@link EdmEntitySet}
- * @param keys the entity key as map of key names to key values
- * @return the requested data object
- */
- Object readData(EdmEntitySet entitySet, Map<String, Object> keys) throws ODataNotImplementedException,
- ODataNotFoundException, EdmException, ODataApplicationException;
-
- /**
- * <p>Retrieves data for the specified function import and key.</p>
- * <p>This method is called also for function imports that have defined in
- * their metadata an other HTTP method than <code>GET</code>.</p>
- * @param function the requested {@link EdmFunctionImport}
- * @param parameters the parameters of the function import
- * as map of parameter names to parameter values
- * @param keys the key of the returned entity set, as map of key names to key values,
- * if the return type of the function import is a collection of entities
- * (optional)
- * @return the requested data object, either a list or a single object;
- * if the function import's return type is of type <code>Binary</code>,
- * the returned object(s) must be of type {@link BinaryData}
- */
- Object readData(EdmFunctionImport function, Map<String, Object> parameters, Map<String, Object> keys)
- throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException;
-
- /**
- * <p>Retrieves related data for the specified source data, entity set, and key.</p>
- * <p>If the underlying association of the EDM is specified to have target
- * multiplicity '*' and no target key is given, this method returns a list of
- * related data, otherwise it returns a single data object.</p>
- * @param sourceEntitySet the {@link EdmEntitySet} of the source entity
- * @param sourceData the data object of the source entity
- * @param targetEntitySet the requested target {@link EdmEntitySet}
- * @param targetKeys the key of the target entity as map of key names to key values
- * (optional)
- * @return the requested releated data object, either a list or a single object
- */
- Object readRelatedData(EdmEntitySet sourceEntitySet, Object sourceData, EdmEntitySet targetEntitySet,
- Map<String, Object> targetKeys) throws ODataNotImplementedException, ODataNotFoundException, EdmException,
- ODataApplicationException;
-
- /**
- * Retrieves the binary data and the MIME type for the media resource
- * associated to the specified media-link entry.
- * @param entitySet the {@link EdmEntitySet} of the media-link entry
- * @param mediaLinkEntryData the data object of the media-link entry
- * @return the binary data and the MIME type of the media resource
- */
- BinaryData readBinaryData(EdmEntitySet entitySet, Object mediaLinkEntryData) throws ODataNotImplementedException,
- ODataNotFoundException, EdmException, ODataApplicationException;
-
- /**
- * <p>Creates and returns a new instance of the requested data-object type.</p>
- * <p>This instance must not be part of the corresponding list and should
- * have empty content, apart from the key and other mandatory properties.
- * However, intermediate objects to access complex properties must not be
- * <code>null</code>.</p>
- * @param entitySet the {@link EdmEntitySet} the object must correspond to
- * @return the new data object
- */
- Object newDataObject(EdmEntitySet entitySet) throws ODataNotImplementedException, EdmException,
- ODataApplicationException;
-
- /**
- * Writes the binary data for the media resource associated to the
- * specified media-link entry.
- * @param entitySet the {@link EdmEntitySet} of the media-link entry
- * @param mediaLinkEntryData the data object of the media-link entry
- * @param binaryData the binary data of the media resource along with
- * the MIME type of the binary data
- */
- void writeBinaryData(EdmEntitySet entitySet, Object mediaLinkEntryData, BinaryData binaryData)
- throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException;
-
- /**
- * Deletes a single data object identified by the specified entity set and key.
- * @param entitySet the {@link EdmEntitySet} of the entity to be deleted
- * @param keys the entity key as map of key names to key values
- */
- void deleteData(EdmEntitySet entitySet, Map<String, Object> keys) throws ODataNotImplementedException,
- ODataNotFoundException, EdmException, ODataApplicationException;
-
- /**
- * <p>Inserts an instance into the entity list of the specified entity set.</p>
- * <p>If {@link #newDataObject} has not set the key and other mandatory
- * properties already, this method must set them before inserting the
- * instance into the list.</p>
- * @param entitySet the {@link EdmEntitySet} the object must correspond to
- * @param data the data object of the new entity
- */
- void createData(EdmEntitySet entitySet, Object data) throws ODataNotImplementedException, EdmException,
- ODataApplicationException;
-
- /**
- * Deletes the relation from the specified source data to a target entity
- * specified by entity set and key.
- * @param sourceEntitySet the {@link EdmEntitySet} of the source entity
- * @param sourceData the data object of the source entity
- * @param targetEntitySet the {@link EdmEntitySet} of the target entity
- * @param targetKeys the key of the target entity as map of key names to key values
- * (optional)
- */
- void deleteRelation(EdmEntitySet sourceEntitySet, Object sourceData, EdmEntitySet targetEntitySet,
- Map<String, Object> targetKeys) throws ODataNotImplementedException, ODataNotFoundException, EdmException,
- ODataApplicationException;
-
- /**
- * Writes a relation from the specified source data to a target entity
- * specified by entity set and key.
- * @param sourceEntitySet the {@link EdmEntitySet} of the source entity
- * @param sourceData the data object of the source entity
- * @param targetEntitySet the {@link EdmEntitySet} of the relation target
- * @param targetKeys the key of the target entity as map of key names to key values
- */
- void writeRelation(EdmEntitySet sourceEntitySet, Object sourceData, EdmEntitySet targetEntitySet,
- Map<String, Object> targetKeys) throws ODataNotImplementedException, ODataNotFoundException, EdmException,
- ODataApplicationException;
-
- /**
- * Container to store binary data (as byte array) and the associated MIME type.
- */
- public class BinaryData {
- private final byte[] data;
- private final String mimeType;
-
- public BinaryData(final byte[] data, final String mimeType) {
- this.data = data;
- this.mimeType = mimeType;
- }
-
- public byte[] getData() {
- return data;
- }
-
- public String getMimeType() {
- return mimeType;
- }
-
- @Override
- public String toString() {
- return "data=" + Arrays.toString(data) + ", mimeType=" + mimeType;
- }
- }
-}
[45/52] Renamed project
Posted by mi...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/util/AnnotationHelper.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/util/AnnotationHelper.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/util/AnnotationHelper.java
deleted file mode 100644
index 0c81fb1..0000000
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/util/AnnotationHelper.java
+++ /dev/null
@@ -1,726 +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.core.annotation.util;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Field;
-import java.lang.reflect.ParameterizedType;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.olingo.odata2.api.annotation.edm.EdmComplexType;
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
-import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
-import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty.Multiplicity;
-import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
-import org.apache.olingo.odata2.api.edm.EdmLiteralKind;
-import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
-import org.apache.olingo.odata2.api.edm.EdmSimpleTypeException;
-import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
-import org.apache.olingo.odata2.api.edm.FullQualifiedName;
-import org.apache.olingo.odata2.api.exception.ODataException;
-import org.apache.olingo.odata2.core.exception.ODataRuntimeException;
-
-/**
- *
- */
-public class AnnotationHelper {
-
- public static final String DEFAULT_CONTAINER_NAME = "DefaultContainer";
-
- /**
- * Compare keys of both instances.
- *
- * @param firstInstance
- * @param secondInstance
- * @return
- */
- public boolean keyMatch(Object firstInstance, Object secondInstance) {
- if (firstInstance == null || secondInstance == null) {
- return false;
- } else if (firstInstance.getClass() != secondInstance.getClass()) {
- return false;
- }
-
- Map<String, Object> firstKeyFields = getValueForAnnotatedFields(firstInstance, EdmKey.class);
- Map<String, Object> secondKeyFields = getValueForAnnotatedFields(secondInstance, EdmKey.class);
-
- return keyValuesMatch(firstKeyFields, secondKeyFields);
- }
-
- /**
- * Compare keys of instance with key values in map.
- *
- * @param instance
- * @param keyName2Value
- * @return
- */
- public boolean keyMatch(Object instance, Map<String, Object> keyName2Value) {
- Map<String, Object> instanceKeyFields = getValueForAnnotatedFields(instance, EdmKey.class);
- return keyValuesMatch(instanceKeyFields, keyName2Value);
- }
-
- private boolean keyValuesMatch(Map<String, Object> firstKeyValues, Map<String, Object> secondKeyValues) {
- if (firstKeyValues.size() != secondKeyValues.size()) {
- return false;
- } else {
- Set<Map.Entry<String, Object>> entries = firstKeyValues.entrySet();
- for (Map.Entry<String, Object> entry : entries) {
- Object firstKey = entry.getValue();
- Object secondKey = secondKeyValues.get(entry.getKey());
- if (!isEqual(firstKey, secondKey)) {
- return false;
- }
- }
- return true;
- }
- }
-
- private boolean isEqual(Object firstKey, Object secondKey) {
- if (firstKey == null) {
- if (secondKey == null) {
- return true;
- } else {
- return secondKey.equals(firstKey);
- }
- } else {
- return firstKey.equals(secondKey);
- }
- }
-
- public String extractEntitTypeName(EdmNavigationProperty enp, Class<?> fallbackClass) {
- Class<?> entityTypeClass = enp.toType();
- return extractEntityTypeName(entityTypeClass == Object.class ? fallbackClass : entityTypeClass);
- }
-
- public String extractEntitTypeName(EdmNavigationProperty enp, Field field) {
- Class<?> entityTypeClass = enp.toType();
- if (entityTypeClass == Object.class) {
- Class<?> toClass = field.getType();
- return extractEntityTypeName((toClass.isArray() || Collection.class.isAssignableFrom(toClass) ?
- (Class<?>) ((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0] : toClass));
- } else {
- return extractEntityTypeName(entityTypeClass);
- }
- }
-
- /**
- * Returns <code>NULL</code> if given class is not annotated. If annotated the set entity type name is returned and if
- * no name is set the default name is generated from the simple class name.
- *
- * @param annotatedClass
- * @return
- */
- public String extractEntityTypeName(Class<?> annotatedClass) {
- return extractTypeName(annotatedClass, EdmEntityType.class);
- }
-
- public FullQualifiedName extractEntityTypeFqn(EdmEntityType type, Class<?> annotatedClass) {
- if(type.namespace().isEmpty()) {
- return new FullQualifiedName(generateNamespace(annotatedClass), extractEntityTypeName(annotatedClass));
- }
- return new FullQualifiedName(type.namespace(), extractEntityTypeName(annotatedClass));
- }
-
- public FullQualifiedName extractEntityTypeFqn(Class<?> annotatedClass) {
- EdmEntityType type = annotatedClass.getAnnotation(EdmEntityType.class);
- if(type == null) {
- return null;
- }
- return extractEntityTypeFqn(type, annotatedClass);
- }
-
- public FullQualifiedName extractComplexTypeFqn(Class<?> annotatedClass) {
- EdmComplexType type = annotatedClass.getAnnotation(EdmComplexType.class);
- if(type == null) {
- return null;
- }
- return extractComplexTypeFqn(type, annotatedClass);
- }
-
- public FullQualifiedName extractComplexTypeFqn(EdmComplexType type, Class<?> annotatedClass) {
- if(type.namespace().isEmpty()) {
- return new FullQualifiedName(generateNamespace(annotatedClass), extractComplexTypeName(annotatedClass));
- }
- return new FullQualifiedName(type.namespace(), extractComplexTypeName(annotatedClass));
- }
-
- public String extractComplexTypeName(Class<?> annotatedClass) {
- return extractTypeName(annotatedClass, EdmComplexType.class);
- }
-
- public String generateNamespace(Class<?> annotatedClass) {
- String packageName = annotatedClass.getPackage().getName();
- return packageName;
- }
-
- /**
- *
- *
- * @param <T> must be EdmEntityType or EdmComplexType annotation
- * @param annotatedClass
- * @param typeAnnotation
- * @return null if annotatedClass is not annotated or name set via annotation or generated via
- * {@link #getCanonicalName(java.lang.Class)}
- */
- private <T extends Annotation> String extractTypeName(Class<?> annotatedClass, Class<T> typeAnnotation) {
- if (annotatedClass == Object.class) {
- return null;
- }
- T type = annotatedClass.getAnnotation(typeAnnotation);
- if (type == null) {
- return null;
- }
-
- String name;
- if (typeAnnotation == EdmEntityType.class) {
- name = ((EdmEntityType) type).name();
- } else if (typeAnnotation == EdmComplexType.class) {
- name = ((EdmComplexType) type).name();
- } else {
- return null;
- }
-
- if (name.isEmpty()) {
- return getCanonicalName(annotatedClass);
- }
- return name;
- }
-
- /**
- * Get the set property name from an EdmProperty or EdmNavigationProperty annotation.
- *
- * @param field
- * @return
- */
- public String getPropertyNameFromAnnotation(Field field) {
- EdmProperty property = field.getAnnotation(EdmProperty.class);
- if (property == null) {
- EdmNavigationProperty navProperty = field.getAnnotation(EdmNavigationProperty.class);
- if (navProperty == null) {
- throw new EdmAnnotationException("Given field '" + field
- + "' has no EdmProperty or EdmNavigationProperty annotation.");
- }
- return navProperty.name();
- }
- return property.name();
- }
-
- public String getPropertyName(Field field) {
- String propertyName = getPropertyNameFromAnnotation(field);
- if (propertyName.isEmpty()) {
- propertyName = getCanonicalName(field);
- }
- return propertyName;
- }
-
- public String extractFromRoleName(EdmNavigationProperty enp, Field field) {
- return getCanonicalRole(field.getDeclaringClass());
- }
-
- public String extractToRoleName(EdmNavigationProperty enp, Field field) {
- String role = enp.toRole();
- if (role.isEmpty()) {
- role = getCanonicalRole(
- field.getType().isArray() || Collection.class.isAssignableFrom(field.getType()) ?
- (Class<?>) ((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0] : field.getType());
- }
- return role;
- }
-
- public String getCanonicalRole(Class<?> fallbackClass) {
- String toRole = extractEntityTypeName(fallbackClass);
- return "r_" + toRole;
- }
-
- public String extractRelationshipName(EdmNavigationProperty enp, Field field) {
- String relationshipName = enp.association();
- if (relationshipName.isEmpty()) {
- final String fromRole = extractFromRoleName(enp, field);
- final String toRole = extractToRoleName(enp, field);
- if (fromRole.compareTo(toRole) > 0) {
- relationshipName = toRole + "-" + fromRole;
- } else {
- relationshipName = fromRole + "-" + toRole;
- }
- }
- return relationshipName;
- }
-
- public EdmMultiplicity getMultiplicity(EdmNavigationProperty enp, Field field) {
- EdmMultiplicity multiplicity = mapMultiplicity(enp.toMultiplicity());
- final boolean isCollectionType = field.getType().isArray() || Collection.class.isAssignableFrom(field.getType());
-
- if (multiplicity == EdmMultiplicity.ONE && isCollectionType) {
- return EdmMultiplicity.MANY;
- }
- return multiplicity;
- }
-
-
- /**
- * Set key fields based on values in map.
- * If an key field is not available or <code>NULL</code> in the map
- * it will be not set as <code>NULL</code> at the instance object.
- *
- * @param instance
- * @param keys
- * @return
- */
- public <T> T setKeyFields(T instance, Map<String, Object> keys) {
- List<Field> fields = getAnnotatedFields(instance, EdmKey.class);
-
- for (Field field : fields) {
- String propertyName = getPropertyName(field);
- Object keyValue = keys.get(propertyName);
- setValueForProperty(instance, propertyName, keyValue);
- }
-
- return instance;
- }
-
- public static final class ODataAnnotationException extends ODataException {
- private static final long serialVersionUID = 1L;
-
- public ODataAnnotationException(String message) {
- super(message);
- }
- }
-
-
- public class AnnotatedNavInfo {
- private final Field fromField;
- private final Field toField;
- private final EdmNavigationProperty fromNavigation;
- private final EdmNavigationProperty toNavigation;
-
- public AnnotatedNavInfo(Field fromField, Field toField, EdmNavigationProperty fromNavigation,
- EdmNavigationProperty toNavigation) {
- this.fromField = fromField;
- this.toField = toField;
- this.fromNavigation = fromNavigation;
- this.toNavigation = toNavigation;
- }
-
- public Field getFromField() {
- return fromField;
- }
-
- public Field getToField() {
- return toField;
- }
-
- public EdmMultiplicity getFromMultiplicity() {
- return getMultiplicity(toNavigation, toField);
- }
-
- public EdmMultiplicity getToMultiplicity() {
- return getMultiplicity(fromNavigation, fromField);
- }
-
- public boolean isBiDirectional() {
- return toNavigation != null;
- }
- }
-
- public AnnotatedNavInfo getCommonNavigationInfo(Class<?> sourceClass, Class<?> targetClass) {
- List<Field> sourceFields = getAnnotatedFields(sourceClass, EdmNavigationProperty.class);
- List<Field> targetFields = getAnnotatedFields(targetClass, EdmNavigationProperty.class);
-
- // first try via association name to get full navigation information
- for (Field sourceField : sourceFields) {
- final EdmNavigationProperty sourceNav = sourceField.getAnnotation(EdmNavigationProperty.class);
- final String sourceAssociation = extractRelationshipName(sourceNav, sourceField);
- for (Field targetField : targetFields) {
- final EdmNavigationProperty targetNav = targetField.getAnnotation(EdmNavigationProperty.class);
- final String targetAssociation = extractRelationshipName(targetNav, targetField);
- if (sourceAssociation.equals(targetAssociation)) {
- return new AnnotatedNavInfo(sourceField, targetField, sourceNav, targetNav);
- }
- }
- }
-
- // if nothing was found assume none bi-directinal navigation
- String targetEntityTypeName = extractEntityTypeName(targetClass);
- for (Field sourceField : sourceFields) {
- final EdmNavigationProperty sourceNav = sourceField.getAnnotation(EdmNavigationProperty.class);
- final String navTargetEntityName = extractEntitTypeName(sourceNav, sourceField);
-
- if (navTargetEntityName.equals(targetEntityTypeName)) {
- return new AnnotatedNavInfo(sourceField, null, sourceNav, null);
- }
- }
-
- return null;
- }
-
- public Class<?> getFieldTypeForProperty(Object instance, String propertyName) throws ODataAnnotationException {
- if (instance == null) {
- return null;
- }
-
- Field field = getFieldForPropertyName(instance, propertyName, instance.getClass(), true);
- if (field == null) {
- throw new ODataAnnotationException("No field for property '" + propertyName
- + "' found at class '" + instance.getClass() + "'.");
- }
- return field.getType();
- }
-
- public Object getValueForProperty(Object instance, String propertyName) throws ODataAnnotationException {
- if (instance == null) {
- return null;
- }
-
- Field field = getFieldForPropertyName(instance, propertyName, instance.getClass(), true);
- if (field == null) {
- throw new ODataAnnotationException("No field for property '" + propertyName
- + "' found at class '" + instance.getClass() + "'.");
- }
- return getFieldValue(instance, field);
- }
-
- public void setValueForProperty(Object instance, String propertyName, Object propertyValue) {
- if (instance != null) {
- Field field = getFieldForPropertyName(instance, propertyName, instance.getClass(), true);
- if (field != null) {
- setFieldValue(instance, field, propertyValue);
- }
- }
- }
-
- private Field getFieldForPropertyName(Object instance, String propertyName,
- Class<?> resultClass, boolean inherited) {
- if (instance == null) {
- return null;
- }
-
- Field[] fields = resultClass.getDeclaredFields();
- for (Field field : fields) {
- EdmProperty property = field.getAnnotation(EdmProperty.class);
- if (property != null) {
- if (property.name().isEmpty() && getCanonicalName(field).equals(propertyName)) {
- return field;
- } else if (property.name().equals(propertyName)) {
- return field;
- }
- }
- }
-
- Class<?> superClass = resultClass.getSuperclass();
- if (inherited && superClass != Object.class) {
- return getFieldForPropertyName(instance, propertyName, superClass, true);
- }
-
- return null;
- }
-
- public Object getValueForField(Object instance, String fieldName, Class<? extends Annotation> annotation) {
- if (instance == null) {
- return null;
- }
- return getValueForField(instance, fieldName, instance.getClass(), annotation, true);
- }
-
- public Object getValueForField(Object instance, Class<? extends Annotation> annotation) {
- if (instance == null) {
- return null;
- }
- return getValueForField(instance, instance.getClass(), annotation, true);
- }
-
- private Object getValueForField(Object instance, Class<?> resultClass,
- Class<? extends Annotation> annotation, boolean inherited) {
- return getValueForField(instance, null, resultClass, annotation, inherited);
- }
-
- public Map<String, Object> getValueForAnnotatedFields(Object instance,
- Class<? extends Annotation> annotation) {
- return getValueForAnnotatedFields(instance, instance.getClass(), annotation, true);
- }
-
- private Map<String, Object> getValueForAnnotatedFields(Object instance, Class<?> resultClass,
- Class<? extends Annotation> annotation, boolean inherited) {
- if (instance == null) {
- return null;
- }
-
- Field[] fields = resultClass.getDeclaredFields();
- Map<String, Object> fieldName2Value = new HashMap<String, Object>();
-
- for (Field field : fields) {
- if (field.getAnnotation(annotation) != null) {
- Object value = getFieldValue(instance, field);
- final EdmProperty property = field.getAnnotation(EdmProperty.class);
- final String name = property == null || property.name().isEmpty() ? field.getName() : property.name();
- fieldName2Value.put(name, value);
- }
- }
-
- Class<?> superClass = resultClass.getSuperclass();
- if (inherited && superClass != Object.class) {
- Map<String, Object> tmp = getValueForAnnotatedFields(instance, superClass, annotation, true);
- fieldName2Value.putAll(tmp);
- }
-
- return fieldName2Value;
- }
-
- public void setValueForAnnotatedField(Object instance, Class<? extends Annotation> annotation, Object value)
- throws ODataAnnotationException {
- List<Field> fields = getAnnotatedFields(instance, annotation);
-
- if(fields.isEmpty()) {
- throw new ODataAnnotationException("No field found for annotation '" + annotation
- + "' on instance '" + instance + "'.");
- } else if(fields.size() > 1) {
- throw new ODataAnnotationException("More then one field found for annotation '" + annotation
- + "' on instance '" + instance + "'.");
- }
-
- setFieldValue(instance, fields.get(0), value);
- }
-
- public void setValuesToAnnotatedFields(Object instance,
- Class<? extends Annotation> annotation, Map<String, Object> fieldName2Value) {
- List<Field> fields = getAnnotatedFields(instance, annotation);
-
- // XXX: refactore
- for (Field field : fields) {
- final String canonicalName = getCanonicalName(field);
- if (fieldName2Value.containsKey(canonicalName)) {
- Object value = fieldName2Value.get(canonicalName);
- setFieldValue(instance, field, value);
- }
- }
- }
-
- public List<Field> getAnnotatedFields(Object instance, Class<? extends Annotation> annotation) {
- if (instance == null) {
- return null;
- }
- return getAnnotatedFields(instance.getClass(), annotation, true);
- }
-
- public List<Field> getAnnotatedFields(Class<?> fieldClass, Class<? extends Annotation> annotation) {
- return getAnnotatedFields(fieldClass, annotation, true);
- }
-
- /**
- *
- * @param instance
- * @param resultClass
- * @param annotation
- * @param inherited
- * @return
- */
- private List<Field> getAnnotatedFields(Class<?> resultClass,
- Class<? extends Annotation> annotation, boolean inherited) {
- if (resultClass == null) {
- return null;
- }
-
- Field[] fields = resultClass.getDeclaredFields();
- List<Field> annotatedFields = new ArrayList<Field>();
-
- for (Field field : fields) {
- if (field.getAnnotation(annotation) != null) {
- annotatedFields.add(field);
- }
- }
-
- Class<?> superClass = resultClass.getSuperclass();
- if (inherited && superClass != Object.class) {
- List<Field> tmp = getAnnotatedFields(superClass, annotation, true);
- annotatedFields.addAll(tmp);
- }
-
- return annotatedFields;
- }
-
- private Object getValueForField(Object instance, String fieldName, Class<?> resultClass,
- Class<? extends Annotation> annotation, boolean inherited) {
- if (instance == null) {
- return null;
- }
-
- Field[] fields = resultClass.getDeclaredFields();
- for (Field field : fields) {
- if (field.getAnnotation(annotation) != null
- && (fieldName == null || field.getName().equals(fieldName))) {
- return getFieldValue(instance, field);
- }
- }
-
- Class<?> superClass = resultClass.getSuperclass();
- if (inherited && superClass != Object.class) {
- return getValueForField(instance, fieldName, superClass, annotation, true);
- }
-
- return null;
- }
-
- private Object getFieldValue(Object instance, Field field) {
- try {
- boolean access = field.isAccessible();
- field.setAccessible(true);
- Object value = field.get(instance);
- field.setAccessible(access);
- return value;
- } catch (IllegalArgumentException ex) { // should never happen
- throw new ODataRuntimeException(ex);
- } catch (IllegalAccessException ex) { // should never happen
- throw new ODataRuntimeException(ex);
- }
- }
-
- private void setFieldValue(Object instance, Field field, Object value) {
- try {
- Object usedValue = value;
- if (value != null
- && field.getType() != value.getClass()
- && value.getClass() == String.class) {
- usedValue = convert(field, (String) value);
- }
- boolean access = field.isAccessible();
- field.setAccessible(true);
- field.set(instance, usedValue);
- field.setAccessible(access);
- } catch (IllegalArgumentException ex) { // should never happen
- throw new ODataRuntimeException(ex);
- } catch (IllegalAccessException ex) { // should never happen
- throw new ODataRuntimeException(ex);
- }
- }
-
- public Object convert(Field field, String propertyValue) {
- Class<?> fieldClass = field.getType();
- try {
- EdmProperty property = field.getAnnotation(EdmProperty.class);
- EdmSimpleTypeKind type = mapTypeKind(property.type());
- return type.getEdmSimpleTypeInstance().valueOfString(propertyValue,
- EdmLiteralKind.DEFAULT, null, fieldClass);
- } catch (EdmSimpleTypeException ex) {
- throw new ODataRuntimeException("Conversion failed for string property with error: "
- + ex.getMessage(), ex);
- }
- }
-
- public boolean isEdmAnnotated(Object object) {
- if (object == null) {
- return false;
- }
- return isEdmAnnotated(object.getClass());
- }
-
- public boolean isEdmTypeAnnotated(Class<?> clazz) {
- boolean isComplexEntity = clazz.getAnnotation(EdmComplexType.class) != null;
- boolean isEntity = clazz.getAnnotation(EdmEntityType.class) != null;
- return isComplexEntity || isEntity;
- }
-
- public boolean isEdmAnnotated(Class<?> clazz) {
- if (clazz == null) {
- return false;
- } else {
- final boolean isEntity = null != clazz.getAnnotation(EdmEntityType.class);
- final boolean isEntitySet = null != clazz.getAnnotation(EdmEntitySet.class);
- final boolean isComplexEntity = null != clazz.getAnnotation(EdmComplexType.class);
- return isEntity || isComplexEntity || isEntitySet;
- }
- }
-
- public String getCanonicalName(Field field) {
- return firstCharToUpperCase(field.getName());
- }
-
- public String getCanonicalName(Class<?> clazz) {
- return firstCharToUpperCase(clazz.getSimpleName());
- }
-
- private String firstCharToUpperCase(String content) {
- if (content == null || content.isEmpty()) {
- return content;
- }
- return content.substring(0, 1).toUpperCase(Locale.ENGLISH) + content.substring(1);
- }
-
- public EdmSimpleTypeKind mapTypeKind(org.apache.olingo.odata2.api.annotation.edm.EdmType type) {
- switch (type) {
- case BINARY: return EdmSimpleTypeKind.Binary;
- case BOOLEAN: return EdmSimpleTypeKind.Boolean;
- case BYTE: return EdmSimpleTypeKind.Byte;
- case COMPLEX: return EdmSimpleTypeKind.Null;
- case DATE_TIME: return EdmSimpleTypeKind.DateTime;
- case DATE_TIME_OFFSET: return EdmSimpleTypeKind.DateTimeOffset;
- case DECIMAL: return EdmSimpleTypeKind.Decimal;
- case DOUBLE: return EdmSimpleTypeKind.Double;
- case GUID: return EdmSimpleTypeKind.Guid;
- case INT16: return EdmSimpleTypeKind.Int16;
- case INT32: return EdmSimpleTypeKind.Int32;
- case INT64: return EdmSimpleTypeKind.Int64;
- case NULL: return EdmSimpleTypeKind.Null;
- case SBYTE: return EdmSimpleTypeKind.SByte;
- case SINGLE: return EdmSimpleTypeKind.Single;
- case STRING: return EdmSimpleTypeKind.String;
- case TIME: return EdmSimpleTypeKind.Time;
- default: throw new ODataRuntimeException("Unknown type '" + type
- + "' for mapping to EdmSimpleTypeKind.");
- }
- }
-
- public EdmMultiplicity mapMultiplicity(Multiplicity multiplicity) {
- switch (multiplicity) {
- case ZERO_OR_ONE: return EdmMultiplicity.ZERO_TO_ONE;
- case ONE: return EdmMultiplicity.ONE;
- case MANY: return EdmMultiplicity.MANY;
- default: throw new ODataRuntimeException("Unknown type '" + multiplicity + "' for mapping to EdmMultiplicity.");
- }
- }
-
- /**
- *
- */
- private static class EdmAnnotationException extends RuntimeException {
-
- private static final long serialVersionUID = 42L;
-
- public EdmAnnotationException(String message) {
- super(message);
- }
- }
-
- public String getCanonicalNamespace(Class<?> aClass) {
- return generateNamespace(aClass);
- }
-
- public String extractContainerName(Class<?> aClass) {
- EdmEntitySet entitySet = aClass.getAnnotation(EdmEntitySet.class);
- if(entitySet != null) {
- String containerName = entitySet.container();
- if(!containerName.isEmpty()) {
- return containerName;
- }
- }
- return DEFAULT_CONTAINER_NAME;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/util/ClassHelper.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/util/ClassHelper.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/util/ClassHelper.java
deleted file mode 100644
index 5e9fcdb..0000000
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/util/ClassHelper.java
+++ /dev/null
@@ -1,105 +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.core.annotation.util;
-
-import java.io.File;
-import java.io.FileFilter;
-import java.io.FilenameFilter;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- *
- */
-public class ClassHelper {
-
- private static final File[] EMPTY_FILE_ARRAY = new File[0];
-
- private static final FilenameFilter CLASSFILE_FILTER = new FilenameFilter() {
- @Override
- public boolean accept(File dir, String name) {
- return name.endsWith(CLASSFILE_ENDING);
- }
- public static final String CLASSFILE_ENDING = ".class";
- };
-
- private static final FileFilter FOLDER_FILTER = new FileFilter() {
- @Override
- public boolean accept(File pathname) {
- return pathname.isDirectory();
- }
- };
-
- public static final List<Class<?>> loadClasses(String packageToScan, ClassValidator cv) {
- return loadClasses(packageToScan, CLASSFILE_FILTER, cv);
- }
-
-
- public static final List<Class<?>> loadClasses(String packageToScan, FilenameFilter ff, ClassValidator cv) {
- final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
- String folderToScan = packageToScan.replace(".", "/");
- URL url = classLoader.getResource(folderToScan);
- if(url == null) {
- throw new IllegalArgumentException("No folder to scan found for package '" + packageToScan + "'.");
- }
- File folder = new File(url.getFile());
- File[] classFiles = folder.listFiles(ff);
- if(classFiles == null) {
- classFiles = EMPTY_FILE_ARRAY;
- }
-
- List<Class<?>> annotatedClasses = new ArrayList<Class<?>>(classFiles.length);
- for (File file : classFiles) {
- String name = file.getName();
- String fqn = packageToScan + "." + name.substring(0, name.length() - 6);
- try {
- Class<?> c = classLoader.loadClass(fqn);
- if (cv.isClassValid(c)) {
- annotatedClasses.add(c);
- }
- } catch (ClassNotFoundException ex) {
- throw new IllegalArgumentException("Exception during class loading of class '" + fqn +
- "' with message '" + ex.getMessage() + "'.");
- }
- }
-
- // recursive search
- File[] subfolders = listSubFolder(folder);
- for (File file : subfolders) {
- List<Class<?>> subFolderClazzes = loadClasses(packageToScan + "." + file.getName(), ff, cv);
- annotatedClasses.addAll(subFolderClazzes);
- }
- //
-
- return annotatedClasses;
- }
-
- private static File[] listSubFolder(File folder) {
- File[] subfolders = folder.listFiles(FOLDER_FILTER);
- if(subfolders == null) {
- return EMPTY_FILE_ARRAY;
- }
- return subfolders;
- }
-
- public interface ClassValidator {
- boolean isClassValid(Class<?> c);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/data/AnnotationsInMemoryDsTest.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/data/AnnotationsInMemoryDsTest.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/data/AnnotationsInMemoryDsTest.java
deleted file mode 100644
index 04dbefc..0000000
--- a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/data/AnnotationsInMemoryDsTest.java
+++ /dev/null
@@ -1,190 +0,0 @@
-/*
- * Copyright 2013 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * 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.core.annotation.data;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.olingo.odata2.api.edm.EdmEntitySet;
-import org.apache.olingo.odata2.api.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.edm.FullQualifiedName;
-import org.apache.olingo.odata2.api.edm.provider.EntitySet;
-import org.apache.olingo.odata2.api.exception.ODataException;
-import org.apache.olingo.odata2.core.annotation.edm.AnnotationEdmProvider;
-import org.apache.olingo.odata2.core.annotation.model.Building;
-import org.apache.olingo.odata2.core.annotation.model.ModelSharedConstants;
-import org.apache.olingo.odata2.core.annotation.model.Photo;
-import org.apache.olingo.odata2.core.annotation.util.AnnotationHelper;
-import org.junit.Assert;
-import org.junit.Test;
-import org.mockito.Mockito;
-
-/**
- *
- */
-public class AnnotationsInMemoryDsTest {
-
- private final AnnotationInMemoryDs datasource;
- private AnnotationEdmProvider edmProvider;
- private static final String DEFAULT_CONTAINER = ModelSharedConstants.CONTAINER_1;
-
- public AnnotationsInMemoryDsTest() {
- datasource = new AnnotationInMemoryDs(Building.class.getPackage().getName(), false);
- edmProvider = new AnnotationEdmProvider(Building.class.getPackage().getName());
- }
-
- @Test
- public void createSimpleEntity() throws Exception {
- EdmEntitySet edmEntitySet = createMockedEdmEntitySet("Buildings");
-
- Building building = new Building();
- building.setName("Common Building");
- datasource.createData(edmEntitySet, building);
-
- Map<String, Object> keys = new HashMap<String, Object>();
- keys.put("Id", "1");
-
- Building read = (Building) datasource.readData(edmEntitySet, keys);
- Assert.assertEquals("Common Building", read.getName());
- Assert.assertEquals("1", read.getId());
- }
-
-
- @Test
- public void createSimpleEntityWithOwnKey() throws Exception {
- EdmEntitySet edmEntitySet = createMockedEdmEntitySet("Buildings");
-
- Building building = new Building();
- building.setName("Common Building");
- AnnotationHelper ah = new AnnotationHelper();
- ah.setValueForProperty(building, "Id", "42");
- datasource.createData(edmEntitySet, building);
-
- Map<String, Object> keys = new HashMap<String, Object>();
- keys.put("Id", "42");
-
- Building read = (Building) datasource.readData(edmEntitySet, keys);
- Assert.assertEquals("Common Building", read.getName());
- Assert.assertEquals("42", read.getId());
- }
-
- @Test
- public void createSimpleEntityWithDuplicateKey() throws Exception {
- EdmEntitySet edmEntitySet = createMockedEdmEntitySet("Buildings");
- AnnotationHelper ah = new AnnotationHelper();
-
- Building building = new Building();
- building.setName("Common Building");
- ah.setValueForProperty(building, "Id", "42");
- datasource.createData(edmEntitySet, building);
- //
- Building buildingDuplicate = new Building();
- buildingDuplicate.setName("Duplicate Building");
- ah.setValueForProperty(buildingDuplicate, "Id", "42");
- datasource.createData(edmEntitySet, buildingDuplicate);
-
- Map<String, Object> keys42 = new HashMap<String, Object>();
- keys42.put("Id", "42");
- Building read42 = (Building) datasource.readData(edmEntitySet, keys42);
- Assert.assertEquals("Common Building", read42.getName());
- Assert.assertEquals("42", read42.getId());
-
- Map<String, Object> keys = new HashMap<String, Object>();
- keys.put("Id", "1");
- Building read = (Building) datasource.readData(edmEntitySet, keys);
- Assert.assertEquals("Duplicate Building", read.getName());
- Assert.assertEquals("1", read.getId());
-}
-
-
- @Test
- public void createEntityTwoKeys() throws Exception {
- EdmEntitySet edmEntitySet = createMockedEdmEntitySet("Photos");
-
- Photo photo = new Photo();
- photo.setName("BigPicture");
- photo.setType("PNG");
- photo.setImageUri("https://localhost/image.png");
- photo.setImageType("image/png");
- datasource.createData(edmEntitySet, photo);
-
- Map<String, Object> keys = new HashMap<String, Object>();
- keys.put("ImageFormat", "PNG");
- keys.put("Name", "BigPicture");
-
- Photo read = (Photo) datasource.readData(edmEntitySet, keys);
- Assert.assertEquals("BigPicture", read.getName());
- Assert.assertEquals("PNG", read.getType());
- Assert.assertEquals("image/png", read.getImageType());
- Assert.assertEquals("https://localhost/image.png", read.getImageUri());
- }
-
- @Test
- // @Ignore("Rethink update method")
- public void createAndUpdateEntityTwoKeys() throws Exception {
- EdmEntitySet edmEntitySet = createMockedEdmEntitySet("Photos");
-
- Photo photo = new Photo();
- final String nameKeyValue = "BigPicture";
- final String typeKeyValue = "PNG";
- photo.setName(nameKeyValue);
- photo.setType(typeKeyValue);
- photo.setImageUri("https://localhost/image.png");
- photo.setImageType("image/png");
- datasource.createData(edmEntitySet, photo);
-
- Map<String, Object> keys = new HashMap<String, Object>();
- keys.put("Name", "BigPicture");
- keys.put("ImageFormat", "PNG");
-
- Photo read = (Photo) datasource.readData(edmEntitySet, keys);
- Assert.assertEquals("BigPicture", read.getName());
- Assert.assertEquals("PNG", read.getType());
- Assert.assertEquals("image/png", read.getImageType());
- Assert.assertEquals("https://localhost/image.png", read.getImageUri());
-
- // update
- Photo updatedPhoto = new Photo();
- updatedPhoto.setName(nameKeyValue);
- updatedPhoto.setType(typeKeyValue);
- updatedPhoto.setImageUri("https://localhost/image.jpg");
- updatedPhoto.setImageType("image/jpg");
- datasource.updateData(edmEntitySet, updatedPhoto);
-
- Map<String, Object> updatedKeys = new HashMap<String, Object>();
- updatedKeys.put("Name", nameKeyValue);
- updatedKeys.put("ImageFormat", typeKeyValue);
-
- Photo readUpdated = (Photo) datasource.readData(edmEntitySet, updatedKeys);
- Assert.assertEquals("BigPicture", readUpdated.getName());
- Assert.assertEquals("PNG", readUpdated.getType());
- Assert.assertEquals("image/jpg", readUpdated.getImageType());
- Assert.assertEquals("https://localhost/image.jpg", readUpdated.getImageUri());
- }
-
- private EdmEntitySet createMockedEdmEntitySet(String entitySetName) throws ODataException {
- EntitySet entitySet = edmProvider.getEntitySet(DEFAULT_CONTAINER, entitySetName);
- FullQualifiedName entityType = entitySet.getEntityType();
-
- EdmEntitySet edmEntitySet = Mockito.mock(EdmEntitySet.class);
- Mockito.when(edmEntitySet.getName()).thenReturn(entitySetName);
- EdmEntityType edmEntityType = Mockito.mock(EdmEntityType.class);
- Mockito.when(edmEntitySet.getEntityType()).thenReturn(edmEntityType);
- Mockito.when(edmEntityType.getName()).thenReturn(entityType.getName());
-
- return edmEntitySet;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProviderTest.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProviderTest.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProviderTest.java
deleted file mode 100644
index 494a090..0000000
--- a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProviderTest.java
+++ /dev/null
@@ -1,463 +0,0 @@
-/*
- * Copyright 2013 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * 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.core.annotation.edm;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-
-import org.apache.olingo.odata2.api.annotation.edm.EdmComplexType;
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
-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.ComplexType;
-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.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.Schema;
-import org.apache.olingo.odata2.api.exception.ODataException;
-import org.apache.olingo.odata2.core.annotation.model.Building;
-import org.apache.olingo.odata2.core.annotation.model.City;
-import org.apache.olingo.odata2.core.annotation.model.Employee;
-import org.apache.olingo.odata2.core.annotation.model.Location;
-import org.apache.olingo.odata2.core.annotation.model.Manager;
-import org.apache.olingo.odata2.core.annotation.model.ModelSharedConstants;
-import org.apache.olingo.odata2.core.annotation.model.Photo;
-import org.apache.olingo.odata2.core.annotation.model.RefBase;
-import org.apache.olingo.odata2.core.annotation.model.Room;
-import org.apache.olingo.odata2.core.annotation.model.Team;
-import org.junit.Test;
-
-/**
- *
- */
-public class AnnotationEdmProviderTest {
-
- @EdmEntityType
- @EdmEntitySet
- private static final class GeneratedNamesTestClass {}
-
- @EdmComplexType
- private static final class GeneratedNamesComplexTestClass {}
-
- @EdmEntityType(namespace="MyTestNamespace")
- @EdmEntitySet(container="MyTestContainer")
- private static final class DefinedNamesTestClass {}
-
- private final AnnotationEdmProvider aep;
- private final Collection<Class<?>> annotatedClasses = new ArrayList<Class<?>>();
-
- public AnnotationEdmProviderTest() {
- annotatedClasses.add(RefBase.class);
- annotatedClasses.add(Building.class);
- annotatedClasses.add(City.class);
- annotatedClasses.add(Employee.class);
- annotatedClasses.add(Location.class);
- annotatedClasses.add(Manager.class);
- annotatedClasses.add(Photo.class);
- annotatedClasses.add(Room.class);
- annotatedClasses.add(Team.class);
-
- aep = new AnnotationEdmProvider(annotatedClasses);
- }
-
- @Test
- public void defaultNamespaceGeneration() throws ODataException {
- Collection<Class<?>> localAnnotatedClasses = new ArrayList<Class<?>>();
- localAnnotatedClasses.add(GeneratedNamesTestClass.class);
- AnnotationEdmProvider localAep = new AnnotationEdmProvider(localAnnotatedClasses);
- // validate
- EntityType testType = localAep.getEntityType(new FullQualifiedName(
- GeneratedNamesTestClass.class.getPackage().getName(),
- GeneratedNamesTestClass.class.getSimpleName()));
- assertNotNull("Requested entity not found.", testType);
- assertEquals("GeneratedNamesTestClass", testType.getName());
- assertNull("This should not have a base type", testType.getBaseType());
- }
-
- @Test
- public void defaultNamespaceGenerationComplexType() throws ODataException {
- Collection<Class<?>> localAnnotatedClasses = new ArrayList<Class<?>>();
- localAnnotatedClasses.add(GeneratedNamesComplexTestClass.class);
- AnnotationEdmProvider localAep = new AnnotationEdmProvider(localAnnotatedClasses);
- // validate
- ComplexType testType = localAep.getComplexType(new FullQualifiedName(
- GeneratedNamesComplexTestClass.class.getPackage().getName(),
- GeneratedNamesComplexTestClass.class.getSimpleName()));
- assertNotNull("Requested entity not found.", testType);
- assertEquals("GeneratedNamesComplexTestClass", testType.getName());
- assertNull("This should not have a base type", testType.getBaseType());
- }
-
- @Test
- public void defaultContainerNameGeneration() throws ODataException {
- @SuppressWarnings({ "unchecked", "rawtypes" })
- AnnotationEdmProvider localAep =
- new AnnotationEdmProvider((Collection) Arrays.asList(GeneratedNamesTestClass.class));
-
- EntityContainerInfo containerInfo = localAep.getEntityContainerInfo(null);
- assertNotNull(containerInfo);
- assertEquals("DefaultContainer", containerInfo.getName());
- }
-
-
- @Test
- public void defaultNamespaceDefined() throws ODataException {
- Collection<Class<?>> localAnnotatedClasses = new ArrayList<Class<?>>();
- localAnnotatedClasses.add(DefinedNamesTestClass.class);
- AnnotationEdmProvider localAep = new AnnotationEdmProvider(localAnnotatedClasses);
- // validate
- EntityType testClass = localAep.getEntityType(new FullQualifiedName("MyTestNamespace",
- DefinedNamesTestClass.class.getSimpleName()));
- assertNotNull("Requested entity not found.", testClass);
- assertEquals("DefinedNamesTestClass", testClass.getName());
- assertNull("This should not have a base type", testClass.getBaseType());
- }
-
- @Test
- public void defaultContainerNameDefined() throws ODataException {
- @SuppressWarnings({ "unchecked", "rawtypes" })
- AnnotationEdmProvider localAep = new AnnotationEdmProvider((Collection) Arrays.asList(DefinedNamesTestClass.class));
-
- EntityContainerInfo containerInfo = localAep.getEntityContainerInfo(null);
- assertNotNull(containerInfo);
- assertEquals("MyTestContainer", containerInfo.getName());
- }
-
- @Test
- public void loadAnnotatedClassesFromPackage() throws Exception {
- AnnotationEdmProvider localAep = new AnnotationEdmProvider("org.apache.olingo.odata2.core.annotation.model");
-
- // validate employee
- EntityType employee = localAep.getEntityType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "Employee"));
- assertEquals("Employee", employee.getName());
- final List<PropertyRef> employeeKeys = employee.getKey().getKeys();
- assertEquals(1, employeeKeys.size());
- assertEquals("EmployeeId", employeeKeys.get(0).getName());
- assertEquals(6, employee.getProperties().size());
- assertEquals(3, employee.getNavigationProperties().size());
-
- List<Schema> schemas = localAep.getSchemas();
- assertEquals(1, schemas.size());
- EntityContainerInfo info = localAep.getEntityContainerInfo(ModelSharedConstants.CONTAINER_1);
- assertTrue(info.isDefaultEntityContainer());
- }
-
- @Test
- public void annotationProviderBasic() throws Exception {
- assertNotNull(aep);
-
- List<Schema> schemas = aep.getSchemas();
- assertEquals(1, schemas.size());
- EntityContainerInfo info = aep.getEntityContainerInfo(ModelSharedConstants.CONTAINER_1);
- assertTrue(info.isDefaultEntityContainer());
-
- FunctionImport funImp = aep.getFunctionImport(ModelSharedConstants.CONTAINER_1, "NoImport");
- assertNull(funImp);
-
- final FullQualifiedName associationFqn = new FullQualifiedName(
- ModelSharedConstants.NAMESPACE_1, "NoAssociation");
- Association noAssociation = aep.getAssociation(associationFqn);
- assertNull(noAssociation);
-
- AssociationSet noAssociationSet = aep.getAssociationSet(
- ModelSharedConstants.CONTAINER_1, associationFqn, "NoSrc", "NoSrcEntity");
- assertNull(noAssociationSet);
-
- AssociationSet asBuildingRooms = aep.getAssociationSet(
- ModelSharedConstants.CONTAINER_1, defaultFqn("BuildingRooms"), "Buildings", "r_Building");
- assertNotNull(asBuildingRooms);
- assertEquals("Buildings", asBuildingRooms.getEnd1().getEntitySet());
- assertEquals("r_Building", asBuildingRooms.getEnd1().getRole());
- assertEquals("Rooms", asBuildingRooms.getEnd2().getEntitySet());
- assertEquals("r_Room", asBuildingRooms.getEnd2().getRole());
- }
-
- @Test
- public void annotationProviderGetDefaultContainer() throws Exception {
- assertNotNull(aep);
-
- List<Schema> schemas = aep.getSchemas();
- assertEquals(1, schemas.size());
- EntityContainerInfo info = aep.getEntityContainerInfo(null);
- assertTrue(info.isDefaultEntityContainer());
- assertEquals(ModelSharedConstants.CONTAINER_1, info.getName());
- }
-
- @Test
- public void schemaBasic() throws Exception {
- assertNotNull(aep);
-
- List<Schema> schemas = aep.getSchemas();
- assertEquals(1, schemas.size());
-
- Schema schema = schemas.get(0);
- List<EntityContainer> containers = schema.getEntityContainers();
- assertEquals(1, containers.size());
- EntityContainer container = containers.get(0);
- assertEquals(ModelSharedConstants.CONTAINER_1, container.getName());
- final List<EntitySet> entitySets = container.getEntitySets();
- assertEquals(6, entitySets.size());
-
- List<Association> associations = schema.getAssociations();
- assertEquals(4, associations.size());
- for (Association association : associations) {
- assertNotNull(association.getName());
- validateAssociation(association);
- }
- }
-
- private FullQualifiedName defaultFqn(String name) {
- return new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, name);
- }
-
- private void validateAssociation(Association association) {
- String name = association.getName();
- if(name.equals("r_Employee-r_Room")) {
- validateAssociation(association,
- "r_Room", EdmMultiplicity.ONE, defaultFqn("Room"),
- "r_Employee", EdmMultiplicity.MANY, defaultFqn("Employee"));
- } else if(name.equals("BuildingRooms")) {
- validateAssociation(association,
- "r_Building", EdmMultiplicity.ONE, defaultFqn("Building"),
- "r_Room", EdmMultiplicity.MANY, defaultFqn("Room"));
- } else if(name.equals("ManagerEmployees")) {
- validateAssociation(association,
- "r_Manager", EdmMultiplicity.ONE, defaultFqn("Manager"),
- "r_Employee", EdmMultiplicity.MANY, defaultFqn("Employee"));
- } else if(name.equals("TeamEmployees")) {
- validateAssociation(association,
- "r_Team", EdmMultiplicity.ONE, defaultFqn("Team"),
- "r_Employee", EdmMultiplicity.MANY, defaultFqn("Employee"));
- } else {
- fail("Got unknown association to validate with name '" + name + "'.");
- }
- }
-
- private void validateAssociation(Association association,
- String fromRole, EdmMultiplicity fromMulti, FullQualifiedName fromType,
- String toRole, EdmMultiplicity toMulti, FullQualifiedName toType) {
-
- AssociationEnd[] ends = new AssociationEnd[]{association.getEnd1(),association.getEnd2()};
- for (AssociationEnd associationEnd : ends) {
- if(associationEnd.getRole().equals(fromRole)) {
- validateAssociationEnd(associationEnd, fromRole, fromMulti, fromType);
- } else if(associationEnd.getRole().equals(toRole)) {
- validateAssociationEnd(associationEnd, toRole, toMulti, toType);
- } else {
- fail("Unexpected navigation end '" + associationEnd.getRole()
- + "' for association with name '" + association.getName() + "'.");
- }
- }
- }
-
- private void validateAssociationEnd(AssociationEnd associationEnd,
- String role, EdmMultiplicity multiplicity, FullQualifiedName type) {
- assertEquals(role, associationEnd.getRole());
- assertEquals(multiplicity, associationEnd.getMultiplicity());
- assertEquals(type, associationEnd.getType());
- }
-
-
- @Test
- public void entitySetTeams() throws Exception {
- // validate teams
- EntitySet teams = aep.getEntitySet(ModelSharedConstants.CONTAINER_1, "Teams");
- assertEquals(ModelSharedConstants.NAMESPACE_1, teams.getEntityType().getNamespace());
- assertEquals("Team", teams.getEntityType().getName());
- }
-
- @Test
- public void entityTypeEmployee() throws Exception {
- // validate employee
- EntityType employee = aep.getEntityType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "Employee"));
- assertEquals("Employee", employee.getName());
- final List<PropertyRef> employeeKeys = employee.getKey().getKeys();
- assertEquals(1, employeeKeys.size());
- assertEquals("EmployeeId", employeeKeys.get(0).getName());
- assertEquals(6, employee.getProperties().size());
- assertEquals(3, employee.getNavigationProperties().size());
-
- for (NavigationProperty navigationProperty : employee.getNavigationProperties()) {
- if (navigationProperty.getName().equals("ne_Manager")) {
- validateNavProperty(navigationProperty, "ManagerEmployees", "r_Employee", "r_Manager");
- } else if (navigationProperty.getName().equals("ne_Team")) {
- validateNavProperty(navigationProperty, "TeamEmployees", "r_Employee", "r_Team");
- } else if (navigationProperty.getName().equals("ne_Room")) {
- validateNavProperty(navigationProperty, "r_Employee-r_Room", "r_Employee", "r_Room");
- } else {
- fail("Got unexpected navigation property with name '" + navigationProperty.getName() + "'.");
- }
- }
-}
-
- @Test
- public void entityTypeTeam() throws Exception {
- // validate team
- EntityType team = aep.getEntityType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "Team"));
- assertEquals("Team", team.getName());
- assertEquals("Base", team.getBaseType().getName());
- assertEquals(ModelSharedConstants.NAMESPACE_1, team.getBaseType().getNamespace());
-
- assertEquals(1, team.getProperties().size());
- assertEquals(1, team.getNavigationProperties().size());
- NavigationProperty navigationProperty= team.getNavigationProperties().get(0);
- validateNavProperty(navigationProperty, "TeamEmployees", "r_Team", "r_Employee");
- }
-
- @Test
- public void entityTypePhotoWithTwoKeyProperties() throws Exception {
- // validate team
- EntityType photo = aep.getEntityType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "Photo"));
- assertEquals("Photo", photo.getName());
- final List<Property> properties = photo.getProperties();
- assertEquals(5, properties.size());
- assertTrue(containsProperty(properties, "Name"));
- assertTrue(containsProperty(properties, "ImageFormat"));
- assertTrue(containsProperty(properties, "MimeType"));
- assertTrue(containsProperty(properties, "ImageUrl"));
- assertTrue(containsProperty(properties, "Image"));
- assertFalse(photo.isAbstract());
- assertTrue(photo.isHasStream());
-
- Key photoKey = photo.getKey();
- List<PropertyRef> keyReferences = photoKey.getKeys();
- assertEquals(2, keyReferences.size());
- PropertyRef name = getPropertyRef(keyReferences, "Name");
- assertEquals("Name", name.getName());
- PropertyRef imageFormat = getPropertyRef(keyReferences, "ImageFormat");
- assertEquals("ImageFormat", imageFormat.getName());
-
-// assertEquals(0, photo.getNavigationProperties().size());
- assertNull(photo.getNavigationProperties());
- }
-
- @Test
- public void entityTypeAbstractBaseType() throws Exception {
- // validate employee
- EntityType baseType = aep.getEntityType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "Base"));
- assertEquals("Base", baseType.getName());
- final List<PropertyRef> keys = baseType.getKey().getKeys();
- assertEquals(1, keys.size());
- assertEquals("Id", keys.get(0).getName());
- assertEquals(2, baseType.getProperties().size());
- assertTrue(baseType.isAbstract());
-
- // validate base for team
- EntityType team = aep.getEntityType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "Team"));
- assertEquals("Team", team.getName());
- assertEquals("Base", team.getBaseType().getName());
- assertEquals(ModelSharedConstants.NAMESPACE_1, team.getBaseType().getNamespace());
- }
-
- @Test
- public void complexTypeLocation() throws Exception {
- // validate employee
- EntityType employee = aep.getEntityType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "Employee"));
- final List<Property> properties = employee.getProperties();
- Property location = null;
- for (Property property : properties) {
- if (property.getName().equals("Location")) {
- location = property;
- }
- }
- assertNotNull(location);
- assertEquals("Location", location.getName());
-
- // validate location complex type
- ComplexType locationType = aep.getComplexType(
- new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "c_Location"));
- assertEquals("c_Location", locationType.getName());
- assertEquals(2, locationType.getProperties().size());
- }
-
- @Test
- public void entityTypeRoomWithNavigation() throws Exception {
- // validate employee
- EntityType room = aep.getEntityType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "Room"));
- assertEquals("Room", room.getName());
- assertEquals("Base", room.getBaseType().getName());
- assertEquals(2, room.getProperties().size());
- final List<NavigationProperty> navigationProperties = room.getNavigationProperties();
- assertEquals(2, navigationProperties.size());
-
- for (NavigationProperty navigationProperty : navigationProperties) {
- if(navigationProperty.getName().equals("nr_Employees")) {
- validateNavProperty(navigationProperty, "r_Employee-r_Room", "r_Room", "r_Employee");
- } else if(navigationProperty.getName().equals("nr_Building")) {
- validateNavProperty(navigationProperty, "BuildingRooms", "r_Room", "r_Building");
- } else {
- fail("Got unexpected navigation property with name '" + navigationProperty.getName() + "'.");
- }
- }
- }
-
- private void validateNavProperty(NavigationProperty navigationProperty, String name,
- String relationship, String fromRole, String toRole) {
- if(name != null) {
- assertEquals(name, navigationProperty.getName());
- }
- FullQualifiedName fqn = new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, relationship);
- assertEquals("Wrong relationship for navigation property.", fqn, navigationProperty.getRelationship());
- assertEquals("Wrong fromRole for navigation property.", fromRole, navigationProperty.getFromRole());
- assertEquals("Wrong toRole for navigation property.", toRole, navigationProperty.getToRole());
- }
-
- private void validateNavProperty(NavigationProperty navigationProperty,
- String relationship, String fromRole, String toRole) {
- validateNavProperty(navigationProperty, null, relationship, fromRole, toRole);
- }
-
- private boolean containsProperty(List<Property> properties, String propertyName) {
- return getProperty(properties, propertyName) != null;
- }
-
- private Property getProperty(List<Property> properties, String name) {
- for (Property property : properties) {
- if(name.equals(property.getName())) {
- return property;
- }
- }
- return null;
- }
-
- private PropertyRef getPropertyRef(List<PropertyRef> properties, String name) {
- for (PropertyRef property : properties) {
- if(name.equals(property.getName())) {
- return property;
- }
- }
- return null;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Building.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Building.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Building.java
deleted file mode 100644
index 737b5e2..0000000
--- a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Building.java
+++ /dev/null
@@ -1,95 +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.core.annotation.model;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
-import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
-import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty.Multiplicity;
-import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
-import org.apache.olingo.odata2.api.annotation.edm.EdmType;
-
-/**
- *
- */
-@EdmEntityType(name = "Building", namespace = ModelSharedConstants.NAMESPACE_1)
-@EdmEntitySet(name = "Buildings")
-public class Building {
- @EdmKey
- @EdmProperty(type = EdmType.INT32)
- private String id;
- @EdmProperty
- private String name;
- @EdmProperty(name = "Image", type = EdmType.BINARY)
- private byte[] image;
- @EdmNavigationProperty(name = "nb_Rooms", toType = Room.class,
- association = "BuildingRooms", toMultiplicity = Multiplicity.MANY)
- private List<Room> rooms = new ArrayList<Room>();
-
- public Building() {}
-
- public String getId() {
- return id;
- }
-
- public void setName(final String name) {
- this.name = name;
- }
-
- public String getName() {
- return name;
- }
-
- public void setImage(final byte[] byteArray) {
- image = byteArray;
- }
-
- public byte[] getImage() {
- if (image == null) {
- return null;
- } else {
- return image.clone();
- }
- }
-
- public List<Room> getRooms() {
- return rooms;
- }
-
- @Override
- public int hashCode() {
- return id == null ? 0 : id.hashCode();
- }
-
- @Override
- public boolean equals(final Object obj) {
- return this == obj
- || obj != null && getClass() == obj.getClass() && id == ((Building) obj).id;
- }
-
- @Override
- public String toString() {
- return "{\"Id\":\"" + id + "\",\"Name\":\"" + name + "\",\"Image\":\"" + Arrays.toString(image) + "\"}";
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/City.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/City.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/City.java
deleted file mode 100644
index 7b866a3..0000000
--- a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/City.java
+++ /dev/null
@@ -1,62 +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.core.annotation.model;
-
-import org.apache.olingo.odata2.api.annotation.edm.EdmComplexType;
-import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
-
-
-/**
- *
- */
-@EdmComplexType(name="c_City", namespace = ModelSharedConstants.NAMESPACE_1)
-public class City {
-
- @EdmProperty
- private String postalCode;
- @EdmProperty
- private String cityName;
-
- public City(final String postalCode, final String name) {
- this.postalCode = postalCode;
- cityName = name;
- }
-
- public void setPostalCode(final String postalCode) {
- this.postalCode = postalCode;
- }
-
- public String getPostalCode() {
- return postalCode;
- }
-
- public void setCityName(final String cityName) {
- this.cityName = cityName;
- }
-
- public String getCityName() {
- return cityName;
- }
-
- @Override
- public String toString() {
- return String.format("%s, %s", cityName, postalCode);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Employee.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Employee.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Employee.java
deleted file mode 100644
index 63b8a76..0000000
--- a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Employee.java
+++ /dev/null
@@ -1,187 +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.core.annotation.model;
-
-import java.text.DateFormat;
-import java.util.Calendar;
-
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
-import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceContent;
-import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceMimeType;
-import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
-import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
-import org.apache.olingo.odata2.api.annotation.edm.EdmType;
-
-/**
- *
- */
-@EdmEntityType(name = "Employee", namespace = ModelSharedConstants.NAMESPACE_1)
-@EdmEntitySet(name = "Employees")
-public class Employee {
- @EdmKey
- @EdmProperty(name = "EmployeeId", type = EdmType.STRING)
- private String employeeId;
- @EdmProperty(name = "EmployeeName")
- private String employeeName;
- @EdmProperty
- private int age;
- @EdmNavigationProperty(name = "ne_Manager", association = "ManagerEmployees")
- private Manager manager;
- @EdmNavigationProperty(name = "ne_Team", association = "TeamEmployees")
- private Team team;
- @EdmNavigationProperty(name = "ne_Room")
- private Room room;
- @EdmMediaResourceMimeType
- private String imageType;
- @EdmMediaResourceContent
- private byte[] image;
- @EdmProperty(name = "ImageUrl")
- private String imageUrl;
- @EdmProperty(name = "EntryDate", type = EdmType.DATE_TIME)
- private Calendar entryDate;
- @EdmProperty(name = "Location")
- private Location location;
-
- public Employee(final String employeeId, final String name) {
- this.employeeId = employeeId;
- setEmployeeName(name);
- }
-
- public String getId() {
- return employeeId;
- }
-
- public void setEmployeeName(final String employeeName) {
- this.employeeName = employeeName;
- }
-
- public String getEmployeeName() {
- return employeeName;
- }
-
- public void setAge(final int age) {
- this.age = age;
- }
-
- public int getAge() {
- return age;
- }
-
- public void setManager(final Manager manager) {
- this.manager = manager;
- }
-
- public Manager getManager() {
- return manager;
- }
-
- public void setTeam(final Team team) {
- this.team = team;
- }
-
- public Team getTeam() {
- return team;
- }
-
- public void setRoom(final Room room) {
- this.room = room;
- }
-
- public Room getRoom() {
- return room;
- }
-
- public void setImageUri(final String imageUri) {
- imageUrl = imageUri;
- }
-
- public String getImageUri() {
- return imageUrl;
- }
-
- public void setLocation(final Location location) {
- this.location = location;
- }
-
- public Location getLocation() {
- return location;
- }
-
- public void setEntryDate(final Calendar date) {
- entryDate = date;
- }
-
- public Calendar getEntryDate() {
- return entryDate;
- }
-
- public void setImageType(final String imageType) {
- this.imageType = imageType;
- }
-
- public String getImageType() {
- return imageType;
- }
-
- public void setImage(final byte[] image) {
- this.image = image;
- }
-
- public byte[] getImage() {
- if (image == null) {
- return null;
- }
- return image.clone();
- }
-
- @Override
- public int hashCode() {
- if (employeeId == null) {
- return 0;
- }
- return employeeId.hashCode();
- }
-
- @Override
- public boolean equals(final Object obj) {
- return this == obj
- || obj != null && getClass() == obj.getClass() && employeeId == ((Employee) obj).employeeId;
- }
-
- @Override
- public String toString() {
- return "{\"EmployeeId\":\"" + employeeId + "\","
- + "\"EmployeeName\":\"" + employeeName + "\","
- + "\"ManagerId\":" + (manager == null ? "null" : "\"" + manager.getId() + "\"") + ","
- + "\"RoomId\":" + (room == null ? "null" : "\"" + room.getId() + "\"") + ","
- + "\"TeamId\":" + (team == null ? "null" : "\"" + team.getId() + "\"") + ","
- + "\"Location\":"
- + (location == null ? "null" :
- "{\"City\":" + (location.getCity() == null ? "null" :
- "{\"PostalCode\":\"" + location.getCity().getPostalCode() + "\","
- + "\"CityName\":\"" + location.getCity().getCityName() + "\"}") + ","
- + "\"Country\":\"" + location.getCountry() + "\"}") + ","
- + "\"Age\":" + age + ","
- + "\"EntryDate\":"
- + (entryDate == null ? "null" : "\"" + DateFormat.getInstance().format(entryDate.getTime()) + "\"") + ","
- + "\"ImageUrl\":\"" + imageUrl + "\"}";
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Location.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Location.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Location.java
deleted file mode 100644
index 7f3f082..0000000
--- a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Location.java
+++ /dev/null
@@ -1,61 +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.core.annotation.model;
-
-import org.apache.olingo.odata2.api.annotation.edm.EdmComplexType;
-import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
-
-
-/**
- *
- */
-@EdmComplexType(name = "c_Location", namespace = ModelSharedConstants.NAMESPACE_1)
-public class Location {
- @EdmProperty
- private String country;
- @EdmProperty
- private City city;
-
- public Location(final String country, final String postalCode, final String cityName) {
- this.country = country;
- city = new City(postalCode, cityName);
- }
-
- public void setCountry(final String country) {
- this.country = country;
- }
-
- public String getCountry() {
- return country;
- }
-
- public void setCity(final City city) {
- this.city = city;
- }
-
- public City getCity() {
- return city;
- }
-
- @Override
- public String toString() {
- return String.format("%s, %s", country, city.toString());
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Manager.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Manager.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Manager.java
deleted file mode 100644
index e3edbd0..0000000
--- a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Manager.java
+++ /dev/null
@@ -1,47 +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.core.annotation.model;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
-import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty.Multiplicity;
-
-/**
- *
- */
-@EdmEntityType(name = "Manager", namespace = ModelSharedConstants.NAMESPACE_1)
-@EdmEntitySet(name = "Managers")
-public class Manager extends Employee {
-
- @EdmNavigationProperty(name = "nm_Employees", association = "ManagerEmployees",
- toMultiplicity = Multiplicity.MANY)
- private List<Employee> employees = new ArrayList<Employee>();
-
- public Manager(final String id, final String name) {
- super(id, name);
- }
-
- public List<Employee> getEmployees() {
- return employees;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/ModelSharedConstants.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/ModelSharedConstants.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/ModelSharedConstants.java
deleted file mode 100644
index 1d44498..0000000
--- a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/ModelSharedConstants.java
+++ /dev/null
@@ -1,25 +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.core.annotation.model;
-
-public interface ModelSharedConstants {
-
- String NAMESPACE_1 = "RefScenario";
- String CONTAINER_1 = "DefaultContainer";
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Photo.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Photo.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Photo.java
deleted file mode 100644
index 520216a..0000000
--- a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Photo.java
+++ /dev/null
@@ -1,128 +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.core.annotation.model;
-
-import java.util.Arrays;
-
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
-import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceContent;
-import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceMimeType;
-import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceSource;
-import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
-import org.apache.olingo.odata2.api.annotation.edm.EdmType;
-
-/**
- *
- */
-@EdmEntityType(name = "Photo", namespace = ModelSharedConstants.NAMESPACE_1)
-@EdmEntitySet(name = "Photos")
-public class Photo {
- @EdmProperty
- @EdmKey
- private String name;
- @EdmProperty(name = "ImageFormat")
- @EdmKey
- private String type;
- @EdmProperty
- @EdmMediaResourceMimeType
- private String mimeType;
- @EdmProperty
- @EdmMediaResourceSource
- private String imageUrl = "http://localhost/someResource.png";
- @EdmProperty(type = EdmType.BINARY)
- @EdmMediaResourceContent
- private byte[] image = ResourceHelper.generateImage();
-
- public String getName() {
- return name;
- }
-
- public void setName(final String name) {
- this.name = name;
- }
-
- public String getType() {
- return type;
- }
-
- public void setType(final String type) {
- this.type = type;
- }
-
- public String getImageUri() {
- return imageUrl;
- }
-
- public void setImageUri(final String uri) {
- imageUrl = uri;
- }
-
- public byte[] getImage() {
- return image.clone();
- }
-
- public void setImage(final byte[] image) {
- this.image = image;
- }
-
- public String getImageType() {
- return mimeType;
- }
-
- public void setImageType(final String imageType) {
- this.mimeType = imageType;
- }
-
- @Override
- public int hashCode() {
- int hash = 5;
- hash = 83 * hash + (this.name != null ? this.name.hashCode() : 0);
- hash = 83 * hash + (this.type != null ? this.type.hashCode() : 0);
- return hash;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- final Photo other = (Photo) obj;
- if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) {
- return false;
- }
- if ((this.type == null) ? (other.type != null) : !this.type.equals(other.type)) {
- return false;
- }
- return true;
- }
-
- @Override
- public String toString() {
- return "{\"Name\":\"" + name + "\","
- + "\"Type\":\"" + type + "\","
- + "\"ImageUrl\":\"" + imageUrl + "\","
- + "\"Image\":\"" + Arrays.toString(image) + "\","
- + "\"MimeType\":\"" + mimeType + "\"";
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/RefBase.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/RefBase.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/RefBase.java
deleted file mode 100644
index 6f3002f..0000000
--- a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/RefBase.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright 2013 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * 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.core.annotation.model;
-
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
-import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
-import org.apache.olingo.odata2.api.annotation.edm.EdmType;
-
-/**
- *
- */
-@EdmEntityType(name="Base", namespace=ModelSharedConstants.NAMESPACE_1)
-public abstract class RefBase {
- @EdmProperty(name="Name")
- protected String name;
- @EdmProperty(name="Id", type = EdmType.STRING)
- @EdmKey
- protected int id;
-
- public RefBase(int id, String name) {
- this.name = name;
- this.id = id;
- }
-
- public String getName() {
- return name;
- }
-
- public String getId() {
- return Integer.toString(id);
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public void setId(int id) {
- this.id = id;
- }
-}
[13/52] Poc for ListsDs and Processor
Posted by mi...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d83070de/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/processor/json/JsonConsumerTest.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/processor/json/JsonConsumerTest.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/processor/json/JsonConsumerTest.java
index c588b30..3d7b89d 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/processor/json/JsonConsumerTest.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/processor/json/JsonConsumerTest.java
@@ -15,11 +15,11 @@
*/
package org.apache.olingo.odata2.core.annotation.processor.json;
-import org.apache.olingo.odata2.core.annotation.processor.json.JsonConsumer;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.Map;
+
import org.junit.Assert;
import org.junit.Test;
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d83070de/odata2-edm-annotation/edm-annotation-webref/pom.xml
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/pom.xml b/odata2-edm-annotation/edm-annotation-webref/pom.xml
index 89ae0b4..cfc7f92 100644
--- a/odata2-edm-annotation/edm-annotation-webref/pom.xml
+++ b/odata2-edm-annotation/edm-annotation-webref/pom.xml
@@ -89,6 +89,13 @@ the License. -->
<version>${project.version}</version>
</dependency>
<dependency>
+ <groupId>org.apache.olingo</groupId>
+ <artifactId>olingo-odata2-ref-incubating</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+
+ <dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.1</version>
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d83070de/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Building.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Building.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Building.java
index 5dca34d..59a8eb8 100644
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Building.java
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Building.java
@@ -45,13 +45,6 @@ public class Building {
to = @NavigationEnd(role = "r_Room", type="Room", multiplicity = EdmMultiplicity.MANY))
private List<Room> rooms = new ArrayList<Room>();
- public Building() { }
-
- public Building(final int id, final String name) {
- this.id = id;
- setName(name);
- }
-
public String getId() {
return Integer.toString(id);
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d83070de/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Employee.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Employee.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Employee.java
index 02a1530..76c4474 100644
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Employee.java
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Employee.java
@@ -36,7 +36,7 @@ import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
public class Employee {
private static int counter = 1;
@EdmKey
- @EdmProperty(name="EmployeeId", type = EdmSimpleTypeKind.Int32)
+ @EdmProperty(name="EmployeeId", type = EdmSimpleTypeKind.String)
private int employeeId;
@EdmProperty(name="EmployeeName")
private String employeeName;
@@ -55,11 +55,6 @@ public class Employee {
@EdmProperty(name="Location")
private Location location;
- public Employee(final int employeeId, final String name) {
- this.employeeId = employeeId;
- setEmployeeName(name);
- }
-
public String getId() {
return Integer.toString(employeeId);
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d83070de/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Manager.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Manager.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Manager.java
index e3b2631..135753b 100644
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Manager.java
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Manager.java
@@ -35,10 +35,6 @@ public class Manager extends Employee {
to = @NavigationEnd(role = "r_Employees", type = "Employee"))
private List<Employee> employees = new ArrayList<Employee>();
- public Manager(final int id, final String name) {
- super(id, name);
- }
-
public List<Employee> getEmployees() {
return employees;
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d83070de/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Photo.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Photo.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Photo.java
index 7fab9bc..fd266ce 100644
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Photo.java
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Photo.java
@@ -50,11 +50,6 @@ public class Photo {
@EdmMediaResourceContent
private byte[] image = ResourceHelper.generateImage();
- public Photo(final String name, final String type) {
- this.name = name;
- this.type = type;
- }
-
public String getName() {
return name;
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d83070de/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/RefBase.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/RefBase.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/RefBase.java
index 82d9812..fef6317 100644
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/RefBase.java
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/RefBase.java
@@ -34,11 +34,6 @@ public abstract class RefBase {
@EdmKey
protected int id;
- public RefBase(int id, String name) {
- this.name = name;
- this.id = id;
- }
-
public String getName() {
return name;
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d83070de/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Room.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Room.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Room.java
index 28373b9..c2e68fa 100644
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Room.java
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Room.java
@@ -45,10 +45,6 @@ public class Room extends RefBase {
to = @NavigationEnd(role = "r_Employees", type = "Employee", multiplicity = EdmMultiplicity.MANY))
private List<Employee> employees = new ArrayList<Employee>();
- public Room(final int id, final String name) {
- super(id, name);
- }
-
public void setSeats(final int seats) {
this.seats = seats;
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d83070de/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Team.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Team.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Team.java
index 2bf6701..d851428 100644
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Team.java
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Team.java
@@ -40,14 +40,6 @@ public class Team extends RefBase {
to = @NavigationEnd(role = "r_Employees", type = "Employee", multiplicity = EdmMultiplicity.MANY))
private List<Employee> employees = new ArrayList<Employee>();
- public Team() {
- super(-1, null);
- }
-
- public Team(final int id, final String name) {
- super(id, name);
- }
-
public Boolean isScrumTeam() {
return isScrumTeam;
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d83070de/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ds/BuildingDs.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ds/BuildingDs.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ds/BuildingDs.java
deleted file mode 100644
index 282bb4f..0000000
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ds/BuildingDs.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Copyright 2013 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * 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.ref.annotation.model.ds;
-
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-import org.apache.olingo.odata2.api.annotation.edm.ds.EntityCreate;
-import org.apache.olingo.odata2.api.annotation.edm.ds.EntityDataSource;
-import org.apache.olingo.odata2.api.annotation.edm.ds.EntityDelete;
-import org.apache.olingo.odata2.api.annotation.edm.ds.EntityRead;
-import org.apache.olingo.odata2.api.annotation.edm.ds.EntitySetRead;
-import org.apache.olingo.odata2.api.annotation.edm.ds.EntityUpdate;
-import org.apache.olingo.odata2.ref.annotation.model.Building;
-
-/**
- *
- */
-@EntityDataSource(name="BuildingDataSource", entityType = Building.class)
-public class BuildingDs {
-
- private static int idCounter = 1;
- private final static Map<Integer, Building> id2Building = new HashMap<Integer, Building>();
-
- @EntityRead
- public Building read(String id) {
- return id2Building.get(Integer.valueOf(id));
- }
-
- @EntitySetRead
- public Collection<Building> read() {
- return id2Building.values();
- }
-
- @EntityCreate
- @EntityUpdate
- public Building createOrUpdate(Building building) {
- Building b = id2Building.get(Integer.valueOf(building.getId()));
- if(b != null) {
- b.setName(building.getName());
- } else {
- final int id = idCounter++;
- b = new Building(id, building.getName());
- id2Building.put(Integer.valueOf(id), b);
- }
- return b;
- }
-
- @EntityDelete
- public Building delete(String id) {
- return id2Building.remove(Integer.valueOf(id));
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d83070de/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ds/PhotoDs.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ds/PhotoDs.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ds/PhotoDs.java
deleted file mode 100644
index 660f59c..0000000
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ds/PhotoDs.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Copyright 2013 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * 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.ref.annotation.model.ds;
-
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-import org.apache.olingo.odata2.api.annotation.edm.ds.EntityCreate;
-import org.apache.olingo.odata2.api.annotation.edm.ds.EntityDataSource;
-import org.apache.olingo.odata2.api.annotation.edm.ds.EntityRead;
-import org.apache.olingo.odata2.api.annotation.edm.ds.EntitySetRead;
-import org.apache.olingo.odata2.api.annotation.edm.ds.EntityUpdate;
-import org.apache.olingo.odata2.ref.annotation.model.Photo;
-
-/**
- *
- */
-@EntityDataSource(entityType = Photo.class)
-public class PhotoDs {
- private static final Map<String, Photo> photoDb = new HashMap<String, Photo>();
-
- private String createPhotoId(Photo p) {
- if(p == null) {
- return null;
- }
- return p.getName() + "-" + p.getType();
- }
-
- @EntityCreate
- @EntityUpdate
- public Photo storePhoto(Photo photo) {
- Photo p = new Photo(photo.getName(), photo.getType());
- p.setImageUri(photo.getImageUri());
- p.setImageType(photo.getImageType());
-
- photoDb.put(createPhotoId(p), p);
-
- return p;
- }
-
- @EntityRead
- public Photo loadPhoto(String name) {
- return photoDb.get(createPhotoId(new Photo(name, "PNG")));
- }
-
- @EntitySetRead
- public Collection<Photo> loadAllPhotos() {
- return photoDb.values();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d83070de/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ds/TeamDs.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ds/TeamDs.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ds/TeamDs.java
deleted file mode 100644
index 9426c7b..0000000
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ds/TeamDs.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Copyright 2013 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * 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.ref.annotation.model.ds;
-
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Map;
-import org.apache.olingo.odata2.api.annotation.edm.ds.EntityRead;
-import org.apache.olingo.odata2.api.annotation.edm.ds.EntityDataSource;
-import org.apache.olingo.odata2.api.annotation.edm.ds.EntityCreate;
-import org.apache.olingo.odata2.api.annotation.edm.ds.EntitySetRead;
-import org.apache.olingo.odata2.api.annotation.edm.ds.EntityUpdate;
-import org.apache.olingo.odata2.ref.annotation.model.Team;
-
-/**
- *
- */
-@EntityDataSource(name="TeamDataSource", entityType = Team.class)
-public class TeamDs {
-
- private static int idCounter = 1;
- private static final Map<Integer, Team> id2Team = new HashMap<Integer, Team>();
-
- @EntityRead
- public Team readTeam(String id) {
- return id2Team.get(Integer.valueOf(id));
- }
-
- @EntitySetRead
- public Collection<Team> readAllTeams() {
- return id2Team.values();
- }
-
- @EntityCreate
- public Team writeTeam(Team team) {
- final int id = idCounter++;
- team.setId(id);
- id2Team.put(Integer.valueOf(id), team);
-
- return team;
- }
-
- @EntityUpdate
- public Team update(Team team) {
- Team t = id2Team.get(Integer.valueOf(team.getId()));
- if(t != null) {
- t.setName(team.getName());
- t.setScrumTeam(team.isScrumTeam());
- }
- return team;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d83070de/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/processor/AnnotationPocServiceFactory.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/processor/AnnotationPocServiceFactory.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/processor/AnnotationPocServiceFactory.java
new file mode 100644
index 0000000..2617df0
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/processor/AnnotationPocServiceFactory.java
@@ -0,0 +1,161 @@
+/**
+ * *****************************************************************************
+ * 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.ref.annotation.processor;
+
+import org.apache.olingo.odata2.core.annotation.ds.AnnotationValueAccess;
+import org.apache.olingo.odata2.core.annotation.ds.AnnotationInMemoryDs;
+import org.apache.olingo.odata2.api.ODataCallback;
+import org.apache.olingo.odata2.api.ODataDebugCallback;
+import org.apache.olingo.odata2.api.ODataService;
+import org.apache.olingo.odata2.api.ODataServiceFactory;
+import org.apache.olingo.odata2.api.commons.HttpStatusCodes;
+import org.apache.olingo.odata2.api.ep.EntityProvider;
+import org.apache.olingo.odata2.api.exception.ODataApplicationException;
+import org.apache.olingo.odata2.api.exception.ODataException;
+import org.apache.olingo.odata2.api.processor.ODataContext;
+import org.apache.olingo.odata2.api.processor.ODataErrorCallback;
+import org.apache.olingo.odata2.api.processor.ODataErrorContext;
+import org.apache.olingo.odata2.api.processor.ODataResponse;
+import org.apache.olingo.odata2.core.annotation.ds.DataStore;
+import org.apache.olingo.odata2.core.annotation.edm.AnnotationEdmProvider;
+import org.apache.olingo.odata2.core.annotation.processor.ListsProcessor;
+import org.apache.olingo.odata2.ref.annotation.model.Building;
+import org.apache.olingo.odata2.ref.annotation.model.Photo;
+import org.apache.olingo.odata2.ref.annotation.model.Room;
+import org.apache.olingo.odata2.ref.annotation.model.Team;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ *
+ */
+public class AnnotationPocServiceFactory extends ODataServiceFactory {
+
+ private static boolean isInitialized = false;
+
+ @Override
+ public ODataService createService(final ODataContext context) throws ODataException {
+
+ String modelPackage = "org.apache.olingo.odata2.ref.annotation.model";
+ AnnotationEdmProvider annotationEdmProvider = new AnnotationEdmProvider(modelPackage);
+ AnnotationInMemoryDs annotationScenarioDs = new AnnotationInMemoryDs(modelPackage);
+ AnnotationValueAccess annotationValueAccess = new AnnotationValueAccess();
+
+ if (!isInitialized) {
+ initializeSampleData(annotationScenarioDs);
+ isInitialized = true;
+ }
+
+ // Edm via Annotations and ListProcessor via AnnotationDS with AnnotationsValueAccess
+ return createODataSingleProcessorService(annotationEdmProvider,
+ new ListsProcessor(annotationScenarioDs, annotationValueAccess));
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public <T extends ODataCallback> T getCallback(final Class<? extends ODataCallback> callbackInterface) {
+ return (T) (callbackInterface.isAssignableFrom(ScenarioErrorCallback.class)
+ ? new ScenarioErrorCallback() : callbackInterface.isAssignableFrom(ODataDebugCallback.class)
+ ? new ScenarioDebugCallback() : super.getCallback(callbackInterface));
+ }
+
+
+
+ /*
+ * Helper classes and methods
+ */
+
+ /**
+ *
+ */
+ private final class ScenarioDebugCallback implements ODataDebugCallback {
+
+ @Override
+ public boolean isDebugEnabled() {
+ return true;
+ }
+ }
+
+ private class ScenarioErrorCallback implements ODataErrorCallback {
+
+ private final Logger LOG = LoggerFactory.getLogger(ScenarioErrorCallback.class);
+
+ @Override
+ public ODataResponse handleError(final ODataErrorContext context) throws ODataApplicationException {
+ if (context.getHttpStatus() == HttpStatusCodes.INTERNAL_SERVER_ERROR) {
+ LOG.error("Internal Server Error", context.getException());
+ }
+
+ return EntityProvider.writeErrorDocument(context);
+ }
+
+ }
+
+ private void initializeSampleData(AnnotationInMemoryDs dataSource) {
+ DataStore<Team> teamDs = dataSource.getDataStore(Team.class);
+ teamDs.create(createTeam("Team Alpha", true));
+ teamDs.create(createTeam("Team Beta", false));
+ teamDs.create(createTeam("Team Gamma", false));
+ teamDs.create(createTeam("Team Omega", true));
+ teamDs.create(createTeam("Team Zeta", true));
+
+ DataStore<Building> buildingsDs = dataSource.getDataStore(Building.class);
+ buildingsDs.create(createBuilding("Red Building"));
+ buildingsDs.create(createBuilding("Green Building"));
+ buildingsDs.create(createBuilding("Blue Building"));
+ buildingsDs.create(createBuilding("Yellow Building"));
+
+ DataStore<Photo> photoDs = dataSource.getDataStore(Photo.class);
+ photoDs.create(createPhoto("Small picture"));
+ photoDs.create(createPhoto("Medium picture"));
+ photoDs.create(createPhoto("Big picture"));
+
+ DataStore<Room> roomDs = dataSource.getDataStore(Room.class);
+ roomDs.create(createRoom("Tiny room", 5, 1));
+ roomDs.create(createRoom("Small room", 20, 1));
+ roomDs.create(createRoom("Big room", 40, 1));
+ roomDs.create(createRoom("Huge room", 120, 1));
+ }
+
+ private Team createTeam(String teamName, boolean isScrumTeam) {
+ Team team = new Team();
+ team.setName(teamName);
+ team.setScrumTeam(isScrumTeam);
+ return team;
+ }
+
+ private Building createBuilding(String buildingName) {
+ Building b = new Building();
+ b.setName(buildingName);
+ return b;
+ }
+
+ private Photo createPhoto(String name) {
+ Photo p = new Photo();
+ p.setName(name);
+ p.setType("PNG");
+ p.setImageType("image/png");
+ p.setImageUri("http://localhost/image/" + name);
+ return p;
+ }
+
+ private Room createRoom(String name, int seats, int version) {
+ Room r = new Room();
+ r.setName(name);
+ r.setSeats(seats);
+ r.setVersion(version);
+ return r;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d83070de/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/processor/ScenarioErrorCallback.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/processor/ScenarioErrorCallback.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/processor/ScenarioErrorCallback.java
deleted file mode 100644
index 45a4f81..0000000
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/processor/ScenarioErrorCallback.java
+++ /dev/null
@@ -1,47 +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.ref.annotation.processor;
-
-import org.apache.olingo.odata2.api.commons.HttpStatusCodes;
-import org.apache.olingo.odata2.api.ep.EntityProvider;
-import org.apache.olingo.odata2.api.exception.ODataApplicationException;
-import org.apache.olingo.odata2.api.processor.ODataErrorCallback;
-import org.apache.olingo.odata2.api.processor.ODataErrorContext;
-import org.apache.olingo.odata2.api.processor.ODataResponse;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Callback for handling errors by logging internal server errors additionally.
- *
- */
-public class ScenarioErrorCallback implements ODataErrorCallback {
-
- private static final Logger LOG = LoggerFactory.getLogger(ScenarioErrorCallback.class);
-
- @Override
- public ODataResponse handleError(final ODataErrorContext context) throws ODataApplicationException {
- if (context.getHttpStatus() == HttpStatusCodes.INTERNAL_SERVER_ERROR) {
- LOG.error("Internal Server Error", context.getException());
- }
-
- return EntityProvider.writeErrorDocument(context);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d83070de/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/processor/ScenarioServiceFactory.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/processor/ScenarioServiceFactory.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/processor/ScenarioServiceFactory.java
deleted file mode 100644
index d04f6f4..0000000
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/processor/ScenarioServiceFactory.java
+++ /dev/null
@@ -1,110 +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.ref.annotation.processor;
-
-import org.apache.olingo.odata2.api.ODataCallback;
-import org.apache.olingo.odata2.api.ODataDebugCallback;
-import org.apache.olingo.odata2.api.ODataService;
-import org.apache.olingo.odata2.api.ODataServiceFactory;
-import org.apache.olingo.odata2.api.exception.ODataException;
-import org.apache.olingo.odata2.api.processor.ODataContext;
-import org.apache.olingo.odata2.core.annotation.edm.AnnotationEdmProvider;
-import org.apache.olingo.odata2.core.annotation.processor.AnnotationProcessor;
-import org.apache.olingo.odata2.ref.annotation.model.Building;
-import org.apache.olingo.odata2.ref.annotation.model.Photo;
-import org.apache.olingo.odata2.ref.annotation.model.Team;
-import org.apache.olingo.odata2.ref.annotation.model.ds.BuildingDs;
-import org.apache.olingo.odata2.ref.annotation.model.ds.PhotoDs;
-import org.apache.olingo.odata2.ref.annotation.model.ds.TeamDs;
-
-/**
- *
- */
-public class ScenarioServiceFactory extends ODataServiceFactory {
-
- private static boolean isInitialized = false;
-
- @Override
- public ODataService createService(final ODataContext context) throws ODataException {
- if(!isInitialized) {
- initializeSampleData();
- isInitialized = true;
- }
-
- return createODataSingleProcessorService(
- new AnnotationEdmProvider("org.apache.olingo.odata2.ref.annotation.model"),
- new AnnotationProcessor(context, "org.apache.olingo.odata2.ref.annotation.model"));
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public <T extends ODataCallback> T getCallback(final Class<? extends ODataCallback> callbackInterface) {
- return (T) (callbackInterface.isAssignableFrom(ScenarioErrorCallback.class)
- ? new ScenarioErrorCallback() : callbackInterface.isAssignableFrom(ODataDebugCallback.class)
- ? new ScenarioDebugCallback() : super.getCallback(callbackInterface));
- }
-
- private final class ScenarioDebugCallback implements ODataDebugCallback {
-
- @Override
- public boolean isDebugEnabled() {
- return true;
- }
- }
-
-
- private void initializeSampleData() {
- TeamDs teamDs = new TeamDs();
- teamDs.writeTeam(createTeam("Team Alpha", true));
- teamDs.writeTeam(createTeam("Team Beta", false));
- teamDs.writeTeam(createTeam("Team Gamma", false));
- teamDs.writeTeam(createTeam("Team Omega", true));
- teamDs.writeTeam(createTeam("Team Zeta", true));
-
- BuildingDs buildingsDs = new BuildingDs();
- buildingsDs.createOrUpdate(createBuilding("Red Building"));
- buildingsDs.createOrUpdate(createBuilding("Green Building"));
- buildingsDs.createOrUpdate(createBuilding("Blue Building"));
-
- PhotoDs photoDs = new PhotoDs();
- photoDs.storePhoto(createPhoto("Small picture"));
- photoDs.storePhoto(createPhoto("Medium picture"));
- photoDs.storePhoto(createPhoto("Big picture"));
- }
-
- private Team createTeam(String teamName, boolean isScrumTeam) {
- Team team = new Team();
- team.setName(teamName);
- team.setScrumTeam(isScrumTeam);
- return team;
- }
-
- private Building createBuilding(String buildingName) {
- Building b = new Building();
- b.setName(buildingName);
- return b;
- }
-
- private Photo createPhoto(String name) {
- Photo p = new Photo(name, "PNG");
- p.setImageType("image/png");
- p.setImageUri("http://localhost/image/" + name);
- return p;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d83070de/odata2-lib/odata-annotation/pom.xml
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-annotation/pom.xml b/odata2-lib/odata-annotation/pom.xml
index 269c062..689e49e 100644
--- a/odata2-lib/odata-annotation/pom.xml
+++ b/odata2-lib/odata-annotation/pom.xml
@@ -1,34 +1,34 @@
<?xml version="1.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.
--->
+<!-- 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
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
- xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
- <modelVersion>4.0.0</modelVersion>
-
- <parent>
- <groupId>org.apache.olingo</groupId>
- <artifactId>olingo-odata2-lib-incubating</artifactId>
- <version>1.1.0-SNAPSHOT</version>
- <relativePath>..</relativePath>
- </parent>
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
+ xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <modelVersion>4.0.0</modelVersion>
- <artifactId>olingo-odata2-api-annotation-incubating</artifactId>
- <name>${project.artifactId}</name>
+ <parent>
+ <groupId>org.apache.olingo</groupId>
+ <artifactId>olingo-odata2-lib-incubating</artifactId>
+ <version>1.1.0-SNAPSHOT</version>
+ <relativePath>..</relativePath>
+ </parent>
+
+ <artifactId>olingo-odata2-api-annotation-incubating</artifactId>
+ <name>${project.artifactId}</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.olingo</groupId>
+ <artifactId>olingo-odata2-api-incubating</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
</project>
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d83070de/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmComplexEntity.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmComplexEntity.java b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmComplexEntity.java
new file mode 100644
index 0000000..adec2d7
--- /dev/null
+++ b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmComplexEntity.java
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * 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.api.annotation.edm;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.TYPE)
+public @interface EdmComplexEntity {
+ String name() default "";
+ String namespace();
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d83070de/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmEntityType.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmEntityType.java b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmEntityType.java
new file mode 100644
index 0000000..ed5d802
--- /dev/null
+++ b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmEntityType.java
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * 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.api.annotation.edm;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.TYPE)
+public @interface EdmEntityType {
+ String name() default "";
+ String namespace();
+ /* If set this entity is exposed as entity set with given name. If not set theire will be no entity set generated. */
+ String entitySetName() default "";
+ String container() default "";
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d83070de/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmFacets.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmFacets.java b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmFacets.java
new file mode 100644
index 0000000..4ea2bd5
--- /dev/null
+++ b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmFacets.java
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * 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.api.annotation.edm;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.ANNOTATION_TYPE)
+public @interface EdmFacets {
+ int maxLength() default 0;
+ int scale() default -1;
+ int precision() default 0;
+ boolean nullable() default false;
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d83070de/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmKey.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmKey.java b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmKey.java
new file mode 100644
index 0000000..48db91f
--- /dev/null
+++ b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmKey.java
@@ -0,0 +1,29 @@
+/*******************************************************************************
+ * 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.api.annotation.edm;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.FIELD)
+public @interface EdmKey {
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d83070de/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmMediaResourceContent.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmMediaResourceContent.java b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmMediaResourceContent.java
new file mode 100644
index 0000000..80e9cd8
--- /dev/null
+++ b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmMediaResourceContent.java
@@ -0,0 +1,29 @@
+/*******************************************************************************
+ * 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.api.annotation.edm;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.FIELD)
+public @interface EdmMediaResourceContent {
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d83070de/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmMediaResourceMimeType.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmMediaResourceMimeType.java b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmMediaResourceMimeType.java
new file mode 100644
index 0000000..d255ff4
--- /dev/null
+++ b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmMediaResourceMimeType.java
@@ -0,0 +1,29 @@
+/*******************************************************************************
+ * 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.api.annotation.edm;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.FIELD)
+public @interface EdmMediaResourceMimeType {
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d83070de/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmMediaResourceSource.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmMediaResourceSource.java b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmMediaResourceSource.java
new file mode 100644
index 0000000..78e72b5
--- /dev/null
+++ b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmMediaResourceSource.java
@@ -0,0 +1,29 @@
+/*******************************************************************************
+ * 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.api.annotation.edm;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.FIELD)
+public @interface EdmMediaResourceSource {
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d83070de/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmNavigationProperty.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmNavigationProperty.java b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmNavigationProperty.java
new file mode 100644
index 0000000..cf898df
--- /dev/null
+++ b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmNavigationProperty.java
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * 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.api.annotation.edm;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.FIELD)
+public @interface EdmNavigationProperty {
+ String name();
+ String relationship();
+
+ //
+ NavigationEnd from() default @NavigationEnd;
+ NavigationEnd to() default @NavigationEnd;
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d83070de/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmProperty.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmProperty.java b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmProperty.java
new file mode 100644
index 0000000..66c5282
--- /dev/null
+++ b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmProperty.java
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * 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.api.annotation.edm;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.FIELD)
+public @interface EdmProperty {
+ EdmSimpleTypeKind type() default EdmSimpleTypeKind.Null;
+ String name() default "";
+ /* only for complex property */
+ String namespace() default "";
+ EdmFacets facets() default @EdmFacets;
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d83070de/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/NavigationEnd.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/NavigationEnd.java b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/NavigationEnd.java
new file mode 100644
index 0000000..2ce5ef1
--- /dev/null
+++ b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/NavigationEnd.java
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * 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.api.annotation.edm;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.FIELD)
+public @interface NavigationEnd {
+ String role() default "";
+ String type() default "";
+
+ EdmMultiplicity multiplicity() default EdmMultiplicity.ONE;
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d83070de/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/AbstractRefTest.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/AbstractRefTest.java b/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/AbstractRefTest.java
index 84b8ed1..e9e2153 100644
--- a/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/AbstractRefTest.java
+++ b/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/AbstractRefTest.java
@@ -39,12 +39,12 @@ import org.apache.olingo.odata2.api.commons.HttpStatusCodes;
import org.apache.olingo.odata2.api.commons.ODataHttpMethod;
import org.apache.olingo.odata2.api.edm.provider.EdmProvider;
import org.apache.olingo.odata2.api.processor.ODataSingleProcessor;
+import org.apache.olingo.odata2.core.annotation.ds.BeanPropertyAccess;
+import org.apache.olingo.odata2.core.annotation.processor.ListsProcessor;
import org.apache.olingo.odata2.core.processor.ODataSingleProcessorService;
import org.apache.olingo.odata2.ref.edm.ScenarioEdmProvider;
import org.apache.olingo.odata2.ref.model.DataContainer;
import org.apache.olingo.odata2.ref.model.Photo;
-import org.apache.olingo.odata2.ref.processor.ListsProcessor;
-import org.apache.olingo.odata2.ref.processor.BeanPropertyAccess;
import org.apache.olingo.odata2.ref.processor.ScenarioDataSource;
import org.apache.olingo.odata2.testutil.fit.AbstractFitTest;
import org.apache.olingo.odata2.testutil.helper.StringHelper;
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d83070de/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/EntryXmlReadOnlyTest.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/EntryXmlReadOnlyTest.java b/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/EntryXmlReadOnlyTest.java
index 50a9b47..eec1f42 100644
--- a/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/EntryXmlReadOnlyTest.java
+++ b/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/EntryXmlReadOnlyTest.java
@@ -30,9 +30,9 @@ import org.apache.http.HttpHeaders;
import org.apache.http.HttpResponse;
import org.apache.olingo.odata2.api.commons.HttpContentType;
import org.apache.olingo.odata2.api.commons.HttpStatusCodes;
+import org.apache.olingo.odata2.core.annotation.processor.ListsProcessor;
import org.apache.olingo.odata2.ref.model.DataContainer;
import org.apache.olingo.odata2.ref.model.Photo;
-import org.apache.olingo.odata2.ref.processor.ListsProcessor;
import org.apache.olingo.odata2.ref.processor.ScenarioDataSource;
import org.custommonkey.xmlunit.XMLAssert;
import org.junit.Test;
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d83070de/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 edfbd27..265fc28 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
@@ -49,13 +49,13 @@ import org.apache.olingo.odata2.api.commons.HttpStatusCodes;
import org.apache.olingo.odata2.api.edm.provider.EdmProvider;
import org.apache.olingo.odata2.api.exception.ODataException;
import org.apache.olingo.odata2.api.processor.ODataSingleProcessor;
+import org.apache.olingo.odata2.core.annotation.ds.BeanPropertyAccess;
+import org.apache.olingo.odata2.core.annotation.processor.ListsProcessor;
import org.apache.olingo.odata2.core.commons.ContentType;
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.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;
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d83070de/odata2-lib/odata-ref/pom.xml
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-ref/pom.xml b/odata2-lib/odata-ref/pom.xml
index fbf419f..7b71a66 100644
--- a/odata2-lib/odata-ref/pom.xml
+++ b/odata2-lib/odata-ref/pom.xml
@@ -91,6 +91,11 @@
<version>${project.version}</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.olingo</groupId>
+ <artifactId>olingo-odata2-edm-annotation-core-incubating</artifactId>
+ <version>${project.version}</version>
+ </dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d83070de/odata2-lib/odata-ref/src/main/java/org/apache/olingo/odata2/ref/processor/BeanPropertyAccess.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-ref/src/main/java/org/apache/olingo/odata2/ref/processor/BeanPropertyAccess.java b/odata2-lib/odata-ref/src/main/java/org/apache/olingo/odata2/ref/processor/BeanPropertyAccess.java
deleted file mode 100644
index a621eb7..0000000
--- a/odata2-lib/odata-ref/src/main/java/org/apache/olingo/odata2/ref/processor/BeanPropertyAccess.java
+++ /dev/null
@@ -1,185 +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.ref.processor;
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.Arrays;
-
-import org.apache.olingo.odata2.api.edm.EdmException;
-import org.apache.olingo.odata2.api.edm.EdmMapping;
-import org.apache.olingo.odata2.api.edm.EdmProperty;
-import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
-import org.apache.olingo.odata2.api.exception.ODataException;
-import org.apache.olingo.odata2.api.exception.ODataHttpException;
-import org.apache.olingo.odata2.api.exception.ODataNotFoundException;
-
-/**
- * Data access.
- */
-public class BeanPropertyAccess implements ValueAccess {
-
- @Override
- public <T> Object getPropertyValue(final T data, final EdmProperty property) throws ODataException {
- return getValue(data, getGetterMethodName(property));
- }
-
- @Override
- public <T, V> void setPropertyValue(T data, final EdmProperty property, final V value) throws ODataException {
- final String methodName = getSetterMethodName(getGetterMethodName(property));
- if (methodName != null) {
- setValue(data, methodName, value);
- }
- }
-
- @Override
- public <T> Class<?> getPropertyType(final T data, final EdmProperty property) throws ODataException {
- return getType(data, getGetterMethodName(property));
- }
-
- @Override
- public <T> Object getMappingValue(final T data, final EdmMapping mapping) throws ODataException {
- if (mapping != null && mapping.getMimeType() != null) {
- return getValue(data, mapping.getMimeType());
- }
- return null;
- }
-
- @Override
- public <T, V> void setMappingValue(T data, final EdmMapping mapping, final V value) throws ODataException {
- if (mapping != null && mapping.getMimeType() != null) {
- setValue(data, getSetterMethodName(mapping.getMimeType()), value);
- }
- }
-
- private String getGetterMethodName(final EdmProperty property) throws EdmException {
- final String prefix = isBooleanProperty(property) ? "is" : "get";
- final String defaultMethodName = prefix + property.getName();
- return property.getMapping() == null || property.getMapping().getInternalName() == null ?
- defaultMethodName : property.getMapping().getInternalName();
- }
-
- private boolean isBooleanProperty(final EdmProperty property) throws EdmException {
- return property.isSimple()
- && property.getType() == EdmSimpleTypeKind.Boolean.getEdmSimpleTypeInstance();
- }
-
- private String getSetterMethodName(final String getterMethodName) {
- return getterMethodName.contains(".") ?
- null : getterMethodName.replaceFirst("^is", "set").replaceFirst("^get", "set");
- }
-
- private <T> Object getValue(final T data, final String methodName) throws ODataNotFoundException {
- Object dataObject = data;
-
- for (final String method : methodName.split("\\.", -1)) {
- if (dataObject != null) {
- try {
- dataObject = dataObject.getClass().getMethod(method).invoke(dataObject);
- } catch (SecurityException e) {
- throw new ODataNotFoundException(ODataHttpException.COMMON, e);
- } catch (NoSuchMethodException e) {
- throw new ODataNotFoundException(ODataHttpException.COMMON, e);
- } catch (IllegalArgumentException e) {
- throw new ODataNotFoundException(ODataHttpException.COMMON, e);
- } catch (IllegalAccessException e) {
- throw new ODataNotFoundException(ODataHttpException.COMMON, e);
- } catch (InvocationTargetException e) {
- throw new ODataNotFoundException(ODataHttpException.COMMON, e);
- }
- }
- }
-
- return dataObject;
- }
-
- private <T, V> void setValue(final T data, final String methodName, final V value)
- throws ODataNotFoundException {
- try {
- boolean found = false;
- for (final Method method : Arrays.asList(data.getClass().getMethods())) {
- if (method.getName().equals(methodName)) {
- found = true;
- final Class<?> type = method.getParameterTypes()[0];
- if (value == null) {
- if (type.equals(byte.class) || type.equals(short.class) || type.equals(int.class)
- || type.equals(long.class) || type.equals(char.class)) {
- method.invoke(data, 0);
- } else if (type.equals(float.class) || type.equals(double.class)) {
- method.invoke(data, 0.0);
- } else if (type.equals(boolean.class)) {
- method.invoke(data, false);
- } else {
- method.invoke(data, value);
- }
- } else {
- method.invoke(data, value);
- }
- break;
- }
- }
- if (!found) {
- throw new ODataNotFoundException(null);
- }
- } catch (SecurityException e) {
- throw new ODataNotFoundException(null, e);
- } catch (IllegalArgumentException e) {
- throw new ODataNotFoundException(null, e);
- } catch (IllegalAccessException e) {
- throw new ODataNotFoundException(null, e);
- } catch (InvocationTargetException e) {
- throw new ODataNotFoundException(null, e);
- }
- }
-
- private <T> Class<?> getType(final T data, final String methodName) throws ODataNotFoundException {
- if (data == null) {
- throw new ODataNotFoundException(ODataHttpException.COMMON);
- }
-
- Class<?> type = data.getClass();
- for (final String method : methodName.split("\\.", -1)) {
- try {
- type = type.getMethod(method).getReturnType();
- if (type.isPrimitive()) {
- if (type == boolean.class) {
- type = Boolean.class;
- } else if (type == byte.class) {
- type = Byte.class;
- } else if (type == short.class) {
- type = Short.class;
- } else if (type == int.class) {
- type = Integer.class;
- } else if (type == long.class) {
- type = Long.class;
- } else if (type == float.class) {
- type = Float.class;
- } else if (type == double.class) {
- type = Double.class;
- }
- }
- } catch (final SecurityException e) {
- throw new ODataNotFoundException(ODataHttpException.COMMON, e);
- } catch (final NoSuchMethodException e) {
- throw new ODataNotFoundException(ODataHttpException.COMMON, e);
- }
- }
- return type;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d83070de/odata2-lib/odata-ref/src/main/java/org/apache/olingo/odata2/ref/processor/ListsDataSource.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-ref/src/main/java/org/apache/olingo/odata2/ref/processor/ListsDataSource.java b/odata2-lib/odata-ref/src/main/java/org/apache/olingo/odata2/ref/processor/ListsDataSource.java
deleted file mode 100644
index 3e24bee..0000000
--- a/odata2-lib/odata-ref/src/main/java/org/apache/olingo/odata2/ref/processor/ListsDataSource.java
+++ /dev/null
@@ -1,200 +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.ref.processor;
-
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.olingo.odata2.api.edm.EdmEntitySet;
-import org.apache.olingo.odata2.api.edm.EdmException;
-import org.apache.olingo.odata2.api.edm.EdmFunctionImport;
-import org.apache.olingo.odata2.api.exception.ODataApplicationException;
-import org.apache.olingo.odata2.api.exception.ODataNotFoundException;
-import org.apache.olingo.odata2.api.exception.ODataNotImplementedException;
-
-/**
- * <p>This interface is intended to make it easier to implement an OData
- * service in cases where all data for each entity set can be provided as a {@link List} of objects from which all
- * properties described in the
- * Entity Data Model can be retrieved and set.</p>
- * <p>By obeying these restrictions, data-source implementations get the
- * following advantages:
- * <ul>
- * <li>All system query options can be handled centrally.</li>
- * <li>Following navigation paths must only be done step by step.</li>
- * </ul>
- * </p>
- *
- */
-public interface ListsDataSource {
-
- /**
- * Retrieves the whole data list for the specified entity set.
- * @param entitySet the requested {@link EdmEntitySet}
- * @return the requested data list
- */
- List<?> readData(EdmEntitySet entitySet) throws ODataNotImplementedException, ODataNotFoundException, EdmException,
- ODataApplicationException;
-
- /**
- * Retrieves a single data object for the specified entity set and key.
- * @param entitySet the requested {@link EdmEntitySet}
- * @param keys the entity key as map of key names to key values
- * @return the requested data object
- */
- Object readData(EdmEntitySet entitySet, Map<String, Object> keys) throws ODataNotImplementedException,
- ODataNotFoundException, EdmException, ODataApplicationException;
-
- /**
- * <p>Retrieves data for the specified function import and key.</p>
- * <p>This method is called also for function imports that have defined in
- * their metadata an other HTTP method than <code>GET</code>.</p>
- * @param function the requested {@link EdmFunctionImport}
- * @param parameters the parameters of the function import
- * as map of parameter names to parameter values
- * @param keys the key of the returned entity set, as map of key names to key values,
- * if the return type of the function import is a collection of entities
- * (optional)
- * @return the requested data object, either a list or a single object;
- * if the function import's return type is of type <code>Binary</code>,
- * the returned object(s) must be of type {@link BinaryData}
- */
- Object readData(EdmFunctionImport function, Map<String, Object> parameters, Map<String, Object> keys)
- throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException;
-
- /**
- * <p>Retrieves related data for the specified source data, entity set, and key.</p>
- * <p>If the underlying association of the EDM is specified to have target
- * multiplicity '*' and no target key is given, this method returns a list of
- * related data, otherwise it returns a single data object.</p>
- * @param sourceEntitySet the {@link EdmEntitySet} of the source entity
- * @param sourceData the data object of the source entity
- * @param targetEntitySet the requested target {@link EdmEntitySet}
- * @param targetKeys the key of the target entity as map of key names to key values
- * (optional)
- * @return the requested releated data object, either a list or a single object
- */
- Object readRelatedData(EdmEntitySet sourceEntitySet, Object sourceData, EdmEntitySet targetEntitySet,
- Map<String, Object> targetKeys) throws ODataNotImplementedException, ODataNotFoundException, EdmException,
- ODataApplicationException;
-
- /**
- * Retrieves the binary data and the MIME type for the media resource
- * associated to the specified media-link entry.
- * @param entitySet the {@link EdmEntitySet} of the media-link entry
- * @param mediaLinkEntryData the data object of the media-link entry
- * @return the binary data and the MIME type of the media resource
- */
- BinaryData readBinaryData(EdmEntitySet entitySet, Object mediaLinkEntryData) throws ODataNotImplementedException,
- ODataNotFoundException, EdmException, ODataApplicationException;
-
- /**
- * <p>Creates and returns a new instance of the requested data-object type.</p>
- * <p>This instance must not be part of the corresponding list and should
- * have empty content, apart from the key and other mandatory properties.
- * However, intermediate objects to access complex properties must not be
- * <code>null</code>.</p>
- * @param entitySet the {@link EdmEntitySet} the object must correspond to
- * @return the new data object
- */
- Object newDataObject(EdmEntitySet entitySet) throws ODataNotImplementedException, EdmException,
- ODataApplicationException;
-
- /**
- * Writes the binary data for the media resource associated to the
- * specified media-link entry.
- * @param entitySet the {@link EdmEntitySet} of the media-link entry
- * @param mediaLinkEntryData the data object of the media-link entry
- * @param binaryData the binary data of the media resource along with
- * the MIME type of the binary data
- */
- void writeBinaryData(EdmEntitySet entitySet, Object mediaLinkEntryData, BinaryData binaryData)
- throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException;
-
- /**
- * Deletes a single data object identified by the specified entity set and key.
- * @param entitySet the {@link EdmEntitySet} of the entity to be deleted
- * @param keys the entity key as map of key names to key values
- */
- void deleteData(EdmEntitySet entitySet, Map<String, Object> keys) throws ODataNotImplementedException,
- ODataNotFoundException, EdmException, ODataApplicationException;
-
- /**
- * <p>Inserts an instance into the entity list of the specified entity set.</p>
- * <p>If {@link #newDataObject} has not set the key and other mandatory
- * properties already, this method must set them before inserting the
- * instance into the list.</p>
- * @param entitySet the {@link EdmEntitySet} the object must correspond to
- * @param data the data object of the new entity
- */
- void createData(EdmEntitySet entitySet, Object data) throws ODataNotImplementedException, EdmException,
- ODataApplicationException;
-
- /**
- * Deletes the relation from the specified source data to a target entity
- * specified by entity set and key.
- * @param sourceEntitySet the {@link EdmEntitySet} of the source entity
- * @param sourceData the data object of the source entity
- * @param targetEntitySet the {@link EdmEntitySet} of the target entity
- * @param targetKeys the key of the target entity as map of key names to key values
- * (optional)
- */
- void deleteRelation(EdmEntitySet sourceEntitySet, Object sourceData, EdmEntitySet targetEntitySet,
- Map<String, Object> targetKeys) throws ODataNotImplementedException, ODataNotFoundException, EdmException,
- ODataApplicationException;
-
- /**
- * Writes a relation from the specified source data to a target entity
- * specified by entity set and key.
- * @param sourceEntitySet the {@link EdmEntitySet} of the source entity
- * @param sourceData the data object of the source entity
- * @param targetEntitySet the {@link EdmEntitySet} of the relation target
- * @param targetKeys the key of the target entity as map of key names to key values
- */
- void writeRelation(EdmEntitySet sourceEntitySet, Object sourceData, EdmEntitySet targetEntitySet,
- Map<String, Object> targetKeys) throws ODataNotImplementedException, ODataNotFoundException, EdmException,
- ODataApplicationException;
-
- /**
- * Container to store binary data (as byte array) and the associated MIME type.
- */
- public class BinaryData {
- private final byte[] data;
- private final String mimeType;
-
- public BinaryData(final byte[] data, final String mimeType) {
- this.data = data;
- this.mimeType = mimeType;
- }
-
- public byte[] getData() {
- return data;
- }
-
- public String getMimeType() {
- return mimeType;
- }
-
- @Override
- public String toString() {
- return "data=" + Arrays.toString(data) + ", mimeType=" + mimeType;
- }
- }
-}
[08/52] git commit: Minor changes for OLINGO-30
Posted by mi...@apache.org.
Minor changes for OLINGO-30
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/f614199c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/f614199c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/f614199c
Branch: refs/heads/master
Commit: f614199c6986fb774da69a4934b1ddff9a3e1b2e
Parents: 5ab0c60
Author: Michael Bolz <mi...@apache.org>
Authored: Tue Oct 15 11:04:38 2013 +0200
Committer: Michael Bolz <mi...@sap.com>
Committed: Tue Oct 15 21:58:25 2013 +0200
----------------------------------------------------------------------
.../olingo/odata2/api/edm/EdmMapping.java | 1 +
.../olingo/odata2/api/edm/provider/Mapping.java | 9 ++++++--
.../api/ep/EntityProviderWriteProperties.java | 6 ++++-
.../odata2/ref/edm/ScenarioEdmProvider.java | 4 ++--
.../odata2/ref/processor/ListsProcessor.java | 24 ++++++++++++++++----
5 files changed, 34 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/f614199c/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/edm/EdmMapping.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/edm/EdmMapping.java b/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/edm/EdmMapping.java
index c810fca..2c1116d 100644
--- a/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/edm/EdmMapping.java
+++ b/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/edm/EdmMapping.java
@@ -36,6 +36,7 @@ public interface EdmMapping {
* Get the mapping name for mime type lookup
*
* @return mapping name as String
+ * @deprecated use instead functionality of {@link #getMediaResourceMimeTypeKey()} method
*/
@Deprecated
String getMimeType();
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/f614199c/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/edm/provider/Mapping.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/edm/provider/Mapping.java b/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/edm/provider/Mapping.java
index 4cdb6de..12a6166 100644
--- a/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/edm/provider/Mapping.java
+++ b/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/edm/provider/Mapping.java
@@ -71,6 +71,7 @@ public class Mapping implements EdmMapping {
* Sets the mime type for this {@link Mapping}.
* @param mimeType
* @return {@link Mapping} for method chaining
+ * @deprecated use instead functionality of {@link #setMediaResourceMimeTypeKey(String)} method
*/
@Deprecated
public Mapping setMimeType(final String mimeType) {
@@ -91,17 +92,21 @@ public class Mapping implements EdmMapping {
/**
* Sets the key for the resource source key which is used for the lookup in the data map
* @param mediaResourceSourceKey under which the source can be found in the data map
+ * @return {@link Mapping} for method chaining
*/
- public void setMediaResourceSourceKey(String mediaResourceSourceKey) {
+ public Mapping setMediaResourceSourceKey(String mediaResourceSourceKey) {
this.mediaResourceSourceKey = mediaResourceSourceKey;
+ return this;
}
/**
* Sets the key for the resource mime type key which is used for the lookup in the data map
* @param mediaResourceMimeTypeKey under which the mime type can be found in the data map
+ * @return {@link Mapping} for method chaining
*/
- public void setMediaResourceMimeTypeKey(String mediaResourceMimeTypeKey) {
+ public Mapping setMediaResourceMimeTypeKey(String mediaResourceMimeTypeKey) {
this.mediaResourceMimeTypeKey = mediaResourceMimeTypeKey;
+ return this;
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/f614199c/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/ep/EntityProviderWriteProperties.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/ep/EntityProviderWriteProperties.java b/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/ep/EntityProviderWriteProperties.java
index 2a7e978..f212810 100644
--- a/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/ep/EntityProviderWriteProperties.java
+++ b/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/ep/EntityProviderWriteProperties.java
@@ -64,6 +64,8 @@ public class EntityProviderWriteProperties {
/**
* Gets the MIME type of the media resource.
* @return the MIME type of the media resource
+ * @deprecated use instead the functionality of 'EdmMapping -> mediaResourceMimeTypeKey' to reference via a key
+ * to the 'mime type' of the media resource provided in the entity data map
*/
@Deprecated
public final String getMediaResourceMimeType() {
@@ -84,7 +86,7 @@ public class EntityProviderWriteProperties {
/**
* Gets the expand select tree data structure resulting from $expand and $select query options.
- * @return a paresed tree structure representing the $expand and $select
+ * @return a parsed tree structure representing the $expand and $select
*/
public final ExpandSelectTreeNode getExpandSelectTree() {
return expandSelectTree;
@@ -117,6 +119,8 @@ public class EntityProviderWriteProperties {
/**
* @param mediaResourceMimeType the mediaResourceMimeType to set
+ * @deprecated use instead the functionality of 'EdmMapping -> mediaResourceMimeTypeKey' to reference via a key
+ * to the 'mime type' of the media resource provided in the entity data map
*/
@Deprecated
public final ODataEntityProviderPropertiesBuilder mediaResourceMimeType(final String mediaResourceMimeType) {
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/f614199c/odata2-lib/odata-ref/src/main/java/org/apache/olingo/odata2/ref/edm/ScenarioEdmProvider.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-ref/src/main/java/org/apache/olingo/odata2/ref/edm/ScenarioEdmProvider.java b/odata2-lib/odata-ref/src/main/java/org/apache/olingo/odata2/ref/edm/ScenarioEdmProvider.java
index b3cf662..c57b06c 100644
--- a/odata2-lib/odata-ref/src/main/java/org/apache/olingo/odata2/ref/edm/ScenarioEdmProvider.java
+++ b/odata2-lib/odata-ref/src/main/java/org/apache/olingo/odata2/ref/edm/ScenarioEdmProvider.java
@@ -215,7 +215,7 @@ public class ScenarioEdmProvider extends EdmProvider {
.setHasStream(true)
.setKey(getKey("EmployeeId"))
.setNavigationProperties(navigationProperties)
- .setMapping(new Mapping().setMimeType("getImageType"));
+ .setMapping(new Mapping().setMimeType("getImageType").setMediaResourceMimeTypeKey("~mrmtk"));
} else if (ENTITY_TYPE_1_BASE.getName().equals(edmFQName.getName())) {
List<Property> properties = new ArrayList<Property>();
@@ -315,7 +315,7 @@ public class ScenarioEdmProvider extends EdmProvider {
.setProperties(properties)
.setHasStream(true)
.setKey(getKey("Id", "Type"))
- .setMapping(new Mapping().setMimeType("getType"));
+ .setMapping(new Mapping().setMimeType("getType").setMediaResourceMimeTypeKey("~MediaResourceMimeTypeKey"));
}
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/f614199c/odata2-lib/odata-ref/src/main/java/org/apache/olingo/odata2/ref/processor/ListsProcessor.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-ref/src/main/java/org/apache/olingo/odata2/ref/processor/ListsProcessor.java b/odata2-lib/odata-ref/src/main/java/org/apache/olingo/odata2/ref/processor/ListsProcessor.java
index 901fe59..58009d9 100644
--- a/odata2-lib/odata-ref/src/main/java/org/apache/olingo/odata2/ref/processor/ListsProcessor.java
+++ b/odata2-lib/odata-ref/src/main/java/org/apache/olingo/odata2/ref/processor/ListsProcessor.java
@@ -46,6 +46,7 @@ import org.apache.olingo.odata2.api.edm.EdmException;
import org.apache.olingo.odata2.api.edm.EdmFunctionImport;
import org.apache.olingo.odata2.api.edm.EdmLiteral;
import org.apache.olingo.odata2.api.edm.EdmLiteralKind;
+import org.apache.olingo.odata2.api.edm.EdmMapping;
import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
import org.apache.olingo.odata2.api.edm.EdmNavigationProperty;
import org.apache.olingo.odata2.api.edm.EdmProperty;
@@ -1518,13 +1519,26 @@ public class ListsProcessor extends ODataSingleProcessor {
null : getterMethodName.replaceFirst("^is", "set").replaceFirst("^get", "set");
}
+ private static void handleMimeType(Object data, EdmMapping mapping, Map<String, Object> valueMap)
+ throws ODataNotFoundException {
+ final String methodName = mapping.getMimeType();
+ if (mapping.getMimeType() != null) {
+ Object value = getValue(data, methodName);
+ valueMap.put(methodName, value);
+ if(mapping.getMediaResourceMimeTypeKey() != null) {
+ valueMap.put(mapping.getMediaResourceMimeTypeKey(), value);
+ }
+ }
+ }
+
private static <T> Map<String, Object> getSimpleTypeValueMap(final T data, final List<EdmProperty> propertyPath)
throws ODataException {
final EdmProperty property = propertyPath.get(propertyPath.size() - 1);
Map<String, Object> valueWithMimeType = new HashMap<String, Object>();
valueWithMimeType.put(property.getName(), getPropertyValue(data, propertyPath));
- final String mimeTypeMappingName = property.getMapping().getMimeType();
- valueWithMimeType.put(mimeTypeMappingName, getValue(data, mimeTypeMappingName));
+
+ handleMimeType(data, property.getMapping(), valueWithMimeType);
+
return valueWithMimeType;
}
@@ -1535,9 +1549,9 @@ public class ListsProcessor extends ODataSingleProcessor {
Map<String, Object> valueMap = new HashMap<String, Object>();
- if (type.getMapping() != null && type.getMapping().getMimeType() != null) {
- final String methodName = type.getMapping().getMimeType();
- valueMap.put(methodName, getValue(data, methodName));
+ EdmMapping mapping = type.getMapping();
+ if (mapping != null) {
+ handleMimeType(data, mapping, valueMap);
}
for (final String propertyName : type.getPropertyNames()) {
[03/52] git commit: Initial EdmAnnotation contribution
Posted by mi...@apache.org.
Initial EdmAnnotation contribution
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/ae7c1f52
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/ae7c1f52
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/ae7c1f52
Branch: refs/heads/master
Commit: ae7c1f52d812cd70354a9933e3b3cb3d61aa3186
Parents: 7ef5a9b
Author: Michael Bolz <mi...@sap.com>
Authored: Wed Oct 9 21:37:03 2013 +0200
Committer: Michael Bolz <mi...@sap.com>
Committed: Thu Oct 10 13:49:47 2013 +0200
----------------------------------------------------------------------
.gitignore | 1 +
.../edm-annotation-api/pom.xml | 42 ++
.../api/annotation/edm/EdmComplexEntity.java | 31 +
.../api/annotation/edm/EdmComplexProperty.java | 32 +
.../odata2/api/annotation/edm/EdmEntitySet.java | 31 +
.../api/annotation/edm/EdmEntityType.java | 31 +
.../odata2/api/annotation/edm/EdmKey.java | 29 +
.../annotation/edm/EdmNavigationProperty.java | 36 +
.../odata2/api/annotation/edm/EdmProperty.java | 33 +
.../odata2/api/annotation/edm/Facets.java | 36 +
.../api/annotation/edm/NavigationEnd.java | 34 +
.../api/annotation/edm/ds/EntityCreate.java | 29 +
.../api/annotation/edm/ds/EntityDataSource.java | 32 +
.../api/annotation/edm/ds/EntityDelete.java | 29 +
.../api/annotation/edm/ds/EntityRead.java | 29 +
.../api/annotation/edm/ds/EntitySetRead.java | 29 +
.../api/annotation/edm/ds/EntityUpdate.java | 29 +
.../edm-annotation-core/pom.xml | 41 ++
.../annotation/edm/AnnotationEdmProvider.java | 737 +++++++++++++++++++
.../core/annotation/edm/AnnotationHelper.java | 62 ++
.../odata2/core/annotation/edm/ClassHelper.java | 104 +++
.../processor/AnnotationProcessor.java | 439 +++++++++++
.../processor/json/EdmAnnotationSerializer.java | 215 ++++++
.../annotation/processor/json/JsonConsumer.java | 136 ++++
.../annotation/processor/json/JsonWriter.java | 256 +++++++
.../src/main/resources/log4j.xml | 39 +
.../edm/AnnotationEdmProviderTest.java | 318 ++++++++
.../odata2/core/annotation/model/Building.java | 100 +++
.../odata2/core/annotation/model/City.java | 61 ++
.../odata2/core/annotation/model/Employee.java | 181 +++++
.../odata2/core/annotation/model/Location.java | 61 ++
.../odata2/core/annotation/model/Manager.java | 46 ++
.../annotation/model/ModelSharedConstants.java | 25 +
.../odata2/core/annotation/model/Photo.java | 130 ++++
.../odata2/core/annotation/model/RefBase.java | 55 ++
.../odata2/core/annotation/model/Room.java | 93 +++
.../odata2/core/annotation/model/Team.java | 83 +++
.../processor/json/JsonConsumerTest.java | 85 +++
.../edm-annotation-webref/pom.xml | 125 ++++
.../odata2/ref/annotation/model/Building.java | 99 +++
.../odata2/ref/annotation/model/City.java | 61 ++
.../ref/annotation/model/DataContainer.java | 290 ++++++++
.../odata2/ref/annotation/model/Employee.java | 189 +++++
.../odata2/ref/annotation/model/Location.java | 61 ++
.../odata2/ref/annotation/model/Manager.java | 46 ++
.../ref/annotation/model/ModelException.java | 32 +
.../annotation/model/ModelSharedConstants.java | 25 +
.../odata2/ref/annotation/model/Photo.java | 131 ++++
.../odata2/ref/annotation/model/RefBase.java | 57 ++
.../ref/annotation/model/ResourceHelper.java | 61 ++
.../odata2/ref/annotation/model/Room.java | 97 +++
.../odata2/ref/annotation/model/Team.java | 83 +++
.../ref/annotation/model/ds/BuildingDs.java | 67 ++
.../odata2/ref/annotation/model/ds/TeamDs.java | 66 ++
.../processor/ScenarioErrorCallback.java | 47 ++
.../processor/ScenarioServiceFactory.java | 97 +++
.../src/main/resources/log4j.xml | 39 +
.../src/main/version/version.html | 27 +
.../src/main/webapp/META-INF/context.xml | 2 +
.../src/main/webapp/WEB-INF/web.xml | 48 ++
.../src/main/webapp/index.jsp | 111 +++
odata2-edm-annotation/pom.xml | 30 +
pom.xml | 1 +
63 files changed, 5672 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ae7c1f52/.gitignore
----------------------------------------------------------------------
diff --git a/.gitignore b/.gitignore
index 9c201f5..3f1a76b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,3 +7,4 @@ bin
*.bak
classes
.DS_Store
+nb-configuration.xml
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ae7c1f52/odata2-edm-annotation/edm-annotation-api/pom.xml
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-api/pom.xml b/odata2-edm-annotation/edm-annotation-api/pom.xml
new file mode 100644
index 0000000..5d697f2
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-api/pom.xml
@@ -0,0 +1,42 @@
+<?xml version="1.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.
+-->
+<project
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
+ xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.olingo</groupId>
+ <artifactId>olingo-odata2-edm-annotation-incubating</artifactId>
+ <version>1.1.0-SNAPSHOT</version>
+ <relativePath>..</relativePath>
+ </parent>
+
+ <artifactId>olingo-odata2-edm-annotation-api-incubating</artifactId>
+ <name>${project.artifactId}</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.olingo</groupId>
+ <artifactId>olingo-odata2-api-incubating</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ae7c1f52/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmComplexEntity.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmComplexEntity.java b/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmComplexEntity.java
new file mode 100644
index 0000000..adec2d7
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmComplexEntity.java
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * 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.api.annotation.edm;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.TYPE)
+public @interface EdmComplexEntity {
+ String name() default "";
+ String namespace();
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ae7c1f52/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmComplexProperty.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmComplexProperty.java b/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmComplexProperty.java
new file mode 100644
index 0000000..3af0227
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmComplexProperty.java
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * 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.api.annotation.edm;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.FIELD)
+public @interface EdmComplexProperty {
+ String name() default "";
+ String namespace() default "";
+ String facet() default "";
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ae7c1f52/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmEntitySet.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmEntitySet.java b/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmEntitySet.java
new file mode 100644
index 0000000..b62d986
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmEntitySet.java
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * 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.api.annotation.edm;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.TYPE)
+public @interface EdmEntitySet {
+ String name();
+ String container();
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ae7c1f52/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmEntityType.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmEntityType.java b/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmEntityType.java
new file mode 100644
index 0000000..67a363d
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmEntityType.java
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * 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.api.annotation.edm;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.TYPE)
+public @interface EdmEntityType {
+ String name() default "";
+ String namespace();
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ae7c1f52/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmKey.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmKey.java b/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmKey.java
new file mode 100644
index 0000000..48db91f
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmKey.java
@@ -0,0 +1,29 @@
+/*******************************************************************************
+ * 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.api.annotation.edm;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.FIELD)
+public @interface EdmKey {
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ae7c1f52/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmNavigationProperty.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmNavigationProperty.java b/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmNavigationProperty.java
new file mode 100644
index 0000000..cf898df
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmNavigationProperty.java
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * 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.api.annotation.edm;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.FIELD)
+public @interface EdmNavigationProperty {
+ String name();
+ String relationship();
+
+ //
+ NavigationEnd from() default @NavigationEnd;
+ NavigationEnd to() default @NavigationEnd;
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ae7c1f52/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmProperty.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmProperty.java b/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmProperty.java
new file mode 100644
index 0000000..68c411b
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmProperty.java
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * 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.api.annotation.edm;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.FIELD)
+public @interface EdmProperty {
+ EdmSimpleTypeKind type() default EdmSimpleTypeKind.Null;
+ String name() default "";
+ String facet() default "";
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ae7c1f52/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/Facets.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/Facets.java b/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/Facets.java
new file mode 100644
index 0000000..24a3be6
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/Facets.java
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * 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.api.annotation.edm;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.ANNOTATION_TYPE)
+public @interface Facets {
+ int maxLength() default 0;
+
+ int scale() default -1;
+
+ int precision() default 0;
+
+ boolean nullable() default false;
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ae7c1f52/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/NavigationEnd.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/NavigationEnd.java b/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/NavigationEnd.java
new file mode 100644
index 0000000..2ce5ef1
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/NavigationEnd.java
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * 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.api.annotation.edm;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.FIELD)
+public @interface NavigationEnd {
+ String role() default "";
+ String type() default "";
+
+ EdmMultiplicity multiplicity() default EdmMultiplicity.ONE;
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ae7c1f52/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/ds/EntityCreate.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/ds/EntityCreate.java b/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/ds/EntityCreate.java
new file mode 100644
index 0000000..529ee63
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/ds/EntityCreate.java
@@ -0,0 +1,29 @@
+/*******************************************************************************
+ * 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.api.annotation.edm.ds;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.METHOD)
+public @interface EntityCreate {
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ae7c1f52/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/ds/EntityDataSource.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/ds/EntityDataSource.java b/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/ds/EntityDataSource.java
new file mode 100644
index 0000000..aa2aff6
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/ds/EntityDataSource.java
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * 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.api.annotation.edm.ds;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.TYPE)
+public @interface EntityDataSource {
+ String name() default "";
+ Class<?> entityClass() default Object.class;
+ Class<?> entityType();
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ae7c1f52/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/ds/EntityDelete.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/ds/EntityDelete.java b/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/ds/EntityDelete.java
new file mode 100644
index 0000000..f852307
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/ds/EntityDelete.java
@@ -0,0 +1,29 @@
+/*******************************************************************************
+ * 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.api.annotation.edm.ds;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.METHOD)
+public @interface EntityDelete {
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ae7c1f52/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/ds/EntityRead.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/ds/EntityRead.java b/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/ds/EntityRead.java
new file mode 100644
index 0000000..76333ca
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/ds/EntityRead.java
@@ -0,0 +1,29 @@
+/*******************************************************************************
+ * 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.api.annotation.edm.ds;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.METHOD)
+public @interface EntityRead {
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ae7c1f52/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/ds/EntitySetRead.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/ds/EntitySetRead.java b/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/ds/EntitySetRead.java
new file mode 100644
index 0000000..79cb80c
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/ds/EntitySetRead.java
@@ -0,0 +1,29 @@
+/*******************************************************************************
+ * 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.api.annotation.edm.ds;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.METHOD)
+public @interface EntitySetRead {
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ae7c1f52/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/ds/EntityUpdate.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/ds/EntityUpdate.java b/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/ds/EntityUpdate.java
new file mode 100644
index 0000000..6aea1eb
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/ds/EntityUpdate.java
@@ -0,0 +1,29 @@
+/*******************************************************************************
+ * 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.api.annotation.edm.ds;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.METHOD)
+public @interface EntityUpdate {
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ae7c1f52/odata2-edm-annotation/edm-annotation-core/pom.xml
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/pom.xml b/odata2-edm-annotation/edm-annotation-core/pom.xml
new file mode 100644
index 0000000..4f34c8d
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-core/pom.xml
@@ -0,0 +1,41 @@
+<?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-edm-annotation-core-incubating</artifactId>
+ <packaging>jar</packaging>
+ <name>${project.artifactId}</name>
+
+ <parent>
+ <groupId>org.apache.olingo</groupId>
+ <artifactId>olingo-odata2-edm-annotation-incubating</artifactId>
+ <version>1.1.0-SNAPSHOT</version>
+ <relativePath>..</relativePath>
+ </parent>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.olingo</groupId>
+ <artifactId>olingo-odata2-edm-annotation-api-incubating</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.olingo</groupId>
+ <artifactId>olingo-odata2-api-incubating</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.olingo</groupId>
+ <artifactId>olingo-odata2-core-incubating</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ae7c1f52/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java
new file mode 100644
index 0000000..419eedd
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java
@@ -0,0 +1,737 @@
+/*******************************************************************************
+ * 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.core.annotation.edm;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.olingo.odata2.api.annotation.edm.EdmComplexEntity;
+import org.apache.olingo.odata2.api.annotation.edm.EdmComplexProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
+import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
+import org.apache.olingo.odata2.api.annotation.edm.NavigationEnd;
+import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
+import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
+import org.apache.olingo.odata2.api.edm.FullQualifiedName;
+import org.apache.olingo.odata2.api.edm.provider.AnnotationAttribute;
+import org.apache.olingo.odata2.api.edm.provider.AnnotationElement;
+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.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.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.Schema;
+import org.apache.olingo.odata2.api.edm.provider.SimpleProperty;
+import org.apache.olingo.odata2.api.edm.provider.Using;
+import org.apache.olingo.odata2.api.exception.ODataException;
+import org.apache.olingo.odata2.core.exception.ODataRuntimeException;
+
+/**
+ * Provider for the entity data model used in the reference scenario
+ *
+ */
+public class AnnotationEdmProvider extends EdmProvider {
+
+ private static final AnnotationHelper ANNOTATION_HELPER = new AnnotationHelper();
+
+ private final List<Class<?>> annotatedClasses;
+ private final Map<String, EntityContainer> name2Container = new HashMap<String, EntityContainer>();
+ private final Map<String, ContainerBuilder> containerName2ContainerBuilder = new HashMap<String, ContainerBuilder>();
+ private final Map<String, Schema> namespace2Schema = new HashMap<String, Schema>();
+ private EntityContainer defaultContainer;
+
+ public AnnotationEdmProvider(Collection<Class<?>> annotatedClasses) {
+
+// this.annotatedClasses = new ArrayList<Class<?>>(annotatedClasses);
+// this.annotatedClasses.addAll(annotatedClasses);
+ this.annotatedClasses = new ArrayList<Class<?>>(annotatedClasses.size());
+ for (Class<?> aClass : annotatedClasses) {
+ if (ANNOTATION_HELPER.isEdmAnnotated(aClass)) {
+ this.annotatedClasses.add(aClass);
+ }
+ }
+
+ init();
+ }
+
+ public AnnotationEdmProvider(String packageToScan) {
+ this.annotatedClasses = ClassHelper.loadClasses(packageToScan, new ClassHelper.ClassValidator() {
+ @Override
+ public boolean isClassValid(Class<?> c) {
+ return ANNOTATION_HELPER.isEdmAnnotated(c);
+ }
+ });
+
+ init();
+ }
+
+ private void init() {
+ for (Class<?> aClass : annotatedClasses) {
+ updateSchema(aClass);
+ handleEntityContainer(aClass);
+ }
+
+ finish();
+ }
+
+ @Override
+ public Association getAssociation(FullQualifiedName edmFQName) throws ODataException {
+ Schema schema = namespace2Schema.get(edmFQName.getNamespace());
+ if (schema != null) {
+ List<Association> associations = schema.getAssociations();
+ for (Association association : associations) {
+ if (association.getName().equals(edmFQName.getName())) {
+ return association;
+ }
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public AssociationSet getAssociationSet(String entityContainer, FullQualifiedName association,
+ String sourceEntitySetName, String sourceEntitySetRole) throws ODataException {
+ EntityContainer container = name2Container.get(entityContainer);
+ if (container != null) {
+ List<AssociationSet> associations = container.getAssociationSets();
+ for (AssociationSet associationSet : associations) {
+ if (associationSet.getAssociation().equals(association)) {
+ final AssociationSetEnd endOne = associationSet.getEnd1();
+ if (endOne.getRole().equals(sourceEntitySetRole)
+ && endOne.getEntitySet().equals(sourceEntitySetName)) {
+ return associationSet;
+ }
+ final AssociationSetEnd endTwo = associationSet.getEnd2();
+ if (endTwo.getRole().equals(sourceEntitySetRole)
+ && endTwo.getEntitySet().equals(sourceEntitySetName)) {
+ return associationSet;
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public ComplexType getComplexType(FullQualifiedName edmFQName) throws ODataException {
+ Schema schema = namespace2Schema.get(edmFQName.getNamespace());
+ if (schema != null) {
+ List<ComplexType> complexTypes = schema.getComplexTypes();
+ for (ComplexType complexType : complexTypes) {
+ if (complexType.getName().equals(edmFQName.getName())) {
+ return complexType;
+ }
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public EntityContainerInfo getEntityContainerInfo(String name) throws ODataException {
+ EntityContainer container = name2Container.get(name);
+ if (container == null) {
+ // use default container (if set)
+ container = defaultContainer;
+ }
+ if (container != null) {
+ EntityContainerInfo info = new EntityContainerInfo();
+ info.setName(container.getName());
+ info.setDefaultEntityContainer(container.isDefaultEntityContainer());
+ info.setExtendz(container.getExtendz());
+ info.setAnnotationAttributes(container.getAnnotationAttributes());
+ info.setAnnotationElements(container.getAnnotationElements());
+
+ return info;
+ }
+
+ return null;
+ }
+
+ @Override
+ public EntitySet getEntitySet(String entityContainer, String name) throws ODataException {
+ EntityContainer container = name2Container.get(entityContainer);
+ if (container != null) {
+ List<EntitySet> entitySets = container.getEntitySets();
+ for (EntitySet entitySet : entitySets) {
+ if (entitySet.getName().equals(name)) {
+ return entitySet;
+ }
+ }
+ }
+
+ return null;
+ }
+
+ @Override
+ public EntityType getEntityType(FullQualifiedName edmFQName) throws ODataException {
+ Schema schema = namespace2Schema.get(edmFQName.getNamespace());
+ if (schema != null) {
+ List<EntityType> complexTypes = schema.getEntityTypes();
+ for (EntityType complexType : complexTypes) {
+ if (complexType.getName().equals(edmFQName.getName())) {
+ return complexType;
+ }
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public FunctionImport getFunctionImport(String entityContainer, String name) throws ODataException {
+ EntityContainer container = name2Container.get(entityContainer);
+ if (container != null) {
+ List<FunctionImport> functionImports = container.getFunctionImports();
+ for (FunctionImport functionImport : functionImports) {
+ if (functionImport.getName().equals(name)) {
+ return functionImport;
+ }
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public List<Schema> getSchemas() throws ODataException {
+ return new ArrayList<Schema>(namespace2Schema.values());
+ }
+
+ //
+ //
+ //
+ private Map<String, SchemaBuilder> namespace2SchemaBuilder = new HashMap<String, SchemaBuilder>();
+
+ private void updateSchema(Class<?> aClass) {
+ EdmEntityType et = aClass.getAnnotation(EdmEntityType.class);
+ if (et != null) {
+ updateSchema(aClass, et);
+ }
+ EdmComplexEntity ect = aClass.getAnnotation(EdmComplexEntity.class);
+ if (ect != null) {
+ updateSchema(aClass, ect);
+ }
+ }
+
+ private void updateSchema(Class<?> aClass, EdmEntityType et) {
+ String namespace = et.namespace();
+ SchemaBuilder b = namespace2SchemaBuilder.get(namespace);
+ if (b == null) {
+ b = SchemaBuilder.init(namespace);
+ namespace2SchemaBuilder.put(namespace, b);
+ }
+ TypeBuilder typeBuilder = TypeBuilder.init(et, aClass);
+ b.addEntityType(typeBuilder.buildEntityType());
+ b.addAssociations(typeBuilder.buildAssociations());
+ }
+
+ private void updateSchema(Class<?> aClass, EdmComplexEntity et) {
+ String namespace = et.namespace();
+ SchemaBuilder b = namespace2SchemaBuilder.get(namespace);
+ if (b == null) {
+ b = SchemaBuilder.init(namespace);
+ namespace2SchemaBuilder.put(namespace, b);
+ }
+ TypeBuilder typeBuilder = TypeBuilder.init(et, aClass);
+ b.addComplexType(typeBuilder.buildComplexType());
+ }
+
+ private void handleEntityContainer(Class<?> aClass) {
+ EdmEntitySet entitySet = aClass.getAnnotation(EdmEntitySet.class);
+ if (entitySet != null) {
+ EdmEntityType entity = aClass.getAnnotation(EdmEntityType.class);
+ String containerName = entitySet.container();
+ ContainerBuilder builder = containerName2ContainerBuilder.get(containerName);
+ if (builder == null) {
+ builder = ContainerBuilder.init(entity.namespace(), containerName);
+ containerName2ContainerBuilder.put(containerName, builder);
+ }
+ builder.addEntitySet(createEntitySet(entitySet, entity));
+ }
+ }
+
+ private EntitySet createEntitySet(EdmEntitySet et, EdmEntityType entity) {
+ String name = et.name();
+ FullQualifiedName typeName = new FullQualifiedName(entity.namespace(), entity.name());
+
+ return new EntitySet().setName(name).setEntityType(typeName);
+ }
+
+ private void finish() {
+ //
+ Collection<ContainerBuilder> containers = containerName2ContainerBuilder.values();
+ for (ContainerBuilder containerBuilder : containers) {
+ SchemaBuilder schemaBuilder = namespace2SchemaBuilder.get(containerBuilder.getNamespace());
+ containerBuilder.addAssociationSets(schemaBuilder.name2Associations.values());
+ final EntityContainer container = containerBuilder.build();
+ schemaBuilder.addEntityContainer(container);
+ name2Container.put(container.getName(), container);
+ if (container.isDefaultEntityContainer()) {
+ defaultContainer = container;
+ }
+ }
+ //
+ Collection<SchemaBuilder> schemaBuilders = namespace2SchemaBuilder.values();
+ for (SchemaBuilder schemaBuilder : schemaBuilders) {
+ final Schema schema = schemaBuilder.build();
+ namespace2Schema.put(schema.getNamespace(), schema);
+ }
+ }
+
+ //
+ //
+ //
+ static class TypeBuilder {
+
+ final private String namespace;
+ final private String name;
+ private boolean isAbstract = false;
+ private FullQualifiedName baseEntityType = null;
+ private final List<PropertyRef> keyProperties = new ArrayList<PropertyRef>();
+ private final List<Property> properties = new ArrayList<Property>();
+ private final List<NavigationProperty> navProperties = new ArrayList<NavigationProperty>();
+ private final List<Association> associations = new ArrayList<Association>();
+
+ public TypeBuilder(String namespace, String name) {
+ this.namespace = namespace;
+ this.name = name;
+ }
+
+ public static TypeBuilder init(EdmEntityType entity, Class<?> aClass) {
+ return new TypeBuilder(entity.namespace(), entity.name()).withClass(aClass);
+ }
+
+ public static TypeBuilder init(EdmComplexEntity entity, Class<?> aClass) {
+ return new TypeBuilder(entity.namespace(), entity.name()).withClass(aClass);
+ }
+
+ private TypeBuilder withClass(Class<?> aClass) {
+ baseEntityType = createBaseEntityFqn(aClass);
+
+ if (Modifier.isAbstract(aClass.getModifiers())) {
+ this.isAbstract = true;
+ }
+
+ Field[] fields = aClass.getDeclaredFields();
+ for (Field field : fields) {
+ EdmProperty ep = field.getAnnotation(EdmProperty.class);
+ if (ep != null) {
+ properties.add(createProperty(ep, field));
+ EdmKey eti = field.getAnnotation(EdmKey.class);
+ if (eti != null) {
+ keyProperties.add(createKeyProperty(ep, field));
+ }
+ }
+ EdmComplexProperty ecp = field.getAnnotation(EdmComplexProperty.class);
+ if (ecp != null) {
+ properties.add(createComplexProperty(ecp, field, namespace));
+ }
+ EdmNavigationProperty enp = field.getAnnotation(EdmNavigationProperty.class);
+ if (enp != null) {
+ final NavigationProperty navProperty = createNavigationProperty(namespace, enp, field);
+ navProperties.add(navProperty);
+ Association association = createAssociation(field, navProperty);
+ associations.add(association);
+ }
+ }
+
+ return this;
+ }
+
+ public TypeBuilder addProperty(PropertyRef property) {
+ keyProperties.add(property);
+ return this;
+ }
+
+ public TypeBuilder addProperty(Property property) {
+ properties.add(property);
+ return this;
+ }
+
+ public TypeBuilder addNavigationProperty(NavigationProperty property) {
+ navProperties.add(property);
+ return this;
+ }
+
+ public TypeBuilder setAbstract(boolean isAbstract) {
+ this.isAbstract = isAbstract;
+ return this;
+ }
+
+ public ComplexType buildComplexType() {
+ ComplexType complexType = new ComplexType();
+ if (baseEntityType != null) {
+ complexType.setBaseType(baseEntityType);
+ }
+ return complexType.setName(name)
+ .setProperties(properties);
+ }
+
+ public EntityType buildEntityType() {
+ EntityType entityType = new EntityType();
+ if (baseEntityType != null) {
+ entityType.setBaseType(baseEntityType);
+ }
+ if (!keyProperties.isEmpty()) {
+ entityType.setKey(new Key().setKeys(keyProperties));
+ }
+ if (!navProperties.isEmpty()) {
+ entityType.setNavigationProperties(navProperties);
+ }
+ return entityType.setName(name)
+ .setAbstract(isAbstract)
+ .setProperties(properties);
+ }
+
+ public Collection<Association> buildAssociations() {
+ return Collections.unmodifiableCollection(associations);
+ }
+
+ private PropertyRef createKeyProperty(EdmProperty et, Field field) {
+ PropertyRef keyProperty = new PropertyRef();
+ String entityName = et.name();
+ if (entityName.isEmpty()) {
+ entityName = getCanonicalName(field);
+ }
+ return keyProperty.setName(entityName);
+ }
+
+ private Property createProperty(EdmProperty ep, Field field) {
+ SimpleProperty sp = new SimpleProperty();
+ String entityName = ep.name();
+ if (entityName.isEmpty()) {
+ entityName = getCanonicalName(field);
+ }
+ sp.setName(entityName);
+ //
+ EdmSimpleTypeKind type = ep.type();
+ if (type == EdmSimpleTypeKind.Null) {
+ type = getEdmSimpleType(field.getType());
+ }
+ sp.setType(type);
+
+ return sp;
+ }
+
+ private Property createComplexProperty(EdmComplexProperty ep, Field field, String defaultNamespace) {
+ ComplexProperty cp = new ComplexProperty();
+ String entityName = ep.name();
+ if (entityName.isEmpty()) {
+ entityName = getCanonicalName(field);
+ }
+ cp.setName(entityName);
+ //
+ String entityNamespace = ep.namespace();
+ if (entityNamespace.isEmpty()) {
+ entityNamespace = defaultNamespace;
+ }
+ cp.setType(new FullQualifiedName(entityNamespace, entityName));
+
+ return cp;
+ }
+
+ private NavigationProperty createNavigationProperty(String namespace, EdmNavigationProperty enp, Field field) {
+ NavigationProperty navProp = new NavigationProperty();
+ String entityName = enp.name();
+ if (entityName.isEmpty()) {
+ entityName = getCanonicalName(field);
+ }
+ navProp.setName(entityName);
+ navProp.setRelationship(new FullQualifiedName(namespace, enp.relationship()));
+ //
+ NavigationEnd from = enp.from();
+ String fromRole = from.role();
+ if (fromRole.isEmpty()) {
+ fromRole = getCanonicalRole(field.getDeclaringClass());
+ }
+ navProp.setFromRole(fromRole);
+
+ NavigationEnd to = enp.to();
+ String toRole = to.role();
+ if (toRole.isEmpty()) {
+ toRole = getCanonicalRole(field.getType());
+ }
+ navProp.setToRole(toRole);
+
+ return navProp;
+ }
+
+ private String getCanonicalRole(Class<?> clazz) {
+ return "r_" + clazz.getSimpleName();
+ }
+
+ private EdmSimpleTypeKind getEdmSimpleType(Class<?> type) {
+ if (type == String.class) {
+ return EdmSimpleTypeKind.String;
+ } else if (type == int.class) {
+ return EdmSimpleTypeKind.Int32;
+ } else if (type == Integer.class) {
+ return EdmSimpleTypeKind.Int32;
+ } else {
+ throw new UnsupportedOperationException("Not supported type '" + type
+ + "' yet."); //To change body of generated methods, choose Tools | Templates.
+ }
+ }
+
+ private EdmEntityType checkForBaseEntity(Class<?> aClass) {
+ Class<?> superClass = aClass.getSuperclass();
+ if (superClass == Object.class) {
+ return null;
+ } else {
+ EdmEntityType edmEntity = superClass.getAnnotation(EdmEntityType.class);
+ if (edmEntity == null) {
+ return checkForBaseEntity(superClass);
+ } else {
+ return edmEntity;
+ }
+ }
+ }
+
+ private FullQualifiedName createBaseEntityFqn(Class<?> aClass) {
+ EdmEntityType baseEntity = checkForBaseEntity(aClass);
+ if (baseEntity == null) {
+ return null;
+ }
+ String beName = baseEntity.name();
+ if (beName.isEmpty()) {
+ beName = aClass.getName();
+ }
+ return new FullQualifiedName(baseEntity.namespace(), beName);
+ }
+
+ private Association createAssociation(Field field, NavigationProperty navProperty) {
+ Association a = new Association();
+ a.setName(navProperty.getRelationship().getName());
+ EdmNavigationProperty navigation = field.getAnnotation(EdmNavigationProperty.class);
+
+ NavigationEnd from = navigation.from();
+ AssociationEnd fromEnd = new AssociationEnd();
+ fromEnd.setRole(navProperty.getFromRole());
+ String typeName = from.type();
+ if (typeName.isEmpty()) {
+ typeName = name;
+ }
+ fromEnd.setType(new FullQualifiedName(namespace, typeName));
+ fromEnd.setMultiplicity(from.multiplicity());
+ a.setEnd1(fromEnd);
+
+ NavigationEnd to = navigation.to();
+ AssociationEnd toEnd = new AssociationEnd();
+ toEnd.setRole(navProperty.getToRole());
+ final FullQualifiedName toFqn;
+ if (to.type().isEmpty()) {
+ Class<?> toClass = field.getType();
+ toFqn = new FullQualifiedName(namespace, toClass.getSimpleName());
+ } else {
+ toFqn = new FullQualifiedName(namespace, to.type());
+ }
+ toEnd.setType(toFqn);
+
+ EdmMultiplicity toMultiplicity = to.multiplicity();
+ Class<?> toClass = field.getType();
+ boolean isCollectionType = toClass.isArray() || Collection.class.isAssignableFrom(toClass);
+ if (toMultiplicity == EdmMultiplicity.ONE && isCollectionType) {
+ // XXX: magic, please check and or remove/refactore
+ toEnd.setMultiplicity(EdmMultiplicity.MANY);
+ } else {
+ toEnd.setMultiplicity(toMultiplicity);
+ }
+
+ a.setEnd2(toEnd);
+
+ return a;
+ }
+
+ private String getCanonicalName(Field field) {
+ return ANNOTATION_HELPER.getCanonicalName(field);
+ }
+ }
+
+ static class SchemaBuilder {
+
+ final private String namespace;
+// private String alias;
+ private final List<Using> usings = new ArrayList<Using>();
+ private final List<EntityType> entityTypes = new ArrayList<EntityType>();
+ private final List<ComplexType> complexTypes = new ArrayList<ComplexType>();
+ private final Map<String, Association> name2Associations = new HashMap<String, Association>();
+ private final List<EntityContainer> entityContainers = new ArrayList<EntityContainer>();
+ private final List<AnnotationAttribute> annotationAttributes = new ArrayList<AnnotationAttribute>();
+ private final List<AnnotationElement> annotationElements = new ArrayList<AnnotationElement>();
+
+ private SchemaBuilder(String namespace) {
+ this.namespace = namespace;
+ }
+
+ public static SchemaBuilder init(String namespace) {
+ return new SchemaBuilder(namespace);
+ }
+
+ public SchemaBuilder addEntityType(EntityType type) {
+ entityTypes.add(type);
+ return this;
+ }
+
+ public SchemaBuilder addEntityContainer(EntityContainer container) {
+ entityContainers.add(container);
+ return this;
+ }
+
+ public SchemaBuilder addComplexType(ComplexType createEntityType) {
+ complexTypes.add(createEntityType);
+ return this;
+ }
+
+ public void addAssociations(Collection<Association> associations) {
+ for (Association association : associations) {
+ final String relationshipName = association.getName();
+ if (name2Associations.containsKey(relationshipName)) {
+ association = mergeAssociations(name2Associations.get(relationshipName), association);
+ }
+ name2Associations.put(relationshipName, association);
+ }
+ }
+
+ private Association mergeAssociations(Association associationOne, Association associationTwo) {
+ AssociationEnd oneEnd1 = associationOne.getEnd1();
+ AssociationEnd oneEnd2 = associationOne.getEnd2();
+ AssociationEnd twoEnd1 = associationTwo.getEnd1();
+ AssociationEnd twoEnd2 = associationTwo.getEnd2();
+ AssociationEnd[] oneEnds = new AssociationEnd[]{oneEnd1, oneEnd2};
+
+ for (AssociationEnd associationEnd : oneEnds) {
+ if (associationEnd.getRole().equals(twoEnd1.getRole())) {
+ if (twoEnd1.getMultiplicity() == EdmMultiplicity.MANY) {
+ associationEnd.setMultiplicity(EdmMultiplicity.MANY);
+ }
+ } else if (associationEnd.getRole().equals(twoEnd2.getRole())) {
+ if (twoEnd2.getMultiplicity() == EdmMultiplicity.MANY) {
+ associationEnd.setMultiplicity(EdmMultiplicity.MANY);
+ }
+ }
+ }
+
+ return associationOne;
+ }
+
+ public Schema build() {
+ Schema s = new Schema();
+ s.setUsings(usings);
+ s.setEntityTypes(entityTypes);
+ s.setComplexTypes(complexTypes);
+ s.setAssociations(new ArrayList<Association>(name2Associations.values()));
+ s.setEntityContainers(entityContainers);
+ s.setAnnotationAttributes(annotationAttributes);
+ s.setAnnotationElements(annotationElements);
+ s.setNamespace(namespace);
+ return s;
+ }
+ }
+
+ private static class ContainerBuilder {
+
+ final private String name;
+ final private String namespace;
+ private boolean defaultContainer = true;
+ private List<EntitySet> entitySets = new ArrayList<EntitySet>();
+ private List<AssociationSet> associationSets = new ArrayList<AssociationSet>();
+ private List<FunctionImport> functionImports = new ArrayList<FunctionImport>();
+// private Documentation documentation;
+
+ private ContainerBuilder(String namespace, String containerName) {
+ this.namespace = namespace;
+ name = containerName;
+ }
+
+ public String getNamespace() {
+ return namespace;
+ }
+
+ public static ContainerBuilder init(String namespace, String containerName) {
+ return new ContainerBuilder(namespace, containerName);
+ }
+
+ public ContainerBuilder setDefaultContainer(boolean isDefault) {
+ defaultContainer = isDefault;
+ return this;
+ }
+
+ public ContainerBuilder addEntitySet(EntitySet entitySet) {
+ entitySets.add(entitySet);
+ return this;
+ }
+
+ public void addAssociationSets(Collection<Association> associations) {
+ for (Association association : associations) {
+ AssociationSet as = new AssociationSet();
+ as.setName(association.getName());
+ FullQualifiedName asAssociationFqn = new FullQualifiedName(namespace, association.getName());
+ as.setAssociation(asAssociationFqn);
+
+ AssociationSetEnd asEnd1 = new AssociationSetEnd();
+ asEnd1.setEntitySet(getEntitySetName(association.getEnd1()));
+ asEnd1.setRole(association.getEnd1().getRole());
+ as.setEnd1(asEnd1);
+
+ AssociationSetEnd asEnd2 = new AssociationSetEnd();
+ asEnd2.setEntitySet(getEntitySetName(association.getEnd2()));
+ asEnd2.setRole(association.getEnd2().getRole());
+ as.setEnd2(asEnd2);
+
+ associationSets.add(as);
+ }
+ }
+
+ public EntityContainer build() {
+ EntityContainer ec = new EntityContainer();
+ ec.setName(name);
+ ec.setDefaultEntityContainer(defaultContainer);
+ ec.setEntitySets(entitySets);
+ ec.setAssociationSets(associationSets);
+ ec.setFunctionImports(functionImports);
+ return ec;
+ }
+
+ private String getEntitySetName(AssociationEnd end) {
+ for (EntitySet entitySet : entitySets) {
+ if(entitySet.getEntityType().equals(end.getType())) {
+ return entitySet.getName();
+ }
+ }
+ throw new ODataRuntimeException("No entity set found for " + end.getType());
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ae7c1f52/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java
new file mode 100644
index 0000000..184685e
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java
@@ -0,0 +1,62 @@
+/*******************************************************************************
+ * 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.core.annotation.edm;
+
+import java.lang.reflect.Field;
+import java.util.Locale;
+import org.apache.olingo.odata2.api.annotation.edm.EdmComplexEntity;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
+
+/**
+ *
+ */
+public class AnnotationHelper {
+
+ public boolean isEdmAnnotated(Object object) {
+ if(object == null) {
+ return false;
+ }
+ return isEdmAnnotated(object.getClass());
+ }
+
+ public boolean isEdmAnnotated(Class<?> clazz) {
+ if (clazz == null) {
+ return false;
+ } else {
+ final boolean isEntity = null != clazz.getAnnotation(EdmEntityType.class);
+ final boolean isComplexEntity = null != clazz.getAnnotation(EdmComplexEntity.class);
+ return isEntity || isComplexEntity;
+ }
+ }
+
+ public String getCanonicalName(Field field) {
+ return firstCharToUpperCase(field.getName());
+ }
+
+ public String getCanonicalName(Class<?> clazz) {
+ return firstCharToUpperCase(clazz.getSimpleName());
+ }
+
+ private String firstCharToUpperCase(String content) {
+ if(content == null || content.isEmpty()) {
+ return content;
+ }
+ return content.substring(0, 1).toUpperCase(Locale.ENGLISH) + content.substring(1);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/ae7c1f52/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/ClassHelper.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/ClassHelper.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/ClassHelper.java
new file mode 100644
index 0000000..baf4626
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/ClassHelper.java
@@ -0,0 +1,104 @@
+/*******************************************************************************
+ * 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.core.annotation.edm;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.io.FilenameFilter;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ *
+ */
+public class ClassHelper {
+
+ private static final File[] EMPTY_FILE_ARRAY = new File[0];
+
+ private static final FilenameFilter CLASSFILE_FILTER = new FilenameFilter() {
+ @Override
+ public boolean accept(File dir, String name) {
+ return name.endsWith(CLASSFILE_ENDING);
+ }
+ public static final String CLASSFILE_ENDING = ".class";
+ };
+
+ private static final FileFilter FOLDER_FILTER = new FileFilter() {
+ @Override
+ public boolean accept(File pathname) {
+ return pathname.isDirectory();
+ }
+ };
+
+ public static final List<Class<?>> loadClasses(String packageToScan, ClassValidator cv) {
+ return loadClasses(packageToScan, CLASSFILE_FILTER, cv);
+ }
+
+
+ public static final List<Class<?>> loadClasses(String packageToScan, FilenameFilter ff, ClassValidator cv) {
+ final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ String folderToScan = packageToScan.replace(".", "/");
+ URL url = classLoader.getResource(folderToScan);
+ if(url == null) {
+ throw new IllegalArgumentException("No folder to scan found for package '" + packageToScan + "'.");
+ }
+ File folder = new File(url.getFile());
+ File[] classFiles = folder.listFiles(ff);
+ if(classFiles == null) {
+ classFiles = EMPTY_FILE_ARRAY;
+ }
+
+ List<Class<?>> annotatedClasses = new ArrayList<Class<?>>(classFiles.length);
+ for (File file : classFiles) {
+ String name = file.getName();
+ String fqn = packageToScan + "." + name.substring(0, name.length() - 6);
+ try {
+ Class<?> c = classLoader.loadClass(fqn);
+ if (cv.isClassValid(c)) {
+ annotatedClasses.add(c);
+ }
+ } catch (ClassNotFoundException ex) {
+ }
+ }
+
+ // recursive search
+ File[] subfolders = listSubFolder(folder);
+ for (File file : subfolders) {
+ List<Class<?>> subFolderClazzes = loadClasses(packageToScan + "." + file.getName(), ff, cv);
+ annotatedClasses.addAll(subFolderClazzes);
+ }
+ //
+
+ return annotatedClasses;
+ }
+
+ private static File[] listSubFolder(File folder) {
+ File[] subfolders = folder.listFiles(FOLDER_FILTER);
+ if(subfolders == null) {
+ return EMPTY_FILE_ARRAY;
+ }
+ return subfolders;
+ }
+
+ public interface ClassValidator {
+ boolean isClassValid(Class<?> c);
+ }
+}
[52/52] git commit: Renamed project
Posted by mi...@apache.org.
Renamed project
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/12ea18ae
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/12ea18ae
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/12ea18ae
Branch: refs/heads/master
Commit: 12ea18aed44f33fb58b577887533bf841771bfea
Parents: 28b35ff
Author: Michael Bolz <mi...@apache.org>
Authored: Thu Dec 5 10:03:26 2013 +0100
Committer: Michael Bolz <mi...@apache.org>
Committed: Thu Dec 5 10:03:26 2013 +0100
----------------------------------------------------------------------
.../annotation-processor-api/pom.xml | 42 +
.../olingo/odata2/api/data/DataSource.java | 200 +++
.../odata2/api/data/DataSourceProcessor.java | 47 +
.../olingo/odata2/api/data/ValueAccess.java | 69 +
.../annotation-processor-core/pom.xml | 48 +
.../annotation/data/AnnotationInMemoryDs.java | 351 ++++
.../annotation/data/AnnotationValueAccess.java | 106 ++
.../annotation/data/BeanPropertyAccess.java | 186 ++
.../odata2/core/annotation/data/DataStore.java | 192 +++
.../annotation/edm/AnnotationEdmProvider.java | 773 +++++++++
.../annotation/processor/ListsProcessor.java | 1630 ++++++++++++++++++
.../core/annotation/util/AnnotationHelper.java | 726 ++++++++
.../core/annotation/util/ClassHelper.java | 105 ++
.../data/AnnotationsInMemoryDsTest.java | 190 ++
.../edm/AnnotationEdmProviderTest.java | 463 +++++
.../odata2/core/annotation/model/Building.java | 95 +
.../odata2/core/annotation/model/City.java | 62 +
.../odata2/core/annotation/model/Employee.java | 187 ++
.../odata2/core/annotation/model/Location.java | 61 +
.../odata2/core/annotation/model/Manager.java | 47 +
.../annotation/model/ModelSharedConstants.java | 25 +
.../odata2/core/annotation/model/Photo.java | 128 ++
.../odata2/core/annotation/model/RefBase.java | 55 +
.../core/annotation/model/ResourceHelper.java | 64 +
.../odata2/core/annotation/model/Room.java | 89 +
.../odata2/core/annotation/model/Team.java | 81 +
.../annotation-processor-webref/pom.xml | 120 ++
.../odata2/ref/annotation/model/Building.java | 97 ++
.../odata2/ref/annotation/model/City.java | 61 +
.../odata2/ref/annotation/model/Employee.java | 192 +++
.../odata2/ref/annotation/model/Location.java | 60 +
.../odata2/ref/annotation/model/Manager.java | 43 +
.../annotation/model/ModelSharedConstants.java | 25 +
.../odata2/ref/annotation/model/Photo.java | 128 ++
.../odata2/ref/annotation/model/RefBase.java | 78 +
.../ref/annotation/model/ResourceHelper.java | 93 +
.../odata2/ref/annotation/model/Room.java | 88 +
.../odata2/ref/annotation/model/Team.java | 73 +
.../processor/AnnotationPocServiceFactory.java | 202 +++
.../src/main/resources/log4j.xml | 39 +
.../src/main/version/version.html | 27 +
.../src/main/webapp/WEB-INF/web.xml | 48 +
.../src/main/webapp/index.jsp | 116 ++
odata2-annotation-processor/pom.xml | 30 +
.../edm-annotation-api/pom.xml | 42 -
.../olingo/odata2/api/data/DataSource.java | 200 ---
.../odata2/api/data/DataSourceProcessor.java | 47 -
.../olingo/odata2/api/data/ValueAccess.java | 69 -
.../edm-annotation-core/pom.xml | 48 -
.../annotation/data/AnnotationInMemoryDs.java | 351 ----
.../annotation/data/AnnotationValueAccess.java | 106 --
.../annotation/data/BeanPropertyAccess.java | 186 --
.../odata2/core/annotation/data/DataStore.java | 192 ---
.../annotation/edm/AnnotationEdmProvider.java | 773 ---------
.../annotation/processor/ListsProcessor.java | 1630 ------------------
.../core/annotation/util/AnnotationHelper.java | 726 --------
.../core/annotation/util/ClassHelper.java | 105 --
.../data/AnnotationsInMemoryDsTest.java | 190 --
.../edm/AnnotationEdmProviderTest.java | 463 -----
.../odata2/core/annotation/model/Building.java | 95 -
.../odata2/core/annotation/model/City.java | 62 -
.../odata2/core/annotation/model/Employee.java | 187 --
.../odata2/core/annotation/model/Location.java | 61 -
.../odata2/core/annotation/model/Manager.java | 47 -
.../annotation/model/ModelSharedConstants.java | 25 -
.../odata2/core/annotation/model/Photo.java | 128 --
.../odata2/core/annotation/model/RefBase.java | 55 -
.../core/annotation/model/ResourceHelper.java | 64 -
.../odata2/core/annotation/model/Room.java | 89 -
.../odata2/core/annotation/model/Team.java | 81 -
.../edm-annotation-webref/pom.xml | 120 --
.../odata2/ref/annotation/model/Building.java | 97 --
.../odata2/ref/annotation/model/City.java | 61 -
.../odata2/ref/annotation/model/Employee.java | 192 ---
.../odata2/ref/annotation/model/Location.java | 60 -
.../odata2/ref/annotation/model/Manager.java | 43 -
.../annotation/model/ModelSharedConstants.java | 25 -
.../odata2/ref/annotation/model/Photo.java | 128 --
.../odata2/ref/annotation/model/RefBase.java | 78 -
.../ref/annotation/model/ResourceHelper.java | 93 -
.../odata2/ref/annotation/model/Room.java | 88 -
.../odata2/ref/annotation/model/Team.java | 73 -
.../processor/AnnotationPocServiceFactory.java | 202 ---
.../src/main/resources/log4j.xml | 39 -
.../src/main/version/version.html | 27 -
.../src/main/webapp/WEB-INF/web.xml | 48 -
.../src/main/webapp/index.jsp | 116 --
odata2-edm-annotation/pom.xml | 30 -
odata2-lib/odata-ref/pom.xml | 2 +-
pom.xml | 2 +-
90 files changed, 7544 insertions(+), 7544 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-annotation-processor/annotation-processor-api/pom.xml
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-api/pom.xml b/odata2-annotation-processor/annotation-processor-api/pom.xml
new file mode 100644
index 0000000..e42ec20
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-api/pom.xml
@@ -0,0 +1,42 @@
+<?xml version="1.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.
+-->
+<project
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
+ xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.olingo</groupId>
+ <artifactId>olingo-odata2-annotation-processor-incubating</artifactId>
+ <version>1.1.0-SNAPSHOT</version>
+ <relativePath>..</relativePath>
+ </parent>
+
+ <artifactId>olingo-odata2-annotation-processor-api-incubating</artifactId>
+ <name>${project.artifactId}</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.olingo</groupId>
+ <artifactId>olingo-odata2-api-incubating</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-annotation-processor/annotation-processor-api/src/main/java/org/apache/olingo/odata2/api/data/DataSource.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-api/src/main/java/org/apache/olingo/odata2/api/data/DataSource.java b/odata2-annotation-processor/annotation-processor-api/src/main/java/org/apache/olingo/odata2/api/data/DataSource.java
new file mode 100644
index 0000000..694f199
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-api/src/main/java/org/apache/olingo/odata2/api/data/DataSource.java
@@ -0,0 +1,200 @@
+/*******************************************************************************
+ * 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.api.data;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.olingo.odata2.api.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.edm.EdmException;
+import org.apache.olingo.odata2.api.edm.EdmFunctionImport;
+import org.apache.olingo.odata2.api.exception.ODataApplicationException;
+import org.apache.olingo.odata2.api.exception.ODataNotFoundException;
+import org.apache.olingo.odata2.api.exception.ODataNotImplementedException;
+
+/**
+ * <p>This interface is intended to make it easier to implement an OData
+ * service in cases where all data for each entity set can be provided as a {@link List} of objects from which all
+ * properties described in the
+ * Entity Data Model can be retrieved and set.</p>
+ * <p>By obeying these restrictions, data-source implementations get the
+ * following advantages:
+ * <ul>
+ * <li>All system query options can be handled centrally.</li>
+ * <li>Following navigation paths must only be done step by step.</li>
+ * </ul>
+ * </p>
+ *
+ */
+public interface DataSource {
+
+ /**
+ * Retrieves the whole data list for the specified entity set.
+ * @param entitySet the requested {@link EdmEntitySet}
+ * @return the requested data list
+ */
+ List<?> readData(EdmEntitySet entitySet) throws ODataNotImplementedException, ODataNotFoundException, EdmException,
+ ODataApplicationException;
+
+ /**
+ * Retrieves a single data object for the specified entity set and key.
+ * @param entitySet the requested {@link EdmEntitySet}
+ * @param keys the entity key as map of key names to key values
+ * @return the requested data object
+ */
+ Object readData(EdmEntitySet entitySet, Map<String, Object> keys) throws ODataNotImplementedException,
+ ODataNotFoundException, EdmException, ODataApplicationException;
+
+ /**
+ * <p>Retrieves data for the specified function import and key.</p>
+ * <p>This method is called also for function imports that have defined in
+ * their metadata an other HTTP method than <code>GET</code>.</p>
+ * @param function the requested {@link EdmFunctionImport}
+ * @param parameters the parameters of the function import
+ * as map of parameter names to parameter values
+ * @param keys the key of the returned entity set, as map of key names to key values,
+ * if the return type of the function import is a collection of entities
+ * (optional)
+ * @return the requested data object, either a list or a single object;
+ * if the function import's return type is of type <code>Binary</code>,
+ * the returned object(s) must be of type {@link BinaryData}
+ */
+ Object readData(EdmFunctionImport function, Map<String, Object> parameters, Map<String, Object> keys)
+ throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException;
+
+ /**
+ * <p>Retrieves related data for the specified source data, entity set, and key.</p>
+ * <p>If the underlying association of the EDM is specified to have target
+ * multiplicity '*' and no target key is given, this method returns a list of
+ * related data, otherwise it returns a single data object.</p>
+ * @param sourceEntitySet the {@link EdmEntitySet} of the source entity
+ * @param sourceData the data object of the source entity
+ * @param targetEntitySet the requested target {@link EdmEntitySet}
+ * @param targetKeys the key of the target entity as map of key names to key values
+ * (optional)
+ * @return the requested releated data object, either a list or a single object
+ */
+ Object readRelatedData(EdmEntitySet sourceEntitySet, Object sourceData, EdmEntitySet targetEntitySet,
+ Map<String, Object> targetKeys) throws ODataNotImplementedException, ODataNotFoundException, EdmException,
+ ODataApplicationException;
+
+ /**
+ * Retrieves the binary data and the MIME type for the media resource
+ * associated to the specified media-link entry.
+ * @param entitySet the {@link EdmEntitySet} of the media-link entry
+ * @param mediaLinkEntryData the data object of the media-link entry
+ * @return the binary data and the MIME type of the media resource
+ */
+ BinaryData readBinaryData(EdmEntitySet entitySet, Object mediaLinkEntryData) throws ODataNotImplementedException,
+ ODataNotFoundException, EdmException, ODataApplicationException;
+
+ /**
+ * <p>Creates and returns a new instance of the requested data-object type.</p>
+ * <p>This instance must not be part of the corresponding list and should
+ * have empty content, apart from the key and other mandatory properties.
+ * However, intermediate objects to access complex properties must not be
+ * <code>null</code>.</p>
+ * @param entitySet the {@link EdmEntitySet} the object must correspond to
+ * @return the new data object
+ */
+ Object newDataObject(EdmEntitySet entitySet) throws ODataNotImplementedException, EdmException,
+ ODataApplicationException;
+
+ /**
+ * Writes the binary data for the media resource associated to the
+ * specified media-link entry.
+ * @param entitySet the {@link EdmEntitySet} of the media-link entry
+ * @param mediaLinkEntryData the data object of the media-link entry
+ * @param binaryData the binary data of the media resource along with
+ * the MIME type of the binary data
+ */
+ void writeBinaryData(EdmEntitySet entitySet, Object mediaLinkEntryData, BinaryData binaryData)
+ throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException;
+
+ /**
+ * Deletes a single data object identified by the specified entity set and key.
+ * @param entitySet the {@link EdmEntitySet} of the entity to be deleted
+ * @param keys the entity key as map of key names to key values
+ */
+ void deleteData(EdmEntitySet entitySet, Map<String, Object> keys) throws ODataNotImplementedException,
+ ODataNotFoundException, EdmException, ODataApplicationException;
+
+ /**
+ * <p>Inserts an instance into the entity list of the specified entity set.</p>
+ * <p>If {@link #newDataObject} has not set the key and other mandatory
+ * properties already, this method must set them before inserting the
+ * instance into the list.</p>
+ * @param entitySet the {@link EdmEntitySet} the object must correspond to
+ * @param data the data object of the new entity
+ */
+ void createData(EdmEntitySet entitySet, Object data) throws ODataNotImplementedException, EdmException,
+ ODataApplicationException;
+
+ /**
+ * Deletes the relation from the specified source data to a target entity
+ * specified by entity set and key.
+ * @param sourceEntitySet the {@link EdmEntitySet} of the source entity
+ * @param sourceData the data object of the source entity
+ * @param targetEntitySet the {@link EdmEntitySet} of the target entity
+ * @param targetKeys the key of the target entity as map of key names to key values
+ * (optional)
+ */
+ void deleteRelation(EdmEntitySet sourceEntitySet, Object sourceData, EdmEntitySet targetEntitySet,
+ Map<String, Object> targetKeys) throws ODataNotImplementedException, ODataNotFoundException, EdmException,
+ ODataApplicationException;
+
+ /**
+ * Writes a relation from the specified source data to a target entity
+ * specified by entity set and key.
+ * @param sourceEntitySet the {@link EdmEntitySet} of the source entity
+ * @param sourceData the data object of the source entity
+ * @param targetEntitySet the {@link EdmEntitySet} of the relation target
+ * @param targetKeys the key of the target entity as map of key names to key values
+ */
+ void writeRelation(EdmEntitySet sourceEntitySet, Object sourceData, EdmEntitySet targetEntitySet,
+ Map<String, Object> targetKeys) throws ODataNotImplementedException, ODataNotFoundException, EdmException,
+ ODataApplicationException;
+
+ /**
+ * Container to store binary data (as byte array) and the associated MIME type.
+ */
+ public class BinaryData {
+ private final byte[] data;
+ private final String mimeType;
+
+ public BinaryData(final byte[] data, final String mimeType) {
+ this.data = data;
+ this.mimeType = mimeType;
+ }
+
+ public byte[] getData() {
+ return data;
+ }
+
+ public String getMimeType() {
+ return mimeType;
+ }
+
+ @Override
+ public String toString() {
+ return "data=" + Arrays.toString(data) + ", mimeType=" + mimeType;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-annotation-processor/annotation-processor-api/src/main/java/org/apache/olingo/odata2/api/data/DataSourceProcessor.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-api/src/main/java/org/apache/olingo/odata2/api/data/DataSourceProcessor.java b/odata2-annotation-processor/annotation-processor-api/src/main/java/org/apache/olingo/odata2/api/data/DataSourceProcessor.java
new file mode 100644
index 0000000..2be5663
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-api/src/main/java/org/apache/olingo/odata2/api/data/DataSourceProcessor.java
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * 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.api.data;
+
+import org.apache.olingo.odata2.api.processor.ODataSingleProcessor;
+
+/**
+ * Abstract class for implementation of the centralized parts of OData processing,
+ * allowing to use the simplified {@link DataSource} and {@link ValueAccess} for the
+ * actual data handling.
+ * <br/>
+ * Extend this class and implement a DataSourceProcessor if the default implementation
+ * (<code>ListProcessor</code> found in <code>annotation-processor-core module</code>) has to be overwritten.
+ */
+public abstract class DataSourceProcessor extends ODataSingleProcessor {
+
+ protected final DataSource dataSource;
+ protected final ValueAccess valueAccess;
+
+ /**
+ * Initialize a {@link DataSourceProcessor} in combination with given {@link DataSource} (providing data objects)
+ * and {@link ValueAccess} (accessing values of data objects).
+ *
+ * @param dataSource used for accessing the data objects
+ * @param valueAccess for accessing the values provided by the data objects
+ */
+ public DataSourceProcessor(final DataSource dataSource, final ValueAccess valueAccess) {
+ this.dataSource = dataSource;
+ this.valueAccess = valueAccess;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-annotation-processor/annotation-processor-api/src/main/java/org/apache/olingo/odata2/api/data/ValueAccess.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-api/src/main/java/org/apache/olingo/odata2/api/data/ValueAccess.java b/odata2-annotation-processor/annotation-processor-api/src/main/java/org/apache/olingo/odata2/api/data/ValueAccess.java
new file mode 100644
index 0000000..685e1b6
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-api/src/main/java/org/apache/olingo/odata2/api/data/ValueAccess.java
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * 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.api.data;
+
+import org.apache.olingo.odata2.api.edm.EdmMapping;
+import org.apache.olingo.odata2.api.edm.EdmProperty;
+import org.apache.olingo.odata2.api.exception.ODataException;
+
+/**
+ * This interface is intended to access values in a Java object.
+ */
+public interface ValueAccess {
+
+ /**
+ * Retrieves the value of an EDM property for the given data object.
+ * @param data the Java data object
+ * @param property the requested {@link EdmProperty}
+ * @return the requested property value
+ */
+ public <T> Object getPropertyValue(final T data, final EdmProperty property) throws ODataException;
+
+ /**
+ * Sets the value of an EDM property for the given data object.
+ * @param data the Java data object
+ * @param property the {@link EdmProperty}
+ * @param value the new value of the property
+ */
+ public <T, V> void setPropertyValue(T data, final EdmProperty property, final V value) throws ODataException;
+
+ /**
+ * Retrieves the Java type of an EDM property for the given data object.
+ * @param data the Java data object
+ * @param property the requested {@link EdmProperty}
+ * @return the requested Java type
+ */
+ public <T> Class<?> getPropertyType(final T data, final EdmProperty property) throws ODataException;
+
+ /**
+ * Retrieves the value defined by a mapping object for the given data object.
+ * @param data the Java data object
+ * @param mapping the requested {@link EdmMapping}
+ * @return the requested value
+ */
+ public <T> Object getMappingValue(final T data, final EdmMapping mapping) throws ODataException;
+
+ /**
+ * Sets the value defined by a mapping object for the given data object.
+ * @param data the Java data object
+ * @param mapping the {@link EdmMapping}
+ * @param value the new value
+ */
+ public <T, V> void setMappingValue(T data, final EdmMapping mapping, final V value) throws ODataException;
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-annotation-processor/annotation-processor-core/pom.xml
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/pom.xml b/odata2-annotation-processor/annotation-processor-core/pom.xml
new file mode 100644
index 0000000..4732522
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-core/pom.xml
@@ -0,0 +1,48 @@
+<?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-annotation-processor-core-incubating</artifactId>
+ <packaging>jar</packaging>
+ <name>${project.artifactId}</name>
+
+ <parent>
+ <groupId>org.apache.olingo</groupId>
+ <artifactId>olingo-odata2-annotation-processor-incubating</artifactId>
+ <version>1.1.0-SNAPSHOT</version>
+ <relativePath>..</relativePath>
+ </parent>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.olingo</groupId>
+ <artifactId>olingo-odata2-annotation-processor-api-incubating</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.olingo</groupId>
+ <artifactId>olingo-odata2-api-incubating</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.olingo</groupId>
+ <artifactId>olingo-odata2-api-annotation-incubating</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.olingo</groupId>
+ <artifactId>olingo-odata2-core-incubating</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ </dependencies>
+
+
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationInMemoryDs.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationInMemoryDs.java b/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationInMemoryDs.java
new file mode 100644
index 0000000..db03a4c
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationInMemoryDs.java
@@ -0,0 +1,351 @@
+/**
+ * *****************************************************************************
+ * 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.core.annotation.data;
+
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceContent;
+import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceMimeType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
+import org.apache.olingo.odata2.api.data.DataSource;
+import org.apache.olingo.odata2.api.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.edm.EdmException;
+import org.apache.olingo.odata2.api.edm.EdmFunctionImport;
+import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
+import org.apache.olingo.odata2.api.exception.ODataApplicationException;
+import org.apache.olingo.odata2.api.exception.ODataNotFoundException;
+import org.apache.olingo.odata2.api.exception.ODataNotImplementedException;
+import org.apache.olingo.odata2.core.annotation.util.AnnotationHelper;
+import org.apache.olingo.odata2.core.annotation.util.ClassHelper;
+import org.apache.olingo.odata2.core.annotation.util.AnnotationHelper.AnnotatedNavInfo;
+import org.apache.olingo.odata2.core.annotation.util.AnnotationHelper.ODataAnnotationException;
+import org.apache.olingo.odata2.core.exception.ODataRuntimeException;
+
+public class AnnotationInMemoryDs implements DataSource {
+
+ private static final AnnotationHelper ANNOTATION_HELPER = new AnnotationHelper();
+ private final Map<String, DataStore<Object>> dataStores = new HashMap<String, DataStore<Object>>();
+ private final boolean persistInMemory;
+
+ public AnnotationInMemoryDs(String packageToScan) {
+ this(packageToScan, true);
+ }
+
+ public AnnotationInMemoryDs(String packageToScan, boolean persistInMemory) {
+ this.persistInMemory = persistInMemory;
+ List<Class<?>> foundClasses = ClassHelper.loadClasses(packageToScan, new ClassHelper.ClassValidator() {
+ @Override
+ public boolean isClassValid(Class<?> c) {
+ return null != c.getAnnotation(org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet.class);
+ }
+ });
+
+ init(foundClasses);
+ }
+
+ @SuppressWarnings("unchecked")
+ private void init(List<Class<?>> foundClasses) {
+ for (Class<?> clz : foundClasses) {
+
+ DataStore<Object> dhs = (DataStore<Object>) getDataStore(clz);
+ org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet entitySet =
+ clz.getAnnotation(org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet.class);
+ dataStores.put(entitySet.name(), dhs);
+ }
+ }
+
+ public <T> DataStore<T> getDataStore(Class<T> clazz) {
+ return DataStore.createInMemory(clazz, persistInMemory);
+ }
+
+ @Override
+ public List<?> readData(EdmEntitySet entitySet) throws ODataNotImplementedException,
+ ODataNotFoundException, EdmException, ODataApplicationException {
+
+ DataStore<Object> holder = getDataStore(entitySet);
+ if (holder != null) {
+ return new ArrayList<Object>(holder.read());
+ }
+
+ throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
+ }
+
+ @Override
+ public Object readData(EdmEntitySet entitySet, Map<String, Object> keys)
+ throws ODataNotFoundException, EdmException, ODataApplicationException {
+
+ DataStore<Object> store = getDataStore(entitySet);
+ if (store != null) {
+ Object keyInstance = store.createInstance();
+ ANNOTATION_HELPER.setKeyFields(keyInstance, keys);
+
+ Object result = store.read(keyInstance);
+ if (result != null) {
+ return result;
+ }
+ }
+
+ throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
+ }
+
+ @Override
+ public Object readData(EdmFunctionImport function, Map<String, Object> parameters, Map<String, Object> keys)
+ throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException {
+ throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
+ }
+
+ @Override
+ public Object readRelatedData(EdmEntitySet sourceEntitySet, Object sourceData, EdmEntitySet targetEntitySet,
+ Map<String, Object> targetKeys)
+ throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException {
+
+ DataStore<?> sourceStore = dataStores.get(sourceEntitySet.getName());
+ DataStore<?> targetStore = dataStores.get(targetEntitySet.getName());
+
+ AnnotatedNavInfo navInfo = ANNOTATION_HELPER.getCommonNavigationInfo(
+ sourceStore.getDataTypeClass(), targetStore.getDataTypeClass());
+ Field sourceField = navInfo.getFromField();
+ if (sourceField == null) {
+ throw new ODataRuntimeException("Missing source field for related data (sourceStore='" + sourceStore
+ + "', targetStore='" + targetStore + "').");
+ }
+
+ Object navigationInstance = getValue(sourceField, sourceData);
+ List<Object> resultData = new ArrayList<Object>();
+ for (Object targetInstance : targetStore.read()) {
+ if (navigationInstance instanceof Collection) {
+ for (Object object : (Collection<?>) navigationInstance) {
+ if (ANNOTATION_HELPER.keyMatch(targetInstance, object)) {
+ resultData.add(targetInstance);
+ }
+ }
+ } else if (ANNOTATION_HELPER.keyMatch(targetInstance, navigationInstance)) {
+ resultData.add(targetInstance);
+ }
+ }
+
+ if (navInfo.getToMultiplicity() == EdmMultiplicity.MANY) {
+ if (targetKeys.isEmpty()) {
+ return resultData;
+ } else {
+ for (Object result : resultData) {
+ if (ANNOTATION_HELPER.keyMatch(result, targetKeys)) {
+ return result;
+ }
+ }
+ return null;
+ }
+ } else {
+ if (resultData.isEmpty()) {
+ return null;
+ }
+ return resultData.get(0);
+ }
+ }
+
+ @Override
+ public BinaryData readBinaryData(EdmEntitySet entitySet, Object mediaLinkEntryData)
+ throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException {
+
+ Object data = ANNOTATION_HELPER.getValueForField(mediaLinkEntryData, EdmMediaResourceContent.class);
+ Object mimeType = ANNOTATION_HELPER.getValueForField(mediaLinkEntryData, EdmMediaResourceMimeType.class);
+
+ BinaryData db = new BinaryData((byte[]) data, String.valueOf(mimeType));
+ return db;
+ }
+
+ @Override
+ public Object newDataObject(EdmEntitySet entitySet)
+ throws ODataNotImplementedException, EdmException, ODataApplicationException {
+
+ DataStore<Object> dataStore = getDataStore(entitySet);
+ if (dataStore != null) {
+ return dataStore.createInstance();
+ }
+
+ throw new ODataRuntimeException("No DataStore found for entitySet with name: " + entitySet.getName());
+ }
+
+ @Override
+ public void writeBinaryData(EdmEntitySet entitySet, Object mediaEntityInstance, BinaryData binaryData)
+ throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException {
+
+ try {
+ ANNOTATION_HELPER.setValueForAnnotatedField(
+ mediaEntityInstance, EdmMediaResourceContent.class, binaryData.getData());
+ ANNOTATION_HELPER.setValueForAnnotatedField(
+ mediaEntityInstance, EdmMediaResourceMimeType.class, binaryData.getMimeType());
+ } catch (ODataAnnotationException e) {
+ throw new ODataRuntimeException("Invalid media resource annotation at entity set '" + entitySet.getName()
+ + "' with message '" + e.getMessage() + "'.", e);
+ }
+ }
+
+ /**
+ * <p>Updates a single data object identified by the specified entity set and key fields of
+ * the data object.</p>
+ * @param entitySet the {@link EdmEntitySet} the object must correspond to
+ * @param data the data object of the new entity
+ * @return updated data object instance
+ * @throws org.apache.olingo.odata2.api.exception.ODataNotImplementedException
+ * @throws org.apache.olingo.odata2.api.edm.EdmException
+ * @throws org.apache.olingo.odata2.api.exception.ODataApplicationException
+ */
+ public Object updateData(EdmEntitySet entitySet, Object data)
+ throws ODataNotImplementedException, EdmException, ODataApplicationException {
+
+ DataStore<Object> dataStore = getDataStore(entitySet);
+ return dataStore.update(data);
+ }
+
+ @Override
+ public void deleteData(EdmEntitySet entitySet, Map<String, Object> keys)
+ throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException {
+ DataStore<Object> dataStore = getDataStore(entitySet);
+ Object keyInstance = dataStore.createInstance();
+ ANNOTATION_HELPER.setKeyFields(keyInstance, keys);
+ dataStore.delete(keyInstance);
+ }
+
+ @Override
+ public void createData(EdmEntitySet entitySet, Object data)
+ throws ODataNotImplementedException, EdmException, ODataApplicationException {
+
+ DataStore<Object> dataStore = getDataStore(entitySet);
+ dataStore.create(data);
+ }
+
+ @Override
+ public void deleteRelation(EdmEntitySet sourceEntitySet, Object sourceData, EdmEntitySet targetEntitySet,
+ Map<String, Object> targetKeys)
+ throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException {
+ throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
+ }
+
+ @Override
+ public void writeRelation(EdmEntitySet sourceEntitySet, Object sourceEntity, EdmEntitySet targetEntitySet,
+ Map<String, Object> targetEntityValues)
+ throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException {
+ // get common data
+ DataStore<Object> sourceStore = dataStores.get(sourceEntitySet.getName());
+ DataStore<Object> targetStore = dataStores.get(targetEntitySet.getName());
+
+ AnnotatedNavInfo commonNavInfo = ANNOTATION_HELPER.getCommonNavigationInfo(
+ sourceStore.getDataTypeClass(), targetStore.getDataTypeClass());
+
+ // get and validate source fields
+ Field sourceField = commonNavInfo.getFromField();
+ if (sourceField == null) {
+ throw new ODataRuntimeException("Missing source field for related data (sourceStore='" + sourceStore
+ + "', targetStore='" + targetStore + "').");
+ }
+
+ // get related target entity
+ Object targetEntity = targetStore.createInstance();
+ ANNOTATION_HELPER.setKeyFields(targetEntity, targetEntityValues);
+ targetEntity = targetStore.read(targetEntity);
+
+ // set at source
+ setValueAtNavigationField(sourceEntity, sourceField, targetEntity);
+ // set at target
+ Field targetField = commonNavInfo.getToField();
+ if(targetField != null) {
+ setValueAtNavigationField(targetEntity, targetField, sourceEntity);
+ }
+ }
+
+ /**
+ * Set (Multiplicity != *) or add (Multiplicity == *) <code>value</code> at <code>field</code>
+ * of <code>instance</code>.
+ *
+ * @param instance
+ * @param field
+ * @param value
+ * @throws EdmException
+ */
+ private void setValueAtNavigationField(Object instance, Field field, Object value)
+ throws EdmException {
+ Class<?> fieldTypeClass = field.getType();
+ if (Collection.class.isAssignableFrom(fieldTypeClass)) {
+ @SuppressWarnings("unchecked")
+ Collection<Object> collection = (Collection<Object>) ANNOTATION_HELPER.getValueForField(
+ instance, field.getName(), EdmNavigationProperty.class);
+ if(collection == null) {
+ collection = new ArrayList<Object>();
+ setValue(instance, field, collection);
+ }
+ collection.add(value);
+ } else if(fieldTypeClass.isArray()) {
+ throw new ODataRuntimeException("Write relations for internal used arrays is not supported.");
+ } else {
+ setValue(instance, field, value);
+ }
+ }
+
+ /**
+ * Returns corresponding DataStore for EdmEntitySet or if no data store is registered an
+ * ODataRuntimeException is thrown.
+ * Never returns NULL.
+ *
+ * @param entitySet for which the corresponding DataStore is returned
+ * @return a DataStore object
+ * @throws EdmException
+ * @throws ODataRuntimeException if no DataStore is found
+ */
+ private DataStore<Object> getDataStore(EdmEntitySet entitySet) throws EdmException {
+ final String name = entitySet.getName();
+ DataStore<Object> dataStore = dataStores.get(name);
+ if (dataStore == null) {
+ throw new ODataRuntimeException("No DataStore found for entity set '" + entitySet + "'.");
+ }
+ return dataStore;
+ }
+
+ private Object getValue(Field field, Object instance) {
+ try {
+ boolean access = field.isAccessible();
+ field.setAccessible(true);
+ Object value = field.get(instance);
+ field.setAccessible(access);
+ return value;
+ } catch (IllegalArgumentException e) {
+ throw new ODataRuntimeException("Error for getting value of field '"
+ + field + "' at instance '" + instance + "'.", e);
+ } catch (IllegalAccessException e) {
+ throw new ODataRuntimeException("Error for getting value of field '"
+ + field + "' at instance '" + instance + "'.", e);
+ }
+ }
+
+ private void setValue(Object instance, Field field, Object value) {
+ try {
+ boolean access = field.isAccessible();
+ field.setAccessible(true);
+ field.set(instance, value);
+ field.setAccessible(access);
+ } catch (IllegalArgumentException e) {
+ throw new ODataRuntimeException("Error for setting value of field: '"
+ + field + "' at instance: '" + instance + "'.", e);
+ } catch (IllegalAccessException e) {
+ throw new ODataRuntimeException("Error for setting value of field: '"
+ + field + "' at instance: '" + instance + "'.", e);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationValueAccess.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationValueAccess.java b/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationValueAccess.java
new file mode 100644
index 0000000..14183bf
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationValueAccess.java
@@ -0,0 +1,106 @@
+/*******************************************************************************
+ * 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.core.annotation.data;
+
+import org.apache.olingo.odata2.api.data.ValueAccess;
+import org.apache.olingo.odata2.api.edm.EdmMapping;
+import org.apache.olingo.odata2.api.edm.EdmProperty;
+import org.apache.olingo.odata2.api.exception.ODataException;
+import org.apache.olingo.odata2.api.exception.ODataNotImplementedException;
+import org.apache.olingo.odata2.core.annotation.util.AnnotationHelper;
+
+/**
+ *
+ */
+public class AnnotationValueAccess implements ValueAccess {
+ private final AnnotationHelper annotationHelper = new AnnotationHelper();
+
+ /**
+ * Retrieves the value of an EDM property for the given data object.
+ * @param data the Java data object
+ * @param property the requested {@link EdmProperty}
+ * @return the requested property value
+ */
+ @Override
+ public <T> Object getPropertyValue(final T data, final EdmProperty property) throws ODataException {
+ if(data == null) {
+ return null;
+ } else if (annotationHelper.isEdmAnnotated(data)) {
+ return annotationHelper.getValueForProperty(data, property.getName());
+ }
+ throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
+ }
+
+ /**
+ * Sets the value of an EDM property for the given data object.
+ * @param data the Java data object
+ * @param property the {@link EdmProperty}
+ * @param value the new value of the property
+ */
+ @Override
+ public <T, V> void setPropertyValue(T data, final EdmProperty property, final V value) throws ODataException {
+ if (annotationHelper.isEdmAnnotated(data)) {
+ annotationHelper.setValueForProperty(data, property.getName(), value);
+ } else {
+ throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
+ }
+ }
+
+ /**
+ * Retrieves the Java type of an EDM property for the given data object.
+ * @param data the Java data object
+ * @param property the requested {@link EdmProperty}
+ * @return the requested Java type
+ */
+ public <T> Class<?> getPropertyType(final T data, final EdmProperty property) throws ODataException {
+ if (annotationHelper.isEdmAnnotated(data)) {
+ Class<?> fieldType = annotationHelper.getFieldTypeForProperty(data, property.getName());
+ if (fieldType == null) {
+ throw new ODataException("No field type found for property " + property);
+ }
+ return fieldType;
+ }
+ throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
+ }
+
+ /**
+ * Retrieves the value defined by a mapping object for the given data object.
+ * @param data the Java data object
+ * @param mapping the requested {@link EdmMapping}
+ * @return the requested value
+ */
+ public <T> Object getMappingValue(final T data, final EdmMapping mapping) throws ODataException {
+ if (mapping != null && mapping.getMediaResourceMimeTypeKey() != null) {
+ return annotationHelper.getValueForProperty(data, mapping.getMediaResourceMimeTypeKey());
+ }
+ return null;
+ }
+
+ /**
+ * Sets the value defined by a mapping object for the given data object.
+ * @param data the Java data object
+ * @param mapping the {@link EdmMapping}
+ * @param value the new value
+ */
+ public <T, V> void setMappingValue(T data, final EdmMapping mapping, final V value) throws ODataException {
+ if (mapping != null && mapping.getMediaResourceMimeTypeKey() != null) {
+ annotationHelper.setValueForProperty(data, mapping.getMediaResourceMimeTypeKey(), value);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/BeanPropertyAccess.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/BeanPropertyAccess.java b/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/BeanPropertyAccess.java
new file mode 100644
index 0000000..be3baac
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/BeanPropertyAccess.java
@@ -0,0 +1,186 @@
+/*******************************************************************************
+ * 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.core.annotation.data;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Arrays;
+
+import org.apache.olingo.odata2.api.data.ValueAccess;
+import org.apache.olingo.odata2.api.edm.EdmException;
+import org.apache.olingo.odata2.api.edm.EdmMapping;
+import org.apache.olingo.odata2.api.edm.EdmProperty;
+import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
+import org.apache.olingo.odata2.api.exception.ODataException;
+import org.apache.olingo.odata2.api.exception.ODataHttpException;
+import org.apache.olingo.odata2.api.exception.ODataNotFoundException;
+
+/**
+ * Data access.
+ */
+public class BeanPropertyAccess implements ValueAccess {
+
+ @Override
+ public <T> Object getPropertyValue(final T data, final EdmProperty property) throws ODataException {
+ return getValue(data, getGetterMethodName(property));
+ }
+
+ @Override
+ public <T, V> void setPropertyValue(T data, final EdmProperty property, final V value) throws ODataException {
+ final String methodName = getSetterMethodName(getGetterMethodName(property));
+ if (methodName != null) {
+ setValue(data, methodName, value);
+ }
+ }
+
+ @Override
+ public <T> Class<?> getPropertyType(final T data, final EdmProperty property) throws ODataException {
+ return getType(data, getGetterMethodName(property));
+ }
+
+ @Override
+ public <T> Object getMappingValue(final T data, final EdmMapping mapping) throws ODataException {
+ if (mapping != null && mapping.getMimeType() != null) {
+ return getValue(data, mapping.getMimeType());
+ }
+ return null;
+ }
+
+ @Override
+ public <T, V> void setMappingValue(T data, final EdmMapping mapping, final V value) throws ODataException {
+ if (mapping != null && mapping.getMimeType() != null) {
+ setValue(data, getSetterMethodName(mapping.getMimeType()), value);
+ }
+ }
+
+ private String getGetterMethodName(final EdmProperty property) throws EdmException {
+ final String prefix = isBooleanProperty(property) ? "is" : "get";
+ final String defaultMethodName = prefix + property.getName();
+ return property.getMapping() == null || property.getMapping().getInternalName() == null ?
+ defaultMethodName : property.getMapping().getInternalName();
+ }
+
+ private boolean isBooleanProperty(final EdmProperty property) throws EdmException {
+ return property.isSimple()
+ && property.getType() == EdmSimpleTypeKind.Boolean.getEdmSimpleTypeInstance();
+ }
+
+ private String getSetterMethodName(final String getterMethodName) {
+ return getterMethodName.contains(".") ?
+ null : getterMethodName.replaceFirst("^is", "set").replaceFirst("^get", "set");
+ }
+
+ private <T> Object getValue(final T data, final String methodName) throws ODataNotFoundException {
+ Object dataObject = data;
+
+ for (final String method : methodName.split("\\.", -1)) {
+ if (dataObject != null) {
+ try {
+ dataObject = dataObject.getClass().getMethod(method).invoke(dataObject);
+ } catch (SecurityException e) {
+ throw new ODataNotFoundException(ODataHttpException.COMMON, e);
+ } catch (NoSuchMethodException e) {
+ throw new ODataNotFoundException(ODataHttpException.COMMON, e);
+ } catch (IllegalArgumentException e) {
+ throw new ODataNotFoundException(ODataHttpException.COMMON, e);
+ } catch (IllegalAccessException e) {
+ throw new ODataNotFoundException(ODataHttpException.COMMON, e);
+ } catch (InvocationTargetException e) {
+ throw new ODataNotFoundException(ODataHttpException.COMMON, e);
+ }
+ }
+ }
+
+ return dataObject;
+ }
+
+ private <T, V> void setValue(final T data, final String methodName, final V value)
+ throws ODataNotFoundException {
+ try {
+ boolean found = false;
+ for (final Method method : Arrays.asList(data.getClass().getMethods())) {
+ if (method.getName().equals(methodName)) {
+ found = true;
+ final Class<?> type = method.getParameterTypes()[0];
+ if (value == null) {
+ if (type.equals(byte.class) || type.equals(short.class) || type.equals(int.class)
+ || type.equals(long.class) || type.equals(char.class)) {
+ method.invoke(data, 0);
+ } else if (type.equals(float.class) || type.equals(double.class)) {
+ method.invoke(data, 0.0);
+ } else if (type.equals(boolean.class)) {
+ method.invoke(data, false);
+ } else {
+ method.invoke(data, value);
+ }
+ } else {
+ method.invoke(data, value);
+ }
+ break;
+ }
+ }
+ if (!found) {
+ throw new ODataNotFoundException(null);
+ }
+ } catch (SecurityException e) {
+ throw new ODataNotFoundException(null, e);
+ } catch (IllegalArgumentException e) {
+ throw new ODataNotFoundException(null, e);
+ } catch (IllegalAccessException e) {
+ throw new ODataNotFoundException(null, e);
+ } catch (InvocationTargetException e) {
+ throw new ODataNotFoundException(null, e);
+ }
+ }
+
+ private <T> Class<?> getType(final T data, final String methodName) throws ODataNotFoundException {
+ if (data == null) {
+ throw new ODataNotFoundException(ODataHttpException.COMMON);
+ }
+
+ Class<?> type = data.getClass();
+ for (final String method : methodName.split("\\.", -1)) {
+ try {
+ type = type.getMethod(method).getReturnType();
+ if (type.isPrimitive()) {
+ if (type == boolean.class) {
+ type = Boolean.class;
+ } else if (type == byte.class) {
+ type = Byte.class;
+ } else if (type == short.class) {
+ type = Short.class;
+ } else if (type == int.class) {
+ type = Integer.class;
+ } else if (type == long.class) {
+ type = Long.class;
+ } else if (type == float.class) {
+ type = Float.class;
+ } else if (type == double.class) {
+ type = Double.class;
+ }
+ }
+ } catch (final SecurityException e) {
+ throw new ODataNotFoundException(ODataHttpException.COMMON, e);
+ } catch (final NoSuchMethodException e) {
+ throw new ODataNotFoundException(ODataHttpException.COMMON, e);
+ }
+ }
+ return type;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/DataStore.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/DataStore.java b/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/DataStore.java
new file mode 100644
index 0000000..696ab9a
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/DataStore.java
@@ -0,0 +1,192 @@
+/*******************************************************************************
+ * 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.core.annotation.data;
+
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+
+import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
+import org.apache.olingo.odata2.api.exception.ODataApplicationException;
+import org.apache.olingo.odata2.core.annotation.util.AnnotationHelper;
+import org.apache.olingo.odata2.core.exception.ODataRuntimeException;
+
+/**
+ *
+ */
+public class DataStore<T> {
+
+ private static final AnnotationHelper ANNOTATION_HELPER = new AnnotationHelper();
+ private final List<T> dataStore;
+ private final Class<T> dataTypeClass;
+
+ private int idCounter = 1;
+
+ private static class InMemoryDataStore {
+ private static final Map<Class<?>, DataStore<?>> c2ds = new HashMap<Class<?>, DataStore<?>>();
+
+ @SuppressWarnings("unchecked")
+ static DataStore<?> getInstance(Class<?> clz, boolean createNewInstance) {
+ DataStore<?> ds = c2ds.get(clz);
+ if (createNewInstance || ds == null) {
+ ds = new DataStore<Object>((Class<Object>) clz);
+ c2ds.put(clz, ds);
+ }
+ return ds;
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ public static <T> DataStore<T> createInMemory(Class<T> clazz) {
+ return (DataStore<T>) InMemoryDataStore.getInstance(clazz, true);
+ }
+
+ @SuppressWarnings("unchecked")
+ public static <T> DataStore<T> createInMemory(Class<T> clazz, boolean keepExisting) {
+ return (DataStore<T>) InMemoryDataStore.getInstance(clazz, !keepExisting);
+ }
+
+ private DataStore(List<T> wrapStore, Class<T> clz) {
+ dataStore = Collections.synchronizedList(wrapStore);
+ dataTypeClass = clz;
+ }
+
+ private DataStore(Class<T> clz) {
+ this(new ArrayList<T>(), clz);
+ }
+
+ public Class<T> getDataTypeClass() {
+ return dataTypeClass;
+ }
+
+ public String getEntityTypeName() {
+ return ANNOTATION_HELPER.extractEntityTypeName(dataTypeClass);
+ }
+
+ public T createInstance() {
+ try {
+ return dataTypeClass.newInstance();
+ } catch (InstantiationException e) {
+ throw new ODataRuntimeException("Unable to create instance of class '" + dataTypeClass + "'.", e);
+ } catch (IllegalAccessException e) {
+ throw new ODataRuntimeException("Unable to create instance of class '" + dataTypeClass + "'.", e);
+ }
+ }
+
+ public T read(T obj) {
+ List<Object> objKeys = getKeys(obj);
+ for (T stored : dataStore) {
+ if (objKeys.equals(getKeys(stored))) {
+ return stored;
+ }
+ }
+ return null;
+ }
+
+ public Collection<T> read() {
+ return Collections.unmodifiableCollection(dataStore);
+ }
+
+ public T create(T object) throws DataStoreException {
+ synchronized (dataStore) {
+ if (read(object) != null || getKeys(object).contains(null)) {
+ createKeys(object);
+ return this.create(object);
+ }
+ dataStore.add(object);
+ }
+ return object;
+ }
+
+ public T update(T object) {
+ synchronized (dataStore) {
+ T stored = read(object);
+ dataStore.remove(stored);
+ dataStore.add(object);
+ }
+ return object;
+ }
+
+ public T delete(T object) {
+ synchronized (dataStore) {
+ T stored = read(object);
+ if (stored != null) {
+ dataStore.remove(stored);
+ }
+ return stored;
+ }
+ }
+
+ private List<Object> getKeys(T object) {
+ Map<String, Object> keys = ANNOTATION_HELPER.getValueForAnnotatedFields(object, EdmKey.class);
+
+ // XXX: list should be in a defined order -> better to create an 'Key' object which is comparable
+ List<Object> keyList = new ArrayList<Object>(keys.values());
+ return keyList;
+ }
+
+ private T createKeys(T object) throws DataStoreException {
+ List<Field> fields = ANNOTATION_HELPER.getAnnotatedFields(object, EdmKey.class);
+ if (fields.isEmpty()) {
+ throw new DataStoreException("No EdmKey annotated fields found for class " + object.getClass());
+ }
+ Map<String, Object> fieldName2KeyValue = new HashMap<String, Object>();
+
+ for (Field field : fields) {
+ Object key = createKey(field);
+ fieldName2KeyValue.put(ANNOTATION_HELPER.getCanonicalName(field), key);
+ }
+
+ ANNOTATION_HELPER.setValuesToAnnotatedFields(object, EdmKey.class, fieldName2KeyValue);
+
+ return object;
+ }
+
+ private Object createKey(Field field) {
+ Class<?> type = field.getType();
+
+ if (type == String.class) {
+ return String.valueOf(idCounter++);
+ } else if (type == Integer.class || type == int.class) {
+ return Integer.valueOf(idCounter++);
+ } else if (type == Long.class || type == long.class) {
+ return Long.valueOf(idCounter++);
+ }
+
+ throw new UnsupportedOperationException("Automated key generation for type '" + type
+ + "' is not supported (caused on field '" + field + "').");
+ }
+
+ public static class DataStoreException extends ODataApplicationException {
+ private static final long serialVersionUID = 42L;
+
+ public DataStoreException(String message) {
+ this(message, null);
+ }
+
+ public DataStoreException(String message, Throwable cause) {
+ super(message, Locale.ENGLISH, cause);
+ }
+ }
+}
[06/52] git commit: Merge commit
'6750521fcad87549d3013ee61aacd8b6498c0acf' into PocEdmAnnotationsExtension
Posted by mi...@apache.org.
Merge commit '6750521fcad87549d3013ee61aacd8b6498c0acf' into PocEdmAnnotationsExtension
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/cf3f45b8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/cf3f45b8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/cf3f45b8
Branch: refs/heads/master
Commit: cf3f45b81e3178f0eddd67ade7a7ca1163d824ae
Parents: 648d0b4 6750521
Author: Michael Bolz <mi...@sap.com>
Authored: Fri Oct 11 22:24:16 2013 +0200
Committer: Michael Bolz <mi...@sap.com>
Committed: Fri Oct 11 22:24:16 2013 +0200
----------------------------------------------------------------------
.../apache/olingo/odata2/api/uri/UriParser.java | 35 +++++++++++++++
.../olingo/odata2/core/uri/UriParserImpl.java | 31 ++++++++++++++
.../olingo/odata2/core/uri/UriParserTest.java | 45 ++++++++++++++++++++
.../olingo/odata2/fit/ref/MiscChangeTest.java | 18 +++++++-
.../odata2/ref/processor/ListsProcessor.java | 38 +++--------------
5 files changed, 133 insertions(+), 34 deletions(-)
----------------------------------------------------------------------
[41/52] Removed not to merge PoC parts
Posted by mi...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/8764e11a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/json/JsonWriter.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/json/JsonWriter.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/json/JsonWriter.java
deleted file mode 100644
index a277b41..0000000
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/json/JsonWriter.java
+++ /dev/null
@@ -1,204 +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.core.annotation.processor.json;
-
-import java.io.IOException;
-import java.io.Writer;
-
-import org.apache.olingo.odata2.core.exception.ODataRuntimeException;
-
-public class JsonWriter {
-
- private final Writer writer;
- private boolean firstProperty = true;
-
- public JsonWriter(Writer writer) {
- this.writer = writer;
- }
-
- public void startCallback(String functionName) {
- try {
- writer.write(encode(functionName) + "(");
- } catch (IOException e) {
- throw new ODataRuntimeException(e.getMessage(), e);
- }
- }
-
- public void endCallback() {
- try {
- writer.write(");");
- } catch (IOException e) {
- throw new ODataRuntimeException(e.getMessage(), e);
- }
- }
-
- public void startObject() {
- try {
- firstProperty = true;
- writer.write("{\n");
- } catch (IOException e) {
- throw new ODataRuntimeException(e.getMessage(), e);
- }
- }
-
- public void endObject() {
- try {
- firstProperty = false;
- writer.write("\n}");
- } catch (IOException e) {
- throw new ODataRuntimeException(e.getMessage(), e);
- }
- }
-
- public void writeName(String name) {
- try {
- writer.write("\"" + encode(name) + "\" : ");
- } catch (IOException e) {
- throw new ODataRuntimeException(e.getMessage(), e);
- }
- }
-
- public void startArray() {
- try {
- writer.write("[\n");
- } catch (IOException e) {
- throw new ODataRuntimeException(e.getMessage(), e);
- }
- }
-
- public void endArray() {
- try {
- writer.write("\n]");
- } catch (IOException e) {
- throw new ODataRuntimeException(e.getMessage(), e);
- }
- }
-
- public void writeSeparator() {
- try {
- writer.write(", ");
- } catch (IOException e) {
- throw new ODataRuntimeException(e.getMessage(), e);
- }
- }
-
- public void writeRawString(String value) {
- try {
- writer.write("\"" + value + "\"");
- } catch (IOException e) {
- throw new ODataRuntimeException(e.getMessage(), e);
- }
- }
-
- public void writeString(String value) {
- try {
- writer.write("\"" + encode(value) + "\"");
- } catch (IOException e) {
- throw new ODataRuntimeException(e.getMessage(), e);
- }
- }
-
- public void writeNull() {
- try {
- writer.write("null");
- } catch (IOException e) {
- throw new ODataRuntimeException(e.getMessage(), e);
- }
- }
-
- public void writeStringProperty(String name, String value) {
- if (value == null) {
- writeProperty(name, value, false);
- } else {
- writeProperty(name, encode(value), false);
- }
- }
-
- public void writeRawStringProperty(String name, String value) {
- writeProperty(name, value, false);
- }
-
- public void writeRawProperty(String name, String value) {
- writeProperty(name, value, true);
- }
-
- private void writeProperty(String name, String value, boolean raw) {
- if (firstProperty) {
- firstProperty = false;
- } else {
- writeSeparator();
- }
-
- // write content
- this.writeName(name);
- if (value == null) {
- writeNull();
- } else {
- try {
- if (raw) {
- writeRaw(value);
- } else {
- writeString(value);
- }
- } catch (Exception e) {
- writeString("exception for property with name '" + name
- + "' with message '" + e.getMessage()
- + "' and toString '" + value.toString() + "'.");
- }
- }
-
- }
-
- private void writeRaw(String value) {
- try {
- writer.write(value);
- } catch (IOException e) {
- throw new ODataRuntimeException(e.getMessage(), e);
- }
- }
-
- private String encode(String unencoded) {
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < unencoded.length(); i++) {
- char c = unencoded.charAt(i);
- if (c == '\\') {
- sb.append("\\\\");
- } else if (c == '"') {
- sb.append("\\\"");
- } else if (c == '\n') {
- sb.append("\\n");
- } else if (c == '\r') {
- sb.append("\\r");
- } else if (c == '\f') {
- sb.append("\\f");
- } else if (c == '\b') {
- sb.append("\\b");
- } else if (c == '\t') {
- sb.append("\\t");
- } else {
- sb.append(c);
- }
- }
- return sb.toString();
- }
-
- public void start() {
- writeRaw("{\n\"d\":");
- }
-
- public void finish() {
- writeRaw("\n}");
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/8764e11a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/util/AnnotationHelper.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/util/AnnotationHelper.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/util/AnnotationHelper.java
new file mode 100644
index 0000000..0c81fb1
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/util/AnnotationHelper.java
@@ -0,0 +1,726 @@
+/**
+ * *****************************************************************************
+ * 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.core.annotation.util;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Field;
+import java.lang.reflect.ParameterizedType;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.olingo.odata2.api.annotation.edm.EdmComplexType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
+import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty.Multiplicity;
+import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
+import org.apache.olingo.odata2.api.edm.EdmLiteralKind;
+import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
+import org.apache.olingo.odata2.api.edm.EdmSimpleTypeException;
+import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
+import org.apache.olingo.odata2.api.edm.FullQualifiedName;
+import org.apache.olingo.odata2.api.exception.ODataException;
+import org.apache.olingo.odata2.core.exception.ODataRuntimeException;
+
+/**
+ *
+ */
+public class AnnotationHelper {
+
+ public static final String DEFAULT_CONTAINER_NAME = "DefaultContainer";
+
+ /**
+ * Compare keys of both instances.
+ *
+ * @param firstInstance
+ * @param secondInstance
+ * @return
+ */
+ public boolean keyMatch(Object firstInstance, Object secondInstance) {
+ if (firstInstance == null || secondInstance == null) {
+ return false;
+ } else if (firstInstance.getClass() != secondInstance.getClass()) {
+ return false;
+ }
+
+ Map<String, Object> firstKeyFields = getValueForAnnotatedFields(firstInstance, EdmKey.class);
+ Map<String, Object> secondKeyFields = getValueForAnnotatedFields(secondInstance, EdmKey.class);
+
+ return keyValuesMatch(firstKeyFields, secondKeyFields);
+ }
+
+ /**
+ * Compare keys of instance with key values in map.
+ *
+ * @param instance
+ * @param keyName2Value
+ * @return
+ */
+ public boolean keyMatch(Object instance, Map<String, Object> keyName2Value) {
+ Map<String, Object> instanceKeyFields = getValueForAnnotatedFields(instance, EdmKey.class);
+ return keyValuesMatch(instanceKeyFields, keyName2Value);
+ }
+
+ private boolean keyValuesMatch(Map<String, Object> firstKeyValues, Map<String, Object> secondKeyValues) {
+ if (firstKeyValues.size() != secondKeyValues.size()) {
+ return false;
+ } else {
+ Set<Map.Entry<String, Object>> entries = firstKeyValues.entrySet();
+ for (Map.Entry<String, Object> entry : entries) {
+ Object firstKey = entry.getValue();
+ Object secondKey = secondKeyValues.get(entry.getKey());
+ if (!isEqual(firstKey, secondKey)) {
+ return false;
+ }
+ }
+ return true;
+ }
+ }
+
+ private boolean isEqual(Object firstKey, Object secondKey) {
+ if (firstKey == null) {
+ if (secondKey == null) {
+ return true;
+ } else {
+ return secondKey.equals(firstKey);
+ }
+ } else {
+ return firstKey.equals(secondKey);
+ }
+ }
+
+ public String extractEntitTypeName(EdmNavigationProperty enp, Class<?> fallbackClass) {
+ Class<?> entityTypeClass = enp.toType();
+ return extractEntityTypeName(entityTypeClass == Object.class ? fallbackClass : entityTypeClass);
+ }
+
+ public String extractEntitTypeName(EdmNavigationProperty enp, Field field) {
+ Class<?> entityTypeClass = enp.toType();
+ if (entityTypeClass == Object.class) {
+ Class<?> toClass = field.getType();
+ return extractEntityTypeName((toClass.isArray() || Collection.class.isAssignableFrom(toClass) ?
+ (Class<?>) ((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0] : toClass));
+ } else {
+ return extractEntityTypeName(entityTypeClass);
+ }
+ }
+
+ /**
+ * Returns <code>NULL</code> if given class is not annotated. If annotated the set entity type name is returned and if
+ * no name is set the default name is generated from the simple class name.
+ *
+ * @param annotatedClass
+ * @return
+ */
+ public String extractEntityTypeName(Class<?> annotatedClass) {
+ return extractTypeName(annotatedClass, EdmEntityType.class);
+ }
+
+ public FullQualifiedName extractEntityTypeFqn(EdmEntityType type, Class<?> annotatedClass) {
+ if(type.namespace().isEmpty()) {
+ return new FullQualifiedName(generateNamespace(annotatedClass), extractEntityTypeName(annotatedClass));
+ }
+ return new FullQualifiedName(type.namespace(), extractEntityTypeName(annotatedClass));
+ }
+
+ public FullQualifiedName extractEntityTypeFqn(Class<?> annotatedClass) {
+ EdmEntityType type = annotatedClass.getAnnotation(EdmEntityType.class);
+ if(type == null) {
+ return null;
+ }
+ return extractEntityTypeFqn(type, annotatedClass);
+ }
+
+ public FullQualifiedName extractComplexTypeFqn(Class<?> annotatedClass) {
+ EdmComplexType type = annotatedClass.getAnnotation(EdmComplexType.class);
+ if(type == null) {
+ return null;
+ }
+ return extractComplexTypeFqn(type, annotatedClass);
+ }
+
+ public FullQualifiedName extractComplexTypeFqn(EdmComplexType type, Class<?> annotatedClass) {
+ if(type.namespace().isEmpty()) {
+ return new FullQualifiedName(generateNamespace(annotatedClass), extractComplexTypeName(annotatedClass));
+ }
+ return new FullQualifiedName(type.namespace(), extractComplexTypeName(annotatedClass));
+ }
+
+ public String extractComplexTypeName(Class<?> annotatedClass) {
+ return extractTypeName(annotatedClass, EdmComplexType.class);
+ }
+
+ public String generateNamespace(Class<?> annotatedClass) {
+ String packageName = annotatedClass.getPackage().getName();
+ return packageName;
+ }
+
+ /**
+ *
+ *
+ * @param <T> must be EdmEntityType or EdmComplexType annotation
+ * @param annotatedClass
+ * @param typeAnnotation
+ * @return null if annotatedClass is not annotated or name set via annotation or generated via
+ * {@link #getCanonicalName(java.lang.Class)}
+ */
+ private <T extends Annotation> String extractTypeName(Class<?> annotatedClass, Class<T> typeAnnotation) {
+ if (annotatedClass == Object.class) {
+ return null;
+ }
+ T type = annotatedClass.getAnnotation(typeAnnotation);
+ if (type == null) {
+ return null;
+ }
+
+ String name;
+ if (typeAnnotation == EdmEntityType.class) {
+ name = ((EdmEntityType) type).name();
+ } else if (typeAnnotation == EdmComplexType.class) {
+ name = ((EdmComplexType) type).name();
+ } else {
+ return null;
+ }
+
+ if (name.isEmpty()) {
+ return getCanonicalName(annotatedClass);
+ }
+ return name;
+ }
+
+ /**
+ * Get the set property name from an EdmProperty or EdmNavigationProperty annotation.
+ *
+ * @param field
+ * @return
+ */
+ public String getPropertyNameFromAnnotation(Field field) {
+ EdmProperty property = field.getAnnotation(EdmProperty.class);
+ if (property == null) {
+ EdmNavigationProperty navProperty = field.getAnnotation(EdmNavigationProperty.class);
+ if (navProperty == null) {
+ throw new EdmAnnotationException("Given field '" + field
+ + "' has no EdmProperty or EdmNavigationProperty annotation.");
+ }
+ return navProperty.name();
+ }
+ return property.name();
+ }
+
+ public String getPropertyName(Field field) {
+ String propertyName = getPropertyNameFromAnnotation(field);
+ if (propertyName.isEmpty()) {
+ propertyName = getCanonicalName(field);
+ }
+ return propertyName;
+ }
+
+ public String extractFromRoleName(EdmNavigationProperty enp, Field field) {
+ return getCanonicalRole(field.getDeclaringClass());
+ }
+
+ public String extractToRoleName(EdmNavigationProperty enp, Field field) {
+ String role = enp.toRole();
+ if (role.isEmpty()) {
+ role = getCanonicalRole(
+ field.getType().isArray() || Collection.class.isAssignableFrom(field.getType()) ?
+ (Class<?>) ((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0] : field.getType());
+ }
+ return role;
+ }
+
+ public String getCanonicalRole(Class<?> fallbackClass) {
+ String toRole = extractEntityTypeName(fallbackClass);
+ return "r_" + toRole;
+ }
+
+ public String extractRelationshipName(EdmNavigationProperty enp, Field field) {
+ String relationshipName = enp.association();
+ if (relationshipName.isEmpty()) {
+ final String fromRole = extractFromRoleName(enp, field);
+ final String toRole = extractToRoleName(enp, field);
+ if (fromRole.compareTo(toRole) > 0) {
+ relationshipName = toRole + "-" + fromRole;
+ } else {
+ relationshipName = fromRole + "-" + toRole;
+ }
+ }
+ return relationshipName;
+ }
+
+ public EdmMultiplicity getMultiplicity(EdmNavigationProperty enp, Field field) {
+ EdmMultiplicity multiplicity = mapMultiplicity(enp.toMultiplicity());
+ final boolean isCollectionType = field.getType().isArray() || Collection.class.isAssignableFrom(field.getType());
+
+ if (multiplicity == EdmMultiplicity.ONE && isCollectionType) {
+ return EdmMultiplicity.MANY;
+ }
+ return multiplicity;
+ }
+
+
+ /**
+ * Set key fields based on values in map.
+ * If an key field is not available or <code>NULL</code> in the map
+ * it will be not set as <code>NULL</code> at the instance object.
+ *
+ * @param instance
+ * @param keys
+ * @return
+ */
+ public <T> T setKeyFields(T instance, Map<String, Object> keys) {
+ List<Field> fields = getAnnotatedFields(instance, EdmKey.class);
+
+ for (Field field : fields) {
+ String propertyName = getPropertyName(field);
+ Object keyValue = keys.get(propertyName);
+ setValueForProperty(instance, propertyName, keyValue);
+ }
+
+ return instance;
+ }
+
+ public static final class ODataAnnotationException extends ODataException {
+ private static final long serialVersionUID = 1L;
+
+ public ODataAnnotationException(String message) {
+ super(message);
+ }
+ }
+
+
+ public class AnnotatedNavInfo {
+ private final Field fromField;
+ private final Field toField;
+ private final EdmNavigationProperty fromNavigation;
+ private final EdmNavigationProperty toNavigation;
+
+ public AnnotatedNavInfo(Field fromField, Field toField, EdmNavigationProperty fromNavigation,
+ EdmNavigationProperty toNavigation) {
+ this.fromField = fromField;
+ this.toField = toField;
+ this.fromNavigation = fromNavigation;
+ this.toNavigation = toNavigation;
+ }
+
+ public Field getFromField() {
+ return fromField;
+ }
+
+ public Field getToField() {
+ return toField;
+ }
+
+ public EdmMultiplicity getFromMultiplicity() {
+ return getMultiplicity(toNavigation, toField);
+ }
+
+ public EdmMultiplicity getToMultiplicity() {
+ return getMultiplicity(fromNavigation, fromField);
+ }
+
+ public boolean isBiDirectional() {
+ return toNavigation != null;
+ }
+ }
+
+ public AnnotatedNavInfo getCommonNavigationInfo(Class<?> sourceClass, Class<?> targetClass) {
+ List<Field> sourceFields = getAnnotatedFields(sourceClass, EdmNavigationProperty.class);
+ List<Field> targetFields = getAnnotatedFields(targetClass, EdmNavigationProperty.class);
+
+ // first try via association name to get full navigation information
+ for (Field sourceField : sourceFields) {
+ final EdmNavigationProperty sourceNav = sourceField.getAnnotation(EdmNavigationProperty.class);
+ final String sourceAssociation = extractRelationshipName(sourceNav, sourceField);
+ for (Field targetField : targetFields) {
+ final EdmNavigationProperty targetNav = targetField.getAnnotation(EdmNavigationProperty.class);
+ final String targetAssociation = extractRelationshipName(targetNav, targetField);
+ if (sourceAssociation.equals(targetAssociation)) {
+ return new AnnotatedNavInfo(sourceField, targetField, sourceNav, targetNav);
+ }
+ }
+ }
+
+ // if nothing was found assume none bi-directinal navigation
+ String targetEntityTypeName = extractEntityTypeName(targetClass);
+ for (Field sourceField : sourceFields) {
+ final EdmNavigationProperty sourceNav = sourceField.getAnnotation(EdmNavigationProperty.class);
+ final String navTargetEntityName = extractEntitTypeName(sourceNav, sourceField);
+
+ if (navTargetEntityName.equals(targetEntityTypeName)) {
+ return new AnnotatedNavInfo(sourceField, null, sourceNav, null);
+ }
+ }
+
+ return null;
+ }
+
+ public Class<?> getFieldTypeForProperty(Object instance, String propertyName) throws ODataAnnotationException {
+ if (instance == null) {
+ return null;
+ }
+
+ Field field = getFieldForPropertyName(instance, propertyName, instance.getClass(), true);
+ if (field == null) {
+ throw new ODataAnnotationException("No field for property '" + propertyName
+ + "' found at class '" + instance.getClass() + "'.");
+ }
+ return field.getType();
+ }
+
+ public Object getValueForProperty(Object instance, String propertyName) throws ODataAnnotationException {
+ if (instance == null) {
+ return null;
+ }
+
+ Field field = getFieldForPropertyName(instance, propertyName, instance.getClass(), true);
+ if (field == null) {
+ throw new ODataAnnotationException("No field for property '" + propertyName
+ + "' found at class '" + instance.getClass() + "'.");
+ }
+ return getFieldValue(instance, field);
+ }
+
+ public void setValueForProperty(Object instance, String propertyName, Object propertyValue) {
+ if (instance != null) {
+ Field field = getFieldForPropertyName(instance, propertyName, instance.getClass(), true);
+ if (field != null) {
+ setFieldValue(instance, field, propertyValue);
+ }
+ }
+ }
+
+ private Field getFieldForPropertyName(Object instance, String propertyName,
+ Class<?> resultClass, boolean inherited) {
+ if (instance == null) {
+ return null;
+ }
+
+ Field[] fields = resultClass.getDeclaredFields();
+ for (Field field : fields) {
+ EdmProperty property = field.getAnnotation(EdmProperty.class);
+ if (property != null) {
+ if (property.name().isEmpty() && getCanonicalName(field).equals(propertyName)) {
+ return field;
+ } else if (property.name().equals(propertyName)) {
+ return field;
+ }
+ }
+ }
+
+ Class<?> superClass = resultClass.getSuperclass();
+ if (inherited && superClass != Object.class) {
+ return getFieldForPropertyName(instance, propertyName, superClass, true);
+ }
+
+ return null;
+ }
+
+ public Object getValueForField(Object instance, String fieldName, Class<? extends Annotation> annotation) {
+ if (instance == null) {
+ return null;
+ }
+ return getValueForField(instance, fieldName, instance.getClass(), annotation, true);
+ }
+
+ public Object getValueForField(Object instance, Class<? extends Annotation> annotation) {
+ if (instance == null) {
+ return null;
+ }
+ return getValueForField(instance, instance.getClass(), annotation, true);
+ }
+
+ private Object getValueForField(Object instance, Class<?> resultClass,
+ Class<? extends Annotation> annotation, boolean inherited) {
+ return getValueForField(instance, null, resultClass, annotation, inherited);
+ }
+
+ public Map<String, Object> getValueForAnnotatedFields(Object instance,
+ Class<? extends Annotation> annotation) {
+ return getValueForAnnotatedFields(instance, instance.getClass(), annotation, true);
+ }
+
+ private Map<String, Object> getValueForAnnotatedFields(Object instance, Class<?> resultClass,
+ Class<? extends Annotation> annotation, boolean inherited) {
+ if (instance == null) {
+ return null;
+ }
+
+ Field[] fields = resultClass.getDeclaredFields();
+ Map<String, Object> fieldName2Value = new HashMap<String, Object>();
+
+ for (Field field : fields) {
+ if (field.getAnnotation(annotation) != null) {
+ Object value = getFieldValue(instance, field);
+ final EdmProperty property = field.getAnnotation(EdmProperty.class);
+ final String name = property == null || property.name().isEmpty() ? field.getName() : property.name();
+ fieldName2Value.put(name, value);
+ }
+ }
+
+ Class<?> superClass = resultClass.getSuperclass();
+ if (inherited && superClass != Object.class) {
+ Map<String, Object> tmp = getValueForAnnotatedFields(instance, superClass, annotation, true);
+ fieldName2Value.putAll(tmp);
+ }
+
+ return fieldName2Value;
+ }
+
+ public void setValueForAnnotatedField(Object instance, Class<? extends Annotation> annotation, Object value)
+ throws ODataAnnotationException {
+ List<Field> fields = getAnnotatedFields(instance, annotation);
+
+ if(fields.isEmpty()) {
+ throw new ODataAnnotationException("No field found for annotation '" + annotation
+ + "' on instance '" + instance + "'.");
+ } else if(fields.size() > 1) {
+ throw new ODataAnnotationException("More then one field found for annotation '" + annotation
+ + "' on instance '" + instance + "'.");
+ }
+
+ setFieldValue(instance, fields.get(0), value);
+ }
+
+ public void setValuesToAnnotatedFields(Object instance,
+ Class<? extends Annotation> annotation, Map<String, Object> fieldName2Value) {
+ List<Field> fields = getAnnotatedFields(instance, annotation);
+
+ // XXX: refactore
+ for (Field field : fields) {
+ final String canonicalName = getCanonicalName(field);
+ if (fieldName2Value.containsKey(canonicalName)) {
+ Object value = fieldName2Value.get(canonicalName);
+ setFieldValue(instance, field, value);
+ }
+ }
+ }
+
+ public List<Field> getAnnotatedFields(Object instance, Class<? extends Annotation> annotation) {
+ if (instance == null) {
+ return null;
+ }
+ return getAnnotatedFields(instance.getClass(), annotation, true);
+ }
+
+ public List<Field> getAnnotatedFields(Class<?> fieldClass, Class<? extends Annotation> annotation) {
+ return getAnnotatedFields(fieldClass, annotation, true);
+ }
+
+ /**
+ *
+ * @param instance
+ * @param resultClass
+ * @param annotation
+ * @param inherited
+ * @return
+ */
+ private List<Field> getAnnotatedFields(Class<?> resultClass,
+ Class<? extends Annotation> annotation, boolean inherited) {
+ if (resultClass == null) {
+ return null;
+ }
+
+ Field[] fields = resultClass.getDeclaredFields();
+ List<Field> annotatedFields = new ArrayList<Field>();
+
+ for (Field field : fields) {
+ if (field.getAnnotation(annotation) != null) {
+ annotatedFields.add(field);
+ }
+ }
+
+ Class<?> superClass = resultClass.getSuperclass();
+ if (inherited && superClass != Object.class) {
+ List<Field> tmp = getAnnotatedFields(superClass, annotation, true);
+ annotatedFields.addAll(tmp);
+ }
+
+ return annotatedFields;
+ }
+
+ private Object getValueForField(Object instance, String fieldName, Class<?> resultClass,
+ Class<? extends Annotation> annotation, boolean inherited) {
+ if (instance == null) {
+ return null;
+ }
+
+ Field[] fields = resultClass.getDeclaredFields();
+ for (Field field : fields) {
+ if (field.getAnnotation(annotation) != null
+ && (fieldName == null || field.getName().equals(fieldName))) {
+ return getFieldValue(instance, field);
+ }
+ }
+
+ Class<?> superClass = resultClass.getSuperclass();
+ if (inherited && superClass != Object.class) {
+ return getValueForField(instance, fieldName, superClass, annotation, true);
+ }
+
+ return null;
+ }
+
+ private Object getFieldValue(Object instance, Field field) {
+ try {
+ boolean access = field.isAccessible();
+ field.setAccessible(true);
+ Object value = field.get(instance);
+ field.setAccessible(access);
+ return value;
+ } catch (IllegalArgumentException ex) { // should never happen
+ throw new ODataRuntimeException(ex);
+ } catch (IllegalAccessException ex) { // should never happen
+ throw new ODataRuntimeException(ex);
+ }
+ }
+
+ private void setFieldValue(Object instance, Field field, Object value) {
+ try {
+ Object usedValue = value;
+ if (value != null
+ && field.getType() != value.getClass()
+ && value.getClass() == String.class) {
+ usedValue = convert(field, (String) value);
+ }
+ boolean access = field.isAccessible();
+ field.setAccessible(true);
+ field.set(instance, usedValue);
+ field.setAccessible(access);
+ } catch (IllegalArgumentException ex) { // should never happen
+ throw new ODataRuntimeException(ex);
+ } catch (IllegalAccessException ex) { // should never happen
+ throw new ODataRuntimeException(ex);
+ }
+ }
+
+ public Object convert(Field field, String propertyValue) {
+ Class<?> fieldClass = field.getType();
+ try {
+ EdmProperty property = field.getAnnotation(EdmProperty.class);
+ EdmSimpleTypeKind type = mapTypeKind(property.type());
+ return type.getEdmSimpleTypeInstance().valueOfString(propertyValue,
+ EdmLiteralKind.DEFAULT, null, fieldClass);
+ } catch (EdmSimpleTypeException ex) {
+ throw new ODataRuntimeException("Conversion failed for string property with error: "
+ + ex.getMessage(), ex);
+ }
+ }
+
+ public boolean isEdmAnnotated(Object object) {
+ if (object == null) {
+ return false;
+ }
+ return isEdmAnnotated(object.getClass());
+ }
+
+ public boolean isEdmTypeAnnotated(Class<?> clazz) {
+ boolean isComplexEntity = clazz.getAnnotation(EdmComplexType.class) != null;
+ boolean isEntity = clazz.getAnnotation(EdmEntityType.class) != null;
+ return isComplexEntity || isEntity;
+ }
+
+ public boolean isEdmAnnotated(Class<?> clazz) {
+ if (clazz == null) {
+ return false;
+ } else {
+ final boolean isEntity = null != clazz.getAnnotation(EdmEntityType.class);
+ final boolean isEntitySet = null != clazz.getAnnotation(EdmEntitySet.class);
+ final boolean isComplexEntity = null != clazz.getAnnotation(EdmComplexType.class);
+ return isEntity || isComplexEntity || isEntitySet;
+ }
+ }
+
+ public String getCanonicalName(Field field) {
+ return firstCharToUpperCase(field.getName());
+ }
+
+ public String getCanonicalName(Class<?> clazz) {
+ return firstCharToUpperCase(clazz.getSimpleName());
+ }
+
+ private String firstCharToUpperCase(String content) {
+ if (content == null || content.isEmpty()) {
+ return content;
+ }
+ return content.substring(0, 1).toUpperCase(Locale.ENGLISH) + content.substring(1);
+ }
+
+ public EdmSimpleTypeKind mapTypeKind(org.apache.olingo.odata2.api.annotation.edm.EdmType type) {
+ switch (type) {
+ case BINARY: return EdmSimpleTypeKind.Binary;
+ case BOOLEAN: return EdmSimpleTypeKind.Boolean;
+ case BYTE: return EdmSimpleTypeKind.Byte;
+ case COMPLEX: return EdmSimpleTypeKind.Null;
+ case DATE_TIME: return EdmSimpleTypeKind.DateTime;
+ case DATE_TIME_OFFSET: return EdmSimpleTypeKind.DateTimeOffset;
+ case DECIMAL: return EdmSimpleTypeKind.Decimal;
+ case DOUBLE: return EdmSimpleTypeKind.Double;
+ case GUID: return EdmSimpleTypeKind.Guid;
+ case INT16: return EdmSimpleTypeKind.Int16;
+ case INT32: return EdmSimpleTypeKind.Int32;
+ case INT64: return EdmSimpleTypeKind.Int64;
+ case NULL: return EdmSimpleTypeKind.Null;
+ case SBYTE: return EdmSimpleTypeKind.SByte;
+ case SINGLE: return EdmSimpleTypeKind.Single;
+ case STRING: return EdmSimpleTypeKind.String;
+ case TIME: return EdmSimpleTypeKind.Time;
+ default: throw new ODataRuntimeException("Unknown type '" + type
+ + "' for mapping to EdmSimpleTypeKind.");
+ }
+ }
+
+ public EdmMultiplicity mapMultiplicity(Multiplicity multiplicity) {
+ switch (multiplicity) {
+ case ZERO_OR_ONE: return EdmMultiplicity.ZERO_TO_ONE;
+ case ONE: return EdmMultiplicity.ONE;
+ case MANY: return EdmMultiplicity.MANY;
+ default: throw new ODataRuntimeException("Unknown type '" + multiplicity + "' for mapping to EdmMultiplicity.");
+ }
+ }
+
+ /**
+ *
+ */
+ private static class EdmAnnotationException extends RuntimeException {
+
+ private static final long serialVersionUID = 42L;
+
+ public EdmAnnotationException(String message) {
+ super(message);
+ }
+ }
+
+ public String getCanonicalNamespace(Class<?> aClass) {
+ return generateNamespace(aClass);
+ }
+
+ public String extractContainerName(Class<?> aClass) {
+ EdmEntitySet entitySet = aClass.getAnnotation(EdmEntitySet.class);
+ if(entitySet != null) {
+ String containerName = entitySet.container();
+ if(!containerName.isEmpty()) {
+ return containerName;
+ }
+ }
+ return DEFAULT_CONTAINER_NAME;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/8764e11a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/util/ClassHelper.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/util/ClassHelper.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/util/ClassHelper.java
new file mode 100644
index 0000000..5e9fcdb
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/util/ClassHelper.java
@@ -0,0 +1,105 @@
+/*******************************************************************************
+ * 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.core.annotation.util;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.io.FilenameFilter;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ *
+ */
+public class ClassHelper {
+
+ private static final File[] EMPTY_FILE_ARRAY = new File[0];
+
+ private static final FilenameFilter CLASSFILE_FILTER = new FilenameFilter() {
+ @Override
+ public boolean accept(File dir, String name) {
+ return name.endsWith(CLASSFILE_ENDING);
+ }
+ public static final String CLASSFILE_ENDING = ".class";
+ };
+
+ private static final FileFilter FOLDER_FILTER = new FileFilter() {
+ @Override
+ public boolean accept(File pathname) {
+ return pathname.isDirectory();
+ }
+ };
+
+ public static final List<Class<?>> loadClasses(String packageToScan, ClassValidator cv) {
+ return loadClasses(packageToScan, CLASSFILE_FILTER, cv);
+ }
+
+
+ public static final List<Class<?>> loadClasses(String packageToScan, FilenameFilter ff, ClassValidator cv) {
+ final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ String folderToScan = packageToScan.replace(".", "/");
+ URL url = classLoader.getResource(folderToScan);
+ if(url == null) {
+ throw new IllegalArgumentException("No folder to scan found for package '" + packageToScan + "'.");
+ }
+ File folder = new File(url.getFile());
+ File[] classFiles = folder.listFiles(ff);
+ if(classFiles == null) {
+ classFiles = EMPTY_FILE_ARRAY;
+ }
+
+ List<Class<?>> annotatedClasses = new ArrayList<Class<?>>(classFiles.length);
+ for (File file : classFiles) {
+ String name = file.getName();
+ String fqn = packageToScan + "." + name.substring(0, name.length() - 6);
+ try {
+ Class<?> c = classLoader.loadClass(fqn);
+ if (cv.isClassValid(c)) {
+ annotatedClasses.add(c);
+ }
+ } catch (ClassNotFoundException ex) {
+ throw new IllegalArgumentException("Exception during class loading of class '" + fqn +
+ "' with message '" + ex.getMessage() + "'.");
+ }
+ }
+
+ // recursive search
+ File[] subfolders = listSubFolder(folder);
+ for (File file : subfolders) {
+ List<Class<?>> subFolderClazzes = loadClasses(packageToScan + "." + file.getName(), ff, cv);
+ annotatedClasses.addAll(subFolderClazzes);
+ }
+ //
+
+ return annotatedClasses;
+ }
+
+ private static File[] listSubFolder(File folder) {
+ File[] subfolders = folder.listFiles(FOLDER_FILTER);
+ if(subfolders == null) {
+ return EMPTY_FILE_ARRAY;
+ }
+ return subfolders;
+ }
+
+ public interface ClassValidator {
+ boolean isClassValid(Class<?> c);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/8764e11a/odata2-edm-annotation/edm-annotation-core/src/main/resources/log4j.xml
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/resources/log4j.xml b/odata2-edm-annotation/edm-annotation-core/src/main/resources/log4j.xml
deleted file mode 100644
index 90a4706..0000000
--- a/odata2-edm-annotation/edm-annotation-core/src/main/resources/log4j.xml
+++ /dev/null
@@ -1,39 +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>
-
- <logger name="org.apache.olingo.odata2.ref" additivity="false">
- <level value="trace" />
- <appender-ref ref="console" />
- </logger>
-
- <root>
- <priority value="error" />
- <appender-ref ref="console" />
- </root>
-</log4j:configuration>
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/8764e11a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/data/AnnotationsInMemoryDsTest.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/data/AnnotationsInMemoryDsTest.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/data/AnnotationsInMemoryDsTest.java
index b132a0b..04dbefc 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/data/AnnotationsInMemoryDsTest.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/data/AnnotationsInMemoryDsTest.java
@@ -24,10 +24,10 @@ import org.apache.olingo.odata2.api.edm.FullQualifiedName;
import org.apache.olingo.odata2.api.edm.provider.EntitySet;
import org.apache.olingo.odata2.api.exception.ODataException;
import org.apache.olingo.odata2.core.annotation.edm.AnnotationEdmProvider;
-import org.apache.olingo.odata2.core.annotation.edm.AnnotationHelper;
import org.apache.olingo.odata2.core.annotation.model.Building;
import org.apache.olingo.odata2.core.annotation.model.ModelSharedConstants;
import org.apache.olingo.odata2.core.annotation.model.Photo;
+import org.apache.olingo.odata2.core.annotation.util.AnnotationHelper;
import org.junit.Assert;
import org.junit.Test;
import org.mockito.Mockito;
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/8764e11a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/processor/json/JsonConsumerTest.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/processor/json/JsonConsumerTest.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/processor/json/JsonConsumerTest.java
deleted file mode 100644
index 3d7b89d..0000000
--- a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/processor/json/JsonConsumerTest.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * Copyright 2013 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * 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.core.annotation.processor.json;
-
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
-import java.io.UnsupportedEncodingException;
-import java.util.Map;
-
-import org.junit.Assert;
-import org.junit.Test;
-
-/**
- *
- */
-public class JsonConsumerTest {
-
- public static final String SIMPLE_TEAM = "{\"d\":{"
- + "\"__metadata\":{\"id\":\"https://localhost/Test.svc/Teams('1')\","
- + "\"uri\":\"https://localhost/Test.svc/Teams('1')\","
- + "\"type\":\"Test.Team\""
- + "},"
- + "\"Id\":\"1\","
- + "\"Name\":\"Team 1\","
- + "\"isScrumTeam\":false}}";
-
- public static final String SIMPLER_TEAM = "{"
- + "\"d\":{"
- + "\"Id\":\"1\",\"Name\":\"Team 1\",\"isScrumTeam\":false"
- + "}}";
-
- @Test
- public void simplerRead() throws Exception {
- InputStream content = encapsulate(SIMPLER_TEAM);
- JsonConsumer jc = new JsonConsumer(content);
- Map<String, String> name2Values = jc.read();
-
-// System.out.println("" + name2Values);
- Assert.assertEquals(3, name2Values.size());
-
- Assert.assertEquals("1", name2Values.get("Id"));
- Assert.assertEquals("Team 1", name2Values.get("Name"));
- Assert.assertEquals("false", name2Values.get("isScrumTeam"));
- }
-
- @Test
- public void simpleRead() throws Exception {
- InputStream content = encapsulate(SIMPLE_TEAM);
- JsonConsumer jc = new JsonConsumer(content);
- Map<String, String> name2Values = jc.read();
-
-// System.out.println("" + name2Values);
- Assert.assertEquals(6, name2Values.size());
-
- Assert.assertEquals("1", name2Values.get("Id"));
- Assert.assertEquals("Team 1", name2Values.get("Name"));
- Assert.assertEquals("false", name2Values.get("isScrumTeam"));
-
- Assert.assertEquals("https://localhost/Test.svc/Teams('1')", name2Values.get("md_id"));
- Assert.assertEquals("https://localhost/Test.svc/Teams('1')", name2Values.get("md_uri"));
- Assert.assertEquals("Test.Team", name2Values.get("md_type"));
- }
-
- public static InputStream encapsulate(final String content) {
- try {
- return new ByteArrayInputStream(content.getBytes("UTF-8"));
- } catch (UnsupportedEncodingException e) {
- // we know that UTF-8 is supported
- throw new RuntimeException("UTF-8 MUST be supported.", e);
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/8764e11a/odata2-edm-annotation/edm-annotation-webref/pom.xml
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/pom.xml b/odata2-edm-annotation/edm-annotation-webref/pom.xml
index 9f4e99f..18ff957 100644
--- a/odata2-edm-annotation/edm-annotation-webref/pom.xml
+++ b/odata2-edm-annotation/edm-annotation-webref/pom.xml
@@ -21,6 +21,10 @@ the License. -->
<relativePath>..</relativePath>
</parent>
+ <properties>
+ <version.slf4j>1.7.1</version.slf4j>
+ </properties>
+
<build>
<finalName>${project.artifactId}</finalName>
<resources>
@@ -88,17 +92,11 @@ the License. -->
<artifactId>olingo-odata2-edm-annotation-core-incubating</artifactId>
<version>${project.version}</version>
</dependency>
- <dependency>
- <groupId>org.apache.olingo</groupId>
- <artifactId>olingo-odata2-ref-incubating</artifactId>
- <version>${project.version}</version>
- </dependency>
-
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
- <version>1.7.1</version>
+ <version>${version.slf4j}</version>
</dependency>
</dependencies>
[33/52] git commit: Minor refactoring and javadoc for
'api-annotations'
Posted by mi...@apache.org.
Minor refactoring and javadoc for 'api-annotations'
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/49786b4b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/49786b4b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/49786b4b
Branch: refs/heads/master
Commit: 49786b4b7636b9417085bc50301716143766b485
Parents: 5269399
Author: Michael Bolz <mi...@apache.org>
Authored: Mon Dec 2 10:15:37 2013 +0100
Committer: Michael Bolz <mi...@apache.org>
Committed: Mon Dec 2 14:38:56 2013 +0100
----------------------------------------------------------------------
.../annotation/edm/AnnotationEdmProvider.java | 52 ++++++------
.../core/annotation/edm/AnnotationHelper.java | 44 ++++++++++-
.../edm/AnnotationEdmProviderTest.java | 83 +++++++++++++++++++-
.../odata2/core/annotation/model/Photo.java | 3 +-
.../api/annotation/edm/Documentation.java | 4 +
.../api/annotation/edm/EdmComplexType.java | 19 ++++-
.../annotation/edm/EdmConcurrencyControl.java | 3 +-
.../api/annotation/edm/EdmDocumentation.java | 44 +++++++++++
.../odata2/api/annotation/edm/EdmEntitySet.java | 20 ++++-
.../api/annotation/edm/EdmEntityType.java | 21 ++++-
.../odata2/api/annotation/edm/EdmFacets.java | 28 +++++++
.../api/annotation/edm/EdmFunctionImport.java | 75 +++++++++++++++---
.../edm/EdmFunctionImportParameter.java | 55 +++++++++----
.../odata2/api/annotation/edm/EdmKey.java | 9 ++-
.../annotation/edm/EdmMediaResourceContent.java | 13 ++-
.../edm/EdmMediaResourceMimeType.java | 13 ++-
.../annotation/edm/EdmMediaResourceSource.java | 10 ++-
.../annotation/edm/EdmNavigationProperty.java | 47 ++++++++++-
.../odata2/api/annotation/edm/EdmProperty.java | 26 ++++++
.../odata2/api/annotation/edm/Facets.java | 4 +
.../api/annotation/edm/FunctionImport.java | 4 +
.../odata2/api/annotation/edm/Parameter.java | 5 ++
.../odata2/api/annotation/edmx/HttpMethod.java | 6 ++
23 files changed, 508 insertions(+), 80 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/49786b4b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java
index 5d705dc..7dfbd0e 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java
@@ -79,7 +79,6 @@ public class AnnotationEdmProvider extends EdmProvider {
private final Map<String, ContainerBuilder> containerName2ContainerBuilder = new HashMap<String, ContainerBuilder>();
private final Map<String, Schema> namespace2Schema = new HashMap<String, Schema>();
private EntityContainer defaultContainer;
- private String DEFAULT_CONTAINER_NAME = "DefaultContainer";
public AnnotationEdmProvider(Collection<Class<?>> annotatedClasses) {
@@ -251,24 +250,27 @@ public class AnnotationEdmProvider extends EdmProvider {
}
private void updateSchema(Class<?> aClass, EdmEntityType et) {
- String namespace = et.namespace();
- SchemaBuilder b = namespace2SchemaBuilder.get(namespace);
- if (b == null) {
- b = SchemaBuilder.init(namespace);
- namespace2SchemaBuilder.put(namespace, b);
- }
+ SchemaBuilder b = getSchemaBuilder(et.namespace(), aClass);
TypeBuilder typeBuilder = TypeBuilder.init(et, aClass);
b.addEntityType(typeBuilder.buildEntityType());
b.addAssociations(typeBuilder.buildAssociations());
}
- private void updateSchema(Class<?> aClass, EdmComplexType et) {
- String namespace = et.namespace();
- SchemaBuilder b = namespace2SchemaBuilder.get(namespace);
- if (b == null) {
- b = SchemaBuilder.init(namespace);
- namespace2SchemaBuilder.put(namespace, b);
+ private SchemaBuilder getSchemaBuilder(String namespace, Class<?> aClass) {
+ String usedNamespace = namespace;
+ if(usedNamespace.isEmpty()) {
+ usedNamespace = ANNOTATION_HELPER.getCanonicalNamespace(aClass);
}
+ SchemaBuilder builder = namespace2SchemaBuilder.get(usedNamespace);
+ if (builder == null) {
+ builder = SchemaBuilder.init(usedNamespace);
+ namespace2SchemaBuilder.put(usedNamespace, builder);
+ }
+ return builder;
+ }
+
+ private void updateSchema(Class<?> aClass, EdmComplexType et) {
+ SchemaBuilder b = getSchemaBuilder(et.namespace(), aClass);
TypeBuilder typeBuilder = TypeBuilder.init(et, aClass);
b.addComplexType(typeBuilder.buildComplexType());
}
@@ -276,15 +278,15 @@ public class AnnotationEdmProvider extends EdmProvider {
private void handleEntityContainer(Class<?> aClass) {
EdmEntityType entityType = aClass.getAnnotation(EdmEntityType.class);
if (entityType != null) {
- String containerName = DEFAULT_CONTAINER_NAME;
+ FullQualifiedName typeName = createFqnForEntityType(aClass, entityType);
+ String containerName = ANNOTATION_HELPER.extractContainerName(aClass);
ContainerBuilder builder = containerName2ContainerBuilder.get(containerName);
if (builder == null) {
- builder = ContainerBuilder.init(entityType.namespace(), containerName);
+ builder = ContainerBuilder.init(typeName.getNamespace(), containerName);
containerName2ContainerBuilder.put(containerName, builder);
}
EdmEntitySet entitySet = aClass.getAnnotation(EdmEntitySet.class);
if (entitySet != null) {
- FullQualifiedName typeName = createFqnForEntityType(aClass, entityType);
builder.addEntitySet(createEntitySet(typeName, entitySet));
}
}
@@ -295,12 +297,7 @@ public class AnnotationEdmProvider extends EdmProvider {
}
private FullQualifiedName createFqnForEntityType(Class<?> annotatedClass, EdmEntityType entityType) {
- String name = entityType.name();
- if (name.isEmpty()) {
- return new FullQualifiedName(entityType.namespace(), annotatedClass.getSimpleName());
- } else {
- return new FullQualifiedName(entityType.namespace(), entityType.name());
- }
+ return ANNOTATION_HELPER.extractEntityTypeFqn(annotatedClass);
}
private void finish() {
@@ -339,21 +336,17 @@ public class AnnotationEdmProvider extends EdmProvider {
private final List<NavigationProperty> navProperties = new ArrayList<NavigationProperty>();
private final List<Association> associations = new ArrayList<Association>();
- // public TypeBuilder(String namespace, String name) {
- // this.namespace = namespace;
- // this.name = name;
- // }
public TypeBuilder(FullQualifiedName fqn) {
this.namespace = fqn.getNamespace();
this.name = fqn.getName();
}
public static TypeBuilder init(EdmEntityType entity, Class<?> aClass) {
- return new TypeBuilder(ANNOTATION_HELPER.extractEntityTypeFqn(aClass)).withClass(aClass);
+ return new TypeBuilder(ANNOTATION_HELPER.extractEntityTypeFqn(entity, aClass)).withClass(aClass);
}
public static TypeBuilder init(EdmComplexType entity, Class<?> aClass) {
- return new TypeBuilder(ANNOTATION_HELPER.extractComplexTypeFqn(aClass)).withClass(aClass);
+ return new TypeBuilder(ANNOTATION_HELPER.extractComplexTypeFqn(entity, aClass)).withClass(aClass);
}
private TypeBuilder withClass(Class<?> aClass) {
@@ -414,8 +407,7 @@ public class AnnotationEdmProvider extends EdmProvider {
if (baseEntityType != null) {
complexType.setBaseType(baseEntityType);
}
- return complexType.setName(name)
- .setProperties(properties);
+ return complexType.setName(name).setProperties(properties);
}
public EntityType buildEntityType() {
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/49786b4b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java
index 7e92284..462a0bc 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java
@@ -44,6 +44,8 @@ import org.apache.olingo.odata2.core.exception.ODataRuntimeException;
*/
public class AnnotationHelper {
+ public static final String DEFAULT_CONTAINER_NAME = "DefaultContainer";
+
/**
* Compare keys of both instances.
*
@@ -131,19 +133,44 @@ public class AnnotationHelper {
return extractTypeName(annotatedClass, EdmEntityType.class);
}
+ public FullQualifiedName extractEntityTypeFqn(EdmEntityType type, Class<?> annotatedClass) {
+ if(type.namespace().isEmpty()) {
+ return new FullQualifiedName(generateNamespace(annotatedClass), extractEntityTypeName(annotatedClass));
+ }
+ return new FullQualifiedName(type.namespace(), extractEntityTypeName(annotatedClass));
+ }
+
public FullQualifiedName extractEntityTypeFqn(Class<?> annotatedClass) {
EdmEntityType type = annotatedClass.getAnnotation(EdmEntityType.class);
- return new FullQualifiedName(type.namespace(), extractEntityTypeName(annotatedClass));
+ if(type == null) {
+ return null;
+ }
+ return extractEntityTypeFqn(type, annotatedClass);
}
public FullQualifiedName extractComplexTypeFqn(Class<?> annotatedClass) {
EdmComplexType type = annotatedClass.getAnnotation(EdmComplexType.class);
+ if(type == null) {
+ return null;
+ }
+ return extractComplexTypeFqn(type, annotatedClass);
+ }
+
+ public FullQualifiedName extractComplexTypeFqn(EdmComplexType type, Class<?> annotatedClass) {
+ if(type.namespace().isEmpty()) {
+ return new FullQualifiedName(generateNamespace(annotatedClass), extractComplexTypeName(annotatedClass));
+ }
return new FullQualifiedName(type.namespace(), extractComplexTypeName(annotatedClass));
}
public String extractComplexTypeName(Class<?> annotatedClass) {
return extractTypeName(annotatedClass, EdmComplexType.class);
}
+
+ public String generateNamespace(Class<?> annotatedClass) {
+ String packageName = annotatedClass.getPackage().getName();
+ return packageName;
+ }
/**
*
@@ -601,4 +628,19 @@ public class AnnotationHelper {
super(message);
}
}
+
+ public String getCanonicalNamespace(Class<?> aClass) {
+ return generateNamespace(aClass);
+ }
+
+ public String extractContainerName(Class<?> aClass) {
+ EdmEntitySet entitySet = aClass.getAnnotation(EdmEntitySet.class);
+ if(entitySet != null) {
+ String containerName = entitySet.container();
+ if(!containerName.isEmpty()) {
+ return containerName;
+ }
+ }
+ return DEFAULT_CONTAINER_NAME;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/49786b4b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProviderTest.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProviderTest.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProviderTest.java
index b772d6c..494a090 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProviderTest.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProviderTest.java
@@ -16,15 +16,20 @@
package org.apache.olingo.odata2.core.annotation.edm;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
import java.util.List;
+import org.apache.olingo.odata2.api.annotation.edm.EdmComplexType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
import org.apache.olingo.odata2.api.edm.FullQualifiedName;
import org.apache.olingo.odata2.api.edm.provider.Association;
@@ -41,6 +46,7 @@ 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.Schema;
+import org.apache.olingo.odata2.api.exception.ODataException;
import org.apache.olingo.odata2.core.annotation.model.Building;
import org.apache.olingo.odata2.core.annotation.model.City;
import org.apache.olingo.odata2.core.annotation.model.Employee;
@@ -51,7 +57,6 @@ import org.apache.olingo.odata2.core.annotation.model.Photo;
import org.apache.olingo.odata2.core.annotation.model.RefBase;
import org.apache.olingo.odata2.core.annotation.model.Room;
import org.apache.olingo.odata2.core.annotation.model.Team;
-import static org.junit.Assert.assertFalse;
import org.junit.Test;
/**
@@ -59,8 +64,19 @@ import org.junit.Test;
*/
public class AnnotationEdmProviderTest {
- private final Collection<Class<?>> annotatedClasses = new ArrayList<Class<?>>();
+ @EdmEntityType
+ @EdmEntitySet
+ private static final class GeneratedNamesTestClass {}
+
+ @EdmComplexType
+ private static final class GeneratedNamesComplexTestClass {}
+
+ @EdmEntityType(namespace="MyTestNamespace")
+ @EdmEntitySet(container="MyTestContainer")
+ private static final class DefinedNamesTestClass {}
+
private final AnnotationEdmProvider aep;
+ private final Collection<Class<?>> annotatedClasses = new ArrayList<Class<?>>();
public AnnotationEdmProviderTest() {
annotatedClasses.add(RefBase.class);
@@ -77,6 +93,69 @@ public class AnnotationEdmProviderTest {
}
@Test
+ public void defaultNamespaceGeneration() throws ODataException {
+ Collection<Class<?>> localAnnotatedClasses = new ArrayList<Class<?>>();
+ localAnnotatedClasses.add(GeneratedNamesTestClass.class);
+ AnnotationEdmProvider localAep = new AnnotationEdmProvider(localAnnotatedClasses);
+ // validate
+ EntityType testType = localAep.getEntityType(new FullQualifiedName(
+ GeneratedNamesTestClass.class.getPackage().getName(),
+ GeneratedNamesTestClass.class.getSimpleName()));
+ assertNotNull("Requested entity not found.", testType);
+ assertEquals("GeneratedNamesTestClass", testType.getName());
+ assertNull("This should not have a base type", testType.getBaseType());
+ }
+
+ @Test
+ public void defaultNamespaceGenerationComplexType() throws ODataException {
+ Collection<Class<?>> localAnnotatedClasses = new ArrayList<Class<?>>();
+ localAnnotatedClasses.add(GeneratedNamesComplexTestClass.class);
+ AnnotationEdmProvider localAep = new AnnotationEdmProvider(localAnnotatedClasses);
+ // validate
+ ComplexType testType = localAep.getComplexType(new FullQualifiedName(
+ GeneratedNamesComplexTestClass.class.getPackage().getName(),
+ GeneratedNamesComplexTestClass.class.getSimpleName()));
+ assertNotNull("Requested entity not found.", testType);
+ assertEquals("GeneratedNamesComplexTestClass", testType.getName());
+ assertNull("This should not have a base type", testType.getBaseType());
+ }
+
+ @Test
+ public void defaultContainerNameGeneration() throws ODataException {
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ AnnotationEdmProvider localAep =
+ new AnnotationEdmProvider((Collection) Arrays.asList(GeneratedNamesTestClass.class));
+
+ EntityContainerInfo containerInfo = localAep.getEntityContainerInfo(null);
+ assertNotNull(containerInfo);
+ assertEquals("DefaultContainer", containerInfo.getName());
+ }
+
+
+ @Test
+ public void defaultNamespaceDefined() throws ODataException {
+ Collection<Class<?>> localAnnotatedClasses = new ArrayList<Class<?>>();
+ localAnnotatedClasses.add(DefinedNamesTestClass.class);
+ AnnotationEdmProvider localAep = new AnnotationEdmProvider(localAnnotatedClasses);
+ // validate
+ EntityType testClass = localAep.getEntityType(new FullQualifiedName("MyTestNamespace",
+ DefinedNamesTestClass.class.getSimpleName()));
+ assertNotNull("Requested entity not found.", testClass);
+ assertEquals("DefinedNamesTestClass", testClass.getName());
+ assertNull("This should not have a base type", testClass.getBaseType());
+ }
+
+ @Test
+ public void defaultContainerNameDefined() throws ODataException {
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ AnnotationEdmProvider localAep = new AnnotationEdmProvider((Collection) Arrays.asList(DefinedNamesTestClass.class));
+
+ EntityContainerInfo containerInfo = localAep.getEntityContainerInfo(null);
+ assertNotNull(containerInfo);
+ assertEquals("MyTestContainer", containerInfo.getName());
+ }
+
+ @Test
public void loadAnnotatedClassesFromPackage() throws Exception {
AnnotationEdmProvider localAep = new AnnotationEdmProvider("org.apache.olingo.odata2.core.annotation.model");
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/49786b4b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Photo.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Photo.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Photo.java
index 52cb2cc..df7d687 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Photo.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Photo.java
@@ -19,6 +19,7 @@
package org.apache.olingo.odata2.core.annotation.model;
import java.util.Arrays;
+
import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
@@ -27,8 +28,6 @@ import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceMimeType;
import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceSource;
import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
-import org.apache.olingo.odata2.core.annotation.model.ModelSharedConstants;
-import org.apache.olingo.odata2.core.annotation.model.ResourceHelper;
/**
*
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/49786b4b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/Documentation.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/Documentation.java b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/Documentation.java
index f37c766..25fff56 100644
--- a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/Documentation.java
+++ b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/Documentation.java
@@ -23,6 +23,10 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
+/**
+ * @deprecated: As of Olingo version 1.1.x, replaced by {@link EdmDocumentation}.
+ */
+@Deprecated
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.ANNOTATION_TYPE)
public @interface Documentation {
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/49786b4b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmComplexType.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmComplexType.java b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmComplexType.java
index b6b52f3..9b135ef 100644
--- a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmComplexType.java
+++ b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmComplexType.java
@@ -23,9 +23,26 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
+/**
+ * <p>Annotation for a EDM/CSDL ComplexType element.</p>
+ * <p>EdmComplexType holds a set of related information like EdmPrimitiveType
+ * properties and EdmComplexType properties.</p>
+ */
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface EdmComplexType {
+ /**
+ * Define the name for the ComplexType.
+ * If not set a default value has to be generated by the EDM provider.
+ *
+ * @return name for the ComplexType
+ */
String name() default "";
- String namespace();
+ /**
+ * Define the namespace for the ComplexType.
+ * If not set a default value has to be generated by the EDM provider.
+ *
+ * @return namespace for the ComplexType
+ */
+ String namespace() default "";
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/49786b4b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmConcurrencyControl.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmConcurrencyControl.java b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmConcurrencyControl.java
index a94e369..d9475f8 100644
--- a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmConcurrencyControl.java
+++ b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmConcurrencyControl.java
@@ -32,5 +32,4 @@ import java.lang.annotation.Target;
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.ANNOTATION_TYPE)
-public @interface EdmConcurrencyControl {
-}
+public @interface EdmConcurrencyControl {}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/49786b4b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmDocumentation.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmDocumentation.java b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmDocumentation.java
new file mode 100644
index 0000000..bb4059b
--- /dev/null
+++ b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmDocumentation.java
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * 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.api.annotation.edm;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * <p>Additional documentation for an EDM element.</p>
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.ANNOTATION_TYPE)
+public @interface EdmDocumentation {
+ /**
+ * Define a summary for this documentation.
+ *
+ * @return summary of documentation for EDM element
+ */
+ String summary() default "";
+ /**
+ * Complete description for this documentation.
+ *
+ * @return description of documentation for EDM element
+ */
+ String longDescription() default "";
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/49786b4b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmEntitySet.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmEntitySet.java b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmEntitySet.java
index 4a7fa6e..ed00268 100644
--- a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmEntitySet.java
+++ b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmEntitySet.java
@@ -23,9 +23,27 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
+/**
+ * <p>Annotation for a EDM/CSDL EntitySet element.</p>
+ * <p>EdmEntitySet is the container for entity type instances as described in the OData protocol.
+ * The {@link EdmEntitySet} annotation defines the annotated class as entity set and must be used
+ * in conjunction with an {@link EdmEntityType} annotation on a class.</p>
+ */
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface EdmEntitySet {
+ /**
+ * Define the name for the EDM Entity Set.
+ * If not set a default value has to be generated by the EDM provider.
+ *
+ * @return name for the EDM Entity Set
+ */
String name() default "";
-// String container() default "";
+ /**
+ * Define the container name for the EDM Entity Set.
+ * If not set a default value has to be generated by the EDM provider.
+ *
+ * @return container name for the EDM Entity Set
+ */
+ String container() default "";
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/49786b4b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmEntityType.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmEntityType.java b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmEntityType.java
index 67a363d..765ba6c 100644
--- a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmEntityType.java
+++ b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmEntityType.java
@@ -23,9 +23,26 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
+/**
+ * <p>Annotation for a EDM/CSDL EntityType element.</p>
+ * <p>EdmEntityType holds a set of related information like EdmPrimitiveType, EdmComplexType
+ * and EdmNavigation properties.</p>
+ */
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface EdmEntityType {
+ /**
+ * Define the name for the EDM EntityType.
+ * If not set a default value has to be generated by the EDM provider.
+ *
+ * @return name for the EDM EntityType
+ */
String name() default "";
- String namespace();
-}
+ /**
+ * Define the namespace for the EDM EntityType.
+ * If not set a default value has to be generated by the EDM provider.
+ *
+ * @return namespace for the EDM EntityType
+ */
+ String namespace() default "";
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/49786b4b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmFacets.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmFacets.java b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmFacets.java
index 98edf8c..2b7c591 100644
--- a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmFacets.java
+++ b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmFacets.java
@@ -23,11 +23,39 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
+/**
+ * <p>Annotation for definition of EdmFactes on an EdmProperty (for an EdmEntityType or EdmComplexType
+ * which contains the EdmProperty as a field).</p>
+ */
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.ANNOTATION_TYPE)
public @interface EdmFacets {
+ /**
+ * The maximum length of the type in use.
+ * A negative value indicates for the EDM provider an unset/default value.
+ *
+ * @return the maximum length of the type in use as Integer
+ */
int maxLength() default -1;
+ /**
+ * The scale of the type in use.
+ * A negative value indicates for the EDM provider an unset/default value.
+ *
+ * @return the scale of the type in use as Integer
+ */
int scale() default -1;
+ /**
+ * The precision of the type in use.
+ * A negative value indicates for the EDM provider an unset/default value.
+ *
+ * @return the precision of the type in use as Integer
+ */
int precision() default -1;
+ /**
+ * The information if the type in use is nullable.
+ * The default value for nullable is <code>false</code>.
+ *
+ * @return <code>true</code> if the type in use is nullable, <code>false</code> otherwise.
+ */
boolean nullable() default false;
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/49786b4b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmFunctionImport.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmFunctionImport.java b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmFunctionImport.java
index dd85784..1972cb4 100644
--- a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmFunctionImport.java
+++ b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmFunctionImport.java
@@ -23,27 +23,78 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
-import org.apache.olingo.odata2.api.annotation.edmx.HttpMethod;
-import org.apache.olingo.odata2.api.annotation.edmx.HttpMethod.Name;
-
+/**
+ * <p>Annotation for definition of an method as an {@link EdmFunctionImport} call/endpoint.</p>
+ */
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface EdmFunctionImport {
- enum Type {
- SIMPLE, ENTITY, COMPLEX
- }
-
+ /**
+ * <p>Annotation for definition of the return type of an {@link EdmFunctionImport} method.</p>
+ */
@interface ReturnType {
+ /**
+ * Concrete return types as specified in OData.
+ */
+ enum Type {
+ SIMPLE, ENTITY, COMPLEX
+ }
+
+ /**
+ * Define the return type for the function import.
+ *
+ * @return return type for the function import
+ */
Type type();
+ /**
+ * Define if the return type for the function import is a collection (entity set) or
+ * an single entity (entity).
+ *
+ * @return <code>true</code> if a collection is returned,
+ * otherwise <code>false</code> if a single entity is returned.
+ */
boolean isCollection() default false;
}
+ /**
+ * Concrete HttpMethods for a function import as specified in OData.
+ */
+ enum HttpMethod {
+ POST, PUT, GET, MERGE, DELETE, PATCH
+ };
+
+ /**
+ * Define the name for the function import.
+ * If not set a default value has to be generated by the EDM provider.
+ *
+ * @return name for the function import
+ */
String name() default "";
-
+ /**
+ * Define the name for the according entity set of the function import.
+ * If not set a default value has to be generated by the EDM provider.
+ *
+ * @return name for the according entity set of the function import
+ */
String entitySet() default "";
-
+ /**
+ * Define the return type of this function import
+ *
+ * @return return type of this function import
+ */
ReturnType returnType();
-
- HttpMethod httpMethod() default @HttpMethod(name = Name.GET);
-}
+ /**
+ * Define the http method for which this function import is used
+ * If not set the default http method <code>GET</code> is used.
+ *
+ * @return http method for which this function import is used
+ */
+ HttpMethod httpMethod() default HttpMethod.GET;
+ /**
+ * Defines additional documentation for this function import.
+ *
+ * @return additional documentation for this function import.
+ */
+ EdmDocumentation documentation() default @EdmDocumentation;
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/49786b4b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmFunctionImportParameter.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmFunctionImportParameter.java b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmFunctionImportParameter.java
index d5b2e80..74d1072 100644
--- a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmFunctionImportParameter.java
+++ b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmFunctionImportParameter.java
@@ -1,20 +1,20 @@
/*******************************************************************************
* 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
+ * 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
+ * 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.
+ * 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.api.annotation.edm;
@@ -22,12 +22,37 @@ import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
+
import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
+/**
+ * <p>Annotation for definition of an {@link EdmFunctionImportParameter} for an {@link EdmFunctionImport}
+ * which contains the {@link EdmFunctionImportParameter} as a parameter.</p>
+ * The EdmProperty annotation has to be used on a parameter within a {@link EdmFunctionImport} annotated method.
+ */
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.PARAMETER)
public @interface EdmFunctionImportParameter {
+ /**
+ * Define the name for the Function Import Parameter.
+ * If not set a default value has to be generated by the EDM provider.
+ *
+ * @return name for the Function Import Parameter
+ */
String name();
+ /**
+ * Define the EdmSimpleType which is used for the Function Import Parameter in the EDM.
+ * If not set a default value has to be generated by the EDM provider (which should be compatible to the
+ * java type of the annotated field).
+ *
+ * @return type for the Function Import Parameter as used in the EDM
+ */
EdmSimpleTypeKind type() default EdmSimpleTypeKind.Null;
- Facets facets() default @Facets;
-}
+ /**
+ * Define the EdmFacets for the Function Import Parameter in the EDM.
+ * If not set the default EdmFacet values are used (see {@link EdmFacets}).
+ *
+ * @return facets for the Function Import Parameter as used in the EDM
+ */
+ EdmFacets facets() default @EdmFacets;
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/49786b4b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmKey.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmKey.java b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmKey.java
index 48db91f..d6495e7 100644
--- a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmKey.java
+++ b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmKey.java
@@ -23,7 +23,12 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
+/**
+ * <p>Annotation for definition of an EdmProperty as EdmKey for the EdmEntityType which contains the EdmProperty.</p>
+ * This annotation can not be parameterized, all values like name are defined via the {@link EdmProperty} annotation.
+ * In addition the EdmKey annotation has to be used in conjunction with an EdmProperty annotation on a field
+ * within a EdmEntityType annotated class.
+ */
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
-public @interface EdmKey {
-}
+public @interface EdmKey {}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/49786b4b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmMediaResourceContent.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmMediaResourceContent.java b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmMediaResourceContent.java
index 80e9cd8..ccdcac3 100644
--- a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmMediaResourceContent.java
+++ b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmMediaResourceContent.java
@@ -23,7 +23,16 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
+/**
+ * <p>Annotation for definition of an {@link EdmProperty} as <b>media resource content</b> for the
+ * {@link EdmEntityType}
+ * which contains the {@link EdmProperty}. Additionally an {@link EdmEntityType} will be flagged in the EDM as
+ * <code>hasStream == true</code> if an {@link EdmProperty} in conjunction with the {@link EdmMediaResourceContent}
+ * annotation is defined.</p>
+ * This annotation can not be parameterized, all values like name are defined via the {@link EdmProperty} annotation.
+ * In addition the {@link EdmMediaResourceContent} annotation has to be used in conjunction with an
+ * {@link EdmProperty} annotation on a field within an {@link EdmEntityType} annotated class.
+ */
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
-public @interface EdmMediaResourceContent {
-}
+public @interface EdmMediaResourceContent {}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/49786b4b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmMediaResourceMimeType.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmMediaResourceMimeType.java b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmMediaResourceMimeType.java
index d255ff4..67068bb 100644
--- a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmMediaResourceMimeType.java
+++ b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmMediaResourceMimeType.java
@@ -23,7 +23,16 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
+/**
+ * <p>Annotation for definition of an {@link EdmProperty} as <b>mime type for the media resource</b>
+ * of the {@link EdmEntityType} which contains the {@link EdmProperty}.
+ * The value of the {@link EdmMediaResourceMimeType} annotated field will be used as <code>Content-Type</code>
+ * of the media content response (of an OData <code>$value</code> request).
+ * </p>
+ * This annotation can not be parameterized, all values like name are defined via the {@link EdmProperty} annotation.
+ * In addition the {@link EdmMediaResourceMimeType} annotation has to be used in conjunction with an
+ * {@link EdmProperty} annotation on a field within an {@link EdmEntityType} annotated class.
+ */
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
-public @interface EdmMediaResourceMimeType {
-}
+public @interface EdmMediaResourceMimeType {}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/49786b4b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmMediaResourceSource.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmMediaResourceSource.java b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmMediaResourceSource.java
index 78e72b5..f9ea72d 100644
--- a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmMediaResourceSource.java
+++ b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmMediaResourceSource.java
@@ -23,7 +23,13 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
+/**
+ * <p>Annotation for definition of an {@link EdmProperty} as <b>media resource source</b> for the {@link EdmEntityType}
+ * which contains the {@link EdmProperty}.
+ * This annotation can not be parameterized, all values like name are defined via the {@link EdmProperty} annotation.
+ * In addition the {@link EdmMediaResourceSource} annotation has to be used in conjunction with an
+ * {@link EdmProperty} annotation on a field within an {@link EdmEntityType} annotated class.
+ */
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
-public @interface EdmMediaResourceSource {
-}
+public @interface EdmMediaResourceSource {}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/49786b4b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmNavigationProperty.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmNavigationProperty.java b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmNavigationProperty.java
index 7cdad48..c193e13 100644
--- a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmNavigationProperty.java
+++ b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmNavigationProperty.java
@@ -25,13 +25,52 @@ import java.lang.annotation.Target;
import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
+/**
+ * <p>Annotation for definition of an EdmNavigationProperty for an EdmEntityType
+ * which contains the navigation property as a field.</p>
+ * The EdmNavigationProperty annotation has to be used on a field within a EdmEntityType annotated class.
+ */
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface EdmNavigationProperty {
-
+ /**
+ * Define the name for the Navigation Property.
+ * If not set a default value has to be generated by the EDM provider.
+ *
+ * @return name for the Navigation Property
+ */
String name() default "";
+ /**
+ * Define the target entity in form of a java class for the Navigation Property.
+ * The referenced java class must be annotated with {@link EdmEntityType}.
+ * If not set a EDM provider should be able to determine the corresponding type or
+ * to handle the default setting.
+ *
+ * @return referenced java class which must be annotated with {@link EdmEntityType}.
+ */
Class<?> toType() default Object.class;
- String association() default ""; // if not set -> will be generated
- String toRole() default ""; // if not set -> will be generated
+ /**
+ * Define the name for the related Edm Association Set (of the Navigation Property).
+ * If not set a default value has to be generated by the EDM provider.
+ *
+ * @return name for the related Edm Association Set (of the Navigation Property).
+ */
+ String association() default "";
+ /**
+ * Define the name for the related Edm Role (of the Navigation Property).
+ * If not set a default value has to be generated by the EDM provider.
+ *
+ * @return name for the related Edm Role (of the Navigation Property).
+ */
+ String toRole() default "";
+ /**
+ * Define the multiplicity to the target EdmEntity of the Navigation Property.
+ * If not set a default multiplicity of <code>ONE</code> is assumed.
+ * This could be overwritten by the EDM provider if the correct multiplicity can be determined.
+ * As example: The default multiplicity of <code>ONE</code> on a field (EdmProperty) with
+ * a java type <code>Collection</code> can be overwritten by a multiplicity of <code>MANY</code>.
+ *
+ * @return multiplicity to the target EdmEntity of the Navigation Property.
+ */
EdmMultiplicity toMultiplicity() default EdmMultiplicity.ONE;
-}
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/49786b4b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmProperty.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmProperty.java b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmProperty.java
index 14911ce..6e45598 100644
--- a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmProperty.java
+++ b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmProperty.java
@@ -22,12 +22,38 @@ import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
+
import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
+/**
+ * <p>Annotation for definition of an EdmProperty for an EdmEntityType or EdmComplexType
+ * which contains the EdmProperty as a field.</p>
+ * The EdmProperty annotation has to be used on a field within a EdmEntityType or EdmComplexType annotated class.
+ */
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface EdmProperty {
+ /**
+ * Define the EdmSimpleType which is used for the Property in the EDM.
+ * If not set a default value has to be generated by the EDM provider (which should be compatible to the
+ * java type of the annotated field).
+ * If the property is a EdmComplexType (and no EdmSimpleType) the default value has to be used.
+ *
+ * @return type for the Property as used in the EDM
+ */
EdmSimpleTypeKind type() default EdmSimpleTypeKind.Null;
+ /**
+ * Define the name for the Property.
+ * If not set a default value has to be generated by the EDM provider.
+ *
+ * @return name for the Property
+ */
String name() default "";
+ /**
+ * Define the EdmFacets for the Property in the EDM.
+ * If not set the default EdmFacet values are used (see {@link EdmFacets}).
+ *
+ * @return facets for the Property as used in the EDM
+ */
EdmFacets facets() default @EdmFacets;
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/49786b4b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/Facets.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/Facets.java b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/Facets.java
index d59a3de..fec2f8d 100644
--- a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/Facets.java
+++ b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/Facets.java
@@ -23,6 +23,10 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
+/**
+ * @deprecated: As of Olingo version 1.1.x, replaced by {@link EdmFacets}.
+ */
+@Deprecated
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.ANNOTATION_TYPE)
public @interface Facets {
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/49786b4b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/FunctionImport.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/FunctionImport.java b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/FunctionImport.java
index 5101cc3..0704a66 100644
--- a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/FunctionImport.java
+++ b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/FunctionImport.java
@@ -26,6 +26,10 @@ import java.lang.annotation.Target;
import org.apache.olingo.odata2.api.annotation.edmx.HttpMethod;
import org.apache.olingo.odata2.api.annotation.edmx.HttpMethod.Name;
+/**
+ * * @deprecated: As of Olingo version 1.1.x, replaced by {@link EdmFunctionImport}.
+ */
+@Deprecated
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface FunctionImport {
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/49786b4b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/Parameter.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/Parameter.java b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/Parameter.java
index ee685e4..a5aeb35 100644
--- a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/Parameter.java
+++ b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/Parameter.java
@@ -23,6 +23,11 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
+/**
+ * @deprecated: As of Olingo version 1.1.x, replaced by @link {@link EdmFunctionImportParameter}
+ * within {@link EdmFunctionImport}.
+ */
+@Deprecated
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.PARAMETER)
public @interface Parameter {
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/49786b4b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edmx/HttpMethod.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edmx/HttpMethod.java b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edmx/HttpMethod.java
index 9e8321a..6912e47 100644
--- a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edmx/HttpMethod.java
+++ b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edmx/HttpMethod.java
@@ -23,6 +23,12 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
+import org.apache.olingo.odata2.api.annotation.edm.EdmFunctionImport;
+
+/**
+ * @deprecated: As of Olingo version 1.1.x, replaced by HttpMethod enum within {@link EdmFunctionImport}.
+ */
+@Deprecated
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.ANNOTATION_TYPE)
public @interface HttpMethod {
[23/52] Added support for multiple 'EdmKey' annotations
Posted by mi...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/b7e7ee0d/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java
index d43f8c9..cca0b5e 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java
@@ -78,14 +78,57 @@ public class AnnotationHelper {
}
}
+ /**
+ * Get the set property name from an EdmProperty or EdmNavigationProperty annotation.
+ *
+ * @param field
+ * @return
+ */
+ public String getPropertyNameFromAnnotation(Field field) {
+ EdmProperty property = field.getAnnotation(EdmProperty.class);
+ if(property == null) {
+ EdmNavigationProperty navProperty = field.getAnnotation(EdmNavigationProperty.class);
+ if(navProperty == null) {
+ throw new EdmAnnotationException("Given field '" + field
+ + "' has no EdmProperty or EdmNavigationProperty annotation.");
+ }
+ return navProperty.name();
+ }
+ return property.name();
+ }
+
+ public String getPropertyName(Field field) {
+ String propertyName = getPropertyNameFromAnnotation(field);
+ if (propertyName.isEmpty()) {
+ propertyName = getCanonicalName(field);
+ }
+ return propertyName;
+ }
+
public static final class ODataAnnotationException extends ODataException {
public ODataAnnotationException(String message) {
super(message);
}
}
-
- public <T> T setKeyFields(T instance, Object[] keyValues) {
+
+ public <T> T setKeyFields(T instance, Map<String, Object> keys) {
+ List<Field> fields = getAnnotatedFields(instance, EdmKey.class);
+ if (fields.size() != keys.size()) {
+ throw new IllegalStateException("Wrong amount of key properties. Expected read keys = "
+ + fields + " given key predicates = " + keys);
+ }
+
+ for (Field field : fields) {
+ String propertyName = getPropertyName(field);
+ Object keyValue = keys.get(propertyName);
+ setValueForProperty(instance, propertyName, keyValue);
+ }
+
+ return instance;
+ }
+
+ public <T> T setKeyFields__(T instance, Object[] keyValues) {
List<Field> fields = getAnnotatedFields(instance, EdmKey.class);
if (fields.size() != keyValues.length) {
throw new IllegalStateException("Wrong amount of key properties. Expected read keys = "
@@ -370,7 +413,8 @@ public class AnnotationHelper {
return type.getEdmSimpleTypeInstance().valueOfString(propertyValue,
EdmLiteralKind.DEFAULT, null, fieldClass);
} catch (EdmSimpleTypeException ex) {
- throw new ODataRuntimeException(ex);
+ throw new ODataRuntimeException("Conversion failed for string property with error: "
+ + ex.getMessage(), ex);
}
}
@@ -406,4 +450,11 @@ public class AnnotationHelper {
}
return content.substring(0, 1).toUpperCase(Locale.ENGLISH) + content.substring(1);
}
+
+
+ private static class EdmAnnotationException extends RuntimeException {
+ public EdmAnnotationException(String message) {
+ super(message);
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/b7e7ee0d/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/AnnotationProcessor.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/AnnotationProcessor.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/AnnotationProcessor.java
index 23fc743..b1b8730 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/AnnotationProcessor.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/AnnotationProcessor.java
@@ -44,7 +44,7 @@ import org.apache.olingo.odata2.api.uri.info.GetEntityUriInfo;
import org.apache.olingo.odata2.api.uri.info.GetMediaResourceUriInfo;
import org.apache.olingo.odata2.api.uri.info.PostUriInfo;
import org.apache.olingo.odata2.api.uri.info.PutMergePatchUriInfo;
-import org.apache.olingo.odata2.core.annotation.ds.DataSourceHolder;
+import org.apache.olingo.odata2.core.annotation.data.DataSourceHolder;
import org.apache.olingo.odata2.core.annotation.edm.AnnotationHelper;
import org.apache.olingo.odata2.core.annotation.edm.ClassHelper;
import org.apache.olingo.odata2.core.annotation.processor.json.EdmAnnotationSerializer;
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/b7e7ee0d/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/data/AnnotationsInMemoryDsTest.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/data/AnnotationsInMemoryDsTest.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/data/AnnotationsInMemoryDsTest.java
new file mode 100644
index 0000000..0aaf309
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/data/AnnotationsInMemoryDsTest.java
@@ -0,0 +1,157 @@
+/*
+ * Copyright 2013 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * 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.core.annotation.data;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.olingo.odata2.api.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.edm.FullQualifiedName;
+import org.apache.olingo.odata2.api.edm.provider.EntityType;
+import org.apache.olingo.odata2.api.exception.ODataApplicationException;
+import org.apache.olingo.odata2.api.exception.ODataException;
+import org.apache.olingo.odata2.core.annotation.edm.AnnotationEdmProvider;
+import org.apache.olingo.odata2.core.annotation.model.Building;
+import org.apache.olingo.odata2.core.annotation.model.ModelSharedConstants;
+import org.apache.olingo.odata2.core.annotation.model.Photo;
+import org.junit.Assert;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+/**
+ *
+ */
+public class AnnotationsInMemoryDsTest {
+
+ private final AnnotationInMemoryDs datasource;
+ private AnnotationEdmProvider edmProvider;
+ private static final String DEFAULT_CONTAINER = ModelSharedConstants.CONTAINER_1;
+ private static final String DEFAULT_NAMESPACE = ModelSharedConstants.NAMESPACE_1;
+
+ public AnnotationsInMemoryDsTest() {
+ datasource = new AnnotationInMemoryDs(Building.class.getPackage().getName());
+ edmProvider = new AnnotationEdmProvider(Building.class.getPackage().getName());
+ }
+
+
+ @Test(expected = ODataApplicationException.class)
+ public void invalidEntity() throws Exception {
+ EdmEntitySet edmEntitySet = createMockedEdmEntitySet("Building");
+
+ datasource.createData(edmEntitySet, this);
+ }
+
+ @Test
+ public void createSimpleEntity() throws Exception {
+ EdmEntitySet edmEntitySet = createMockedEdmEntitySet("Building");
+
+ Building building = new Building();
+ building.setName("Common Building");
+ datasource.createData(edmEntitySet, building);
+
+ Map<String, Object> keys = new HashMap<String, Object>();
+ keys.put("Id", "1");
+
+ Building read = (Building) datasource.readData(edmEntitySet, keys);
+ Assert.assertEquals("Common Building", read.getName());
+ }
+
+ @Test
+ public void createEntityTwoKeys() throws Exception {
+ EdmEntitySet edmEntitySet = createMockedEdmEntitySet("Photo");
+
+ Photo photo = new Photo();
+ photo.setName("BigPicture");
+ photo.setType("PNG");
+ photo.setImageUri("https://localhost/image.png");
+ photo.setImageType("image/png");
+ datasource.createData(edmEntitySet, photo);
+
+ Map<String, Object> keys = new HashMap<String, Object>();
+// keys.put("ImageFormat", "PNG");
+// keys.put("Name", "BigPicture");
+ keys.put("Name", "1");
+ keys.put("ImageFormat", "2");
+
+ Photo read = (Photo) datasource.readData(edmEntitySet, keys);
+// Assert.assertEquals("BigPicture", read.getName());
+ Assert.assertEquals("1", read.getName());
+ Assert.assertEquals("2", read.getType());
+ Assert.assertEquals("image/png", read.getImageType());
+ Assert.assertEquals("https://localhost/image.png", read.getImageUri());
+ }
+
+ @Test
+// @Ignore("Rethink update method")
+ public void createAndUpdateEntityTwoKeys() throws Exception {
+ EdmEntitySet edmEntitySet = createMockedEdmEntitySet("Photo");
+
+ Photo photo = new Photo();
+ final String nameKeyValue = "BigPicture";
+ final String typeKeyValue = "PNG";
+ photo.setName(nameKeyValue);
+ photo.setType(typeKeyValue);
+ photo.setImageUri("https://localhost/image.png");
+ photo.setImageType("image/png");
+ datasource.createData(edmEntitySet, photo);
+
+ Map<String, Object> keys = new HashMap<String, Object>();
+ keys.put("Name", "1");
+ keys.put("ImageFormat", "2");
+
+ Photo read = (Photo) datasource.readData(edmEntitySet, keys);
+ Assert.assertEquals("1", read.getName());
+ Assert.assertEquals("2", read.getType());
+ Assert.assertEquals("image/png", read.getImageType());
+ Assert.assertEquals("https://localhost/image.png", read.getImageUri());
+
+
+ // update
+ Photo updatedPhoto = new Photo();
+// updatedPhoto.setName(nameKeyValue);
+// updatedPhoto.setType(typeKeyValue);
+ updatedPhoto.setName("1");
+ updatedPhoto.setType("2");
+ updatedPhoto.setImageUri("https://localhost/image.jpg");
+ updatedPhoto.setImageType("image/jpg");
+ datasource.updateData(edmEntitySet, updatedPhoto);
+
+ Map<String, Object> updatedKeys = new HashMap<String, Object>();
+// updatedKeys.put("Name", nameKeyValue);
+// updatedKeys.put("ImageFormat", typeKeyValue);
+ updatedKeys.put("Name", "1");
+ updatedKeys.put("ImageFormat", "2");
+
+ Photo readUpdated = (Photo) datasource.readData(edmEntitySet, updatedKeys);
+ Assert.assertEquals("1", readUpdated.getName());
+ Assert.assertEquals("2", readUpdated.getType());
+ Assert.assertEquals("image/jpg", readUpdated.getImageType());
+ Assert.assertEquals("https://localhost/image.jpg", readUpdated.getImageUri());
+ }
+
+ private EdmEntitySet createMockedEdmEntitySet(String entitySetName) throws ODataException {
+// EntitySet entitySet = edmProvider.getEntitySet(DEFAULT_CONTAINER, entitySetName);
+ EntityType entityType = edmProvider.getEntityType(new FullQualifiedName(DEFAULT_NAMESPACE, entitySetName));
+
+ EdmEntitySet edmEntitySet = Mockito.mock(EdmEntitySet.class);
+ EdmEntityType edmEntityType = Mockito.mock(EdmEntityType.class);
+ Mockito.when(edmEntitySet.getEntityType()).thenReturn(edmEntityType);
+ Mockito.when(edmEntityType.getName()).thenReturn(entityType.getName());
+
+ return edmEntitySet;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/b7e7ee0d/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProviderTest.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProviderTest.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProviderTest.java
index 4a875a2..4d1a6b7 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProviderTest.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProviderTest.java
@@ -36,6 +36,7 @@ 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.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;
@@ -50,11 +51,11 @@ import org.apache.olingo.odata2.core.annotation.model.Photo;
import org.apache.olingo.odata2.core.annotation.model.RefBase;
import org.apache.olingo.odata2.core.annotation.model.Room;
import org.apache.olingo.odata2.core.annotation.model.Team;
+import static org.junit.Assert.assertFalse;
import org.junit.Test;
/**
*
- * @author d046871
*/
public class AnnotationEdmProviderTest {
@@ -148,7 +149,7 @@ public class AnnotationEdmProviderTest {
EntityContainer container = containers.get(0);
assertEquals(ModelSharedConstants.CONTAINER_1, container.getName());
final List<EntitySet> entitySets = container.getEntitySets();
- assertEquals(5, entitySets.size());
+ assertEquals(6, entitySets.size());
List<Association> associations = schema.getAssociations();
assertEquals(4, associations.size());
@@ -257,6 +258,33 @@ public class AnnotationEdmProviderTest {
}
@Test
+ public void entityTypePhotoWithTwoKeyProperties() throws Exception {
+ // validate team
+ EntityType photo = aep.getEntityType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "Photo"));
+ assertEquals("Photo", photo.getName());
+ final List<Property> properties = photo.getProperties();
+ assertEquals(5, properties.size());
+ assertTrue(containsProperty(properties, "Name"));
+ assertTrue(containsProperty(properties, "ImageFormat"));
+ assertTrue(containsProperty(properties, "MimeType"));
+ assertTrue(containsProperty(properties, "ImageUrl"));
+ assertTrue(containsProperty(properties, "Image"));
+ assertFalse(photo.isAbstract());
+ assertTrue(photo.isHasStream());
+
+ Key photoKey = photo.getKey();
+ List<PropertyRef> keyReferences = photoKey.getKeys();
+ assertEquals(2, keyReferences.size());
+ PropertyRef name = getPropertyRef(keyReferences, "Name");
+ assertEquals("Name", name.getName());
+ PropertyRef imageFormat = getPropertyRef(keyReferences, "ImageFormat");
+ assertEquals("ImageFormat", imageFormat.getName());
+
+// assertEquals(0, photo.getNavigationProperties().size());
+ assertNull(photo.getNavigationProperties());
+ }
+
+ @Test
public void entityTypeAbstractBaseType() throws Exception {
// validate employee
EntityType baseType = aep.getEntityType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "Base"));
@@ -331,4 +359,26 @@ public class AnnotationEdmProviderTest {
String relationship, String fromRole, String toRole) {
validateNavProperty(navigationProperty, null, relationship, fromRole, toRole);
}
+
+ private boolean containsProperty(List<Property> properties, String propertyName) {
+ return getProperty(properties, propertyName) != null;
+ }
+
+ private Property getProperty(List<Property> properties, String name) {
+ for (Property property : properties) {
+ if(name.equals(property.getName())) {
+ return property;
+ }
+ }
+ return null;
+ }
+
+ private PropertyRef getPropertyRef(List<PropertyRef> properties, String name) {
+ for (PropertyRef property : properties) {
+ if(name.equals(property.getName())) {
+ return property;
+ }
+ }
+ return null;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/b7e7ee0d/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Building.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Building.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Building.java
index 2abf4e3..f1a3fa9 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Building.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Building.java
@@ -39,7 +39,7 @@ import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
public class Building {
@EdmKey
@EdmProperty(type = EdmSimpleTypeKind.String)
- private int id;
+ private String id;
@EdmProperty
private String name;
private byte[] image;
@@ -47,16 +47,8 @@ public class Building {
to = @NavigationEnd(role = "r_Room", entitySet=Room.class, multiplicity = EdmMultiplicity.MANY))
private List<Room> rooms = new ArrayList<Room>();
- public Building() {
- }
-
- public Building(final int id, final String name) {
- this.id = id;
- setName(name);
- }
-
public String getId() {
- return Integer.toString(id);
+ return id;
}
public void setName(final String name) {
@@ -85,7 +77,10 @@ public class Building {
@Override
public int hashCode() {
- return id;
+ if(id == null) {
+ return 0;
+ }
+ return id.hashCode();
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/b7e7ee0d/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Photo.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Photo.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Photo.java
index 6c89654..52cb2cc 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Photo.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Photo.java
@@ -19,31 +19,38 @@
package org.apache.olingo.odata2.core.annotation.model;
import java.util.Arrays;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
+import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceContent;
+import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceMimeType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceSource;
+import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
+import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
+import org.apache.olingo.odata2.core.annotation.model.ModelSharedConstants;
+import org.apache.olingo.odata2.core.annotation.model.ResourceHelper;
/**
*
*/
+@EdmEntityType(name = "Photo", namespace = ModelSharedConstants.NAMESPACE_1)
+@EdmEntitySet(name = "Photos")
public class Photo {
- private static final String RESOURCE = "/male_1_WinterW.jpg";
-
- private final int id;
+ @EdmProperty
+ @EdmKey
private String name;
- private String type = "image/jpeg";
- private String imageUrl = "http://localhost" + RESOURCE;
- private byte[] image = new byte[0];
- private String imageType = type;
- private byte[] binaryData;
- private String content;
-
- public Photo(final int id, final String name, final String type) {
- this.id = id;
- setName(name);
- setType(type);
- }
-
- public int getId() {
- return id;
- }
+ @EdmProperty(name = "ImageFormat")
+ @EdmKey
+ private String type;
+ @EdmProperty
+ @EdmMediaResourceMimeType
+ private String mimeType;
+ @EdmProperty
+ @EdmMediaResourceSource
+ private String imageUrl = "http://localhost/someResource.png";
+ @EdmProperty(type = EdmSimpleTypeKind.Binary)
+ @EdmMediaResourceContent
+ private byte[] image = ResourceHelper.generateImage();
public String getName() {
return name;
@@ -78,53 +85,45 @@ public class Photo {
}
public String getImageType() {
- return imageType;
+ return mimeType;
}
public void setImageType(final String imageType) {
- this.imageType = imageType;
- }
-
- public byte[] getBinaryData() {
- if (binaryData == null) {
- return null;
- } else {
- return binaryData.clone();
- }
- }
-
- public void setBinaryData(final byte[] binaryData) {
- this.binaryData = binaryData;
- }
-
- public void setContent(final String content) {
- this.content = content;
- }
-
- public String getContent() {
- return content;
+ this.mimeType = imageType;
}
@Override
public int hashCode() {
- return id;
+ int hash = 5;
+ hash = 83 * hash + (this.name != null ? this.name.hashCode() : 0);
+ hash = 83 * hash + (this.type != null ? this.type.hashCode() : 0);
+ return hash;
}
@Override
- public boolean equals(final Object obj) {
- return this == obj
- || obj != null && getClass() == obj.getClass() && id == ((Photo) obj).id;
+ public boolean equals(Object obj) {
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ final Photo other = (Photo) obj;
+ if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) {
+ return false;
+ }
+ if ((this.type == null) ? (other.type != null) : !this.type.equals(other.type)) {
+ return false;
+ }
+ return true;
}
-
+
@Override
public String toString() {
- return "{\"Id\":" + id + ","
- + "\"Name\":\"" + name + "\","
+ return "{\"Name\":\"" + name + "\","
+ "\"Type\":\"" + type + "\","
+ "\"ImageUrl\":\"" + imageUrl + "\","
+ "\"Image\":\"" + Arrays.toString(image) + "\","
- + "\"ImageType\":\"" + imageType + "\","
- + "\"Content:\"" + content + "\","
- + "\"BinaryData\":\"" + Arrays.toString(binaryData) + "\"}";
+ + "\"MimeType\":\"" + mimeType + "\"";
}
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/b7e7ee0d/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/ResourceHelper.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/ResourceHelper.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/ResourceHelper.java
new file mode 100644
index 0000000..73d1218
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/ResourceHelper.java
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * 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.core.annotation.model;
+
+import java.awt.image.BufferedImage;
+import java.awt.image.WritableRaster;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import javax.imageio.ImageIO;
+
+/**
+ *
+ */
+public class ResourceHelper {
+
+ public enum Format {BMP, JPEG, PNG, GIF};
+
+ public static byte[] generateImage() {
+ return generateImage(Format.PNG);
+ }
+
+ public static byte[] generateImage(Format format) {
+ try {
+ int width = 320;
+ int height = 320;
+ BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_BINARY);
+ WritableRaster raster = image.getRaster();
+
+ int mod = format.ordinal() + 2;
+ for (int h = 0; h < height; h++) {
+ for (int w = 0; w < width; w++) {
+ if (((h / 32) + (w / 32)) % mod == 0) {
+ raster.setSample(w, h, 0, 0);
+ } else {
+ raster.setSample(w, h, 0, 1);
+ }
+ }
+ }
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
+ ImageIO.write(image, format.name(), out);
+ return out.toByteArray();
+ } catch (IOException ex) {
+ return new byte[0];
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/b7e7ee0d/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Photo.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Photo.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Photo.java
index 3623b2b..eafee7b 100644
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Photo.java
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Photo.java
@@ -34,9 +34,10 @@ import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
@EdmEntityType(name = "Photo", namespace = ModelSharedConstants.NAMESPACE_1)
@EdmEntitySet(name = "Photos")
public class Photo {
- @EdmProperty
@EdmKey
+ @EdmProperty
private String name;
+ @EdmKey
@EdmProperty
private String type;
@EdmProperty
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/b7e7ee0d/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/processor/AnnotationPocServiceFactory.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/processor/AnnotationPocServiceFactory.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/processor/AnnotationPocServiceFactory.java
index 9dcac65..5210466 100644
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/processor/AnnotationPocServiceFactory.java
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/processor/AnnotationPocServiceFactory.java
@@ -14,8 +14,8 @@
*/
package org.apache.olingo.odata2.ref.annotation.processor;
-import org.apache.olingo.odata2.core.annotation.ds.AnnotationValueAccess;
-import org.apache.olingo.odata2.core.annotation.ds.AnnotationInMemoryDs;
+import org.apache.olingo.odata2.core.annotation.data.AnnotationValueAccess;
+import org.apache.olingo.odata2.core.annotation.data.AnnotationInMemoryDs;
import org.apache.olingo.odata2.api.ODataCallback;
import org.apache.olingo.odata2.api.ODataDebugCallback;
import org.apache.olingo.odata2.api.ODataService;
@@ -28,13 +28,12 @@ import org.apache.olingo.odata2.api.processor.ODataContext;
import org.apache.olingo.odata2.api.processor.ODataErrorCallback;
import org.apache.olingo.odata2.api.processor.ODataErrorContext;
import org.apache.olingo.odata2.api.processor.ODataResponse;
-import org.apache.olingo.odata2.core.annotation.ds.DataStore;
+import org.apache.olingo.odata2.core.annotation.data.DataStore;
import org.apache.olingo.odata2.core.annotation.edm.AnnotationEdmProvider;
import org.apache.olingo.odata2.core.annotation.processor.ListsProcessor;
import org.apache.olingo.odata2.ref.annotation.model.Building;
import org.apache.olingo.odata2.ref.annotation.model.Photo;
import org.apache.olingo.odata2.ref.annotation.model.ResourceHelper;
-import org.apache.olingo.odata2.ref.annotation.model.ResourceHelper;
import org.apache.olingo.odata2.ref.annotation.model.Room;
import org.apache.olingo.odata2.ref.annotation.model.Team;
import org.slf4j.Logger;
@@ -73,8 +72,6 @@ public class AnnotationPocServiceFactory extends ODataServiceFactory {
? new ScenarioDebugCallback() : super.getCallback(callbackInterface));
}
-
-
/*
* Helper classes and methods
*/
@@ -105,7 +102,7 @@ public class AnnotationPocServiceFactory extends ODataServiceFactory {
}
- private void initializeSampleData(AnnotationInMemoryDs dataSource) {
+ private void initializeSampleData(AnnotationInMemoryDs dataSource) throws ODataApplicationException {
DataStore<Team> teamDs = dataSource.getDataStore(Team.class);
teamDs.create(createTeam("Team Alpha", true));
teamDs.create(createTeam("Team Beta", false));
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/b7e7ee0d/odata2-edm-annotation/edm-annotation-webref/src/main/webapp/index.jsp
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/webapp/index.jsp b/odata2-edm-annotation/edm-annotation-webref/src/main/webapp/index.jsp
index 3ffc551..dffa84d 100644
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/webapp/index.jsp
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/webapp/index.jsp
@@ -77,11 +77,11 @@ th, td { border: 1px solid; padding: 20px; }
target="_blank">Employees('1')</a></li>
<li><a href="ReferenceScenario.svc/Managers('1')"
target="_blank">Managers('1')</a></li>
- <li><a href="ReferenceScenario.svc/Buildings('1')"
- target="_blank">Buildings('1')</a></li>
+ <li><a href="ReferenceScenario.svc/Buildings(1)"
+ target="_blank">Buildings(1)</a></li>
<li><a href="ReferenceScenario.svc/Rooms('1')" target="_blank">Rooms('1')</a></li>
- <li><a href="ReferenceScenario.svc/Container2.Photos(Id=4,Type='foo')"
- target="_blank">Container2.Photos(Id=4,Type='foo')</a></li>
+ <li><a href="ReferenceScenario.svc/Photos(Name='1',Type='2')"
+ target="_blank">Container2.Photos(Name='1',Type='2')</a></li>
</ul>
</td>
<td valign="top">
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/b7e7ee0d/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/AbstractRefTest.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/AbstractRefTest.java b/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/AbstractRefTest.java
index e9e2153..de5f99e 100644
--- a/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/AbstractRefTest.java
+++ b/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/AbstractRefTest.java
@@ -39,7 +39,7 @@ import org.apache.olingo.odata2.api.commons.HttpStatusCodes;
import org.apache.olingo.odata2.api.commons.ODataHttpMethod;
import org.apache.olingo.odata2.api.edm.provider.EdmProvider;
import org.apache.olingo.odata2.api.processor.ODataSingleProcessor;
-import org.apache.olingo.odata2.core.annotation.ds.BeanPropertyAccess;
+import org.apache.olingo.odata2.core.annotation.data.BeanPropertyAccess;
import org.apache.olingo.odata2.core.annotation.processor.ListsProcessor;
import org.apache.olingo.odata2.core.processor.ODataSingleProcessorService;
import org.apache.olingo.odata2.ref.edm.ScenarioEdmProvider;
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/b7e7ee0d/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 265fc28..688532d 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
@@ -49,7 +49,7 @@ import org.apache.olingo.odata2.api.commons.HttpStatusCodes;
import org.apache.olingo.odata2.api.edm.provider.EdmProvider;
import org.apache.olingo.odata2.api.exception.ODataException;
import org.apache.olingo.odata2.api.processor.ODataSingleProcessor;
-import org.apache.olingo.odata2.core.annotation.ds.BeanPropertyAccess;
+import org.apache.olingo.odata2.core.annotation.data.BeanPropertyAccess;
import org.apache.olingo.odata2.core.annotation.processor.ListsProcessor;
import org.apache.olingo.odata2.core.commons.ContentType;
import org.apache.olingo.odata2.core.processor.ODataSingleProcessorService;
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/b7e7ee0d/odata2-lib/odata-ref/src/main/java/org/apache/olingo/odata2/ref/processor/ScenarioServiceFactory.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-ref/src/main/java/org/apache/olingo/odata2/ref/processor/ScenarioServiceFactory.java b/odata2-lib/odata-ref/src/main/java/org/apache/olingo/odata2/ref/processor/ScenarioServiceFactory.java
index 49cd8b2..08d6e16 100644
--- a/odata2-lib/odata-ref/src/main/java/org/apache/olingo/odata2/ref/processor/ScenarioServiceFactory.java
+++ b/odata2-lib/odata-ref/src/main/java/org/apache/olingo/odata2/ref/processor/ScenarioServiceFactory.java
@@ -24,7 +24,7 @@ import org.apache.olingo.odata2.api.ODataService;
import org.apache.olingo.odata2.api.ODataServiceFactory;
import org.apache.olingo.odata2.api.exception.ODataException;
import org.apache.olingo.odata2.api.processor.ODataContext;
-import org.apache.olingo.odata2.core.annotation.ds.BeanPropertyAccess;
+import org.apache.olingo.odata2.core.annotation.data.BeanPropertyAccess;
import org.apache.olingo.odata2.core.annotation.processor.ListsProcessor;
import org.apache.olingo.odata2.ref.edm.ScenarioEdmProvider;
import org.apache.olingo.odata2.ref.model.DataContainer;
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/b7e7ee0d/odata2-lib/odata-ref/src/test/java/org/apache/olingo/odata2/ref/read/EntitySetTest.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-ref/src/test/java/org/apache/olingo/odata2/ref/read/EntitySetTest.java b/odata2-lib/odata-ref/src/test/java/org/apache/olingo/odata2/ref/read/EntitySetTest.java
index 53fd6ef..d07473d 100644
--- a/odata2-lib/odata-ref/src/test/java/org/apache/olingo/odata2/ref/read/EntitySetTest.java
+++ b/odata2-lib/odata-ref/src/test/java/org/apache/olingo/odata2/ref/read/EntitySetTest.java
@@ -38,7 +38,7 @@ import org.apache.olingo.odata2.api.processor.ODataContext;
import org.apache.olingo.odata2.api.processor.ODataResponse;
import org.apache.olingo.odata2.api.uri.PathInfo;
import org.apache.olingo.odata2.api.uri.UriInfo;
-import org.apache.olingo.odata2.core.annotation.ds.BeanPropertyAccess;
+import org.apache.olingo.odata2.core.annotation.data.BeanPropertyAccess;
import org.apache.olingo.odata2.core.annotation.processor.ListsProcessor;
import org.apache.olingo.odata2.core.commons.ContentType;
import org.apache.olingo.odata2.ref.model.DataContainer;
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/b7e7ee0d/odata2-lib/odata-ref/src/test/java/org/apache/olingo/odata2/ref/read/EntityTest.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-ref/src/test/java/org/apache/olingo/odata2/ref/read/EntityTest.java b/odata2-lib/odata-ref/src/test/java/org/apache/olingo/odata2/ref/read/EntityTest.java
index 87593f2..be55778 100644
--- a/odata2-lib/odata-ref/src/test/java/org/apache/olingo/odata2/ref/read/EntityTest.java
+++ b/odata2-lib/odata-ref/src/test/java/org/apache/olingo/odata2/ref/read/EntityTest.java
@@ -43,7 +43,7 @@ import org.apache.olingo.odata2.api.processor.ODataResponse;
import org.apache.olingo.odata2.api.uri.KeyPredicate;
import org.apache.olingo.odata2.api.uri.PathInfo;
import org.apache.olingo.odata2.api.uri.UriInfo;
-import org.apache.olingo.odata2.core.annotation.ds.BeanPropertyAccess;
+import org.apache.olingo.odata2.core.annotation.data.BeanPropertyAccess;
import org.apache.olingo.odata2.core.annotation.processor.ListsProcessor;
import org.apache.olingo.odata2.core.commons.ContentType;
import org.apache.olingo.odata2.ref.model.DataContainer;
[29/52] Refactored EdmNavigationProperty annotation
Posted by mi...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/4d80947e/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Building.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Building.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Building.java
index 488c462..bb50759 100644
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Building.java
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Building.java
@@ -26,14 +26,13 @@ import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
-import org.apache.olingo.odata2.api.annotation.edm.NavigationEnd;
import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
/**
*
*/
-@EdmEntityType(name="Building", namespace=ModelSharedConstants.NAMESPACE_1)
+@EdmEntityType(name = "Building", namespace = ModelSharedConstants.NAMESPACE_1)
@EdmEntitySet(name = "Buildings")
public class Building {
@EdmKey
@@ -41,9 +40,10 @@ public class Building {
private int id;
@EdmProperty
private String name;
+ @EdmProperty(name = "Image", type = EdmSimpleTypeKind.Binary)
private byte[] image;
- @EdmNavigationProperty(name="nb_rooms", association="BuildingRooms",
- to = @NavigationEnd(role = "r_Room", entitySet=Room.class, multiplicity = EdmMultiplicity.MANY))
+ @EdmNavigationProperty(name = "nb_Rooms", toType = Room.class,
+ association = "BuildingRooms", toMultiplicity = EdmMultiplicity.MANY)
private List<Room> rooms = new ArrayList<Room>();
public String getId() {
@@ -73,7 +73,7 @@ public class Building {
public void addRoom(Room room) {
rooms.add(room);
}
-
+
public List<Room> getRooms() {
return rooms;
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/4d80947e/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Employee.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Employee.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Employee.java
index e946a5a..2975d1b 100644
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Employee.java
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Employee.java
@@ -20,44 +20,47 @@ package org.apache.olingo.odata2.ref.annotation.model;
import java.text.DateFormat;
import java.util.Calendar;
+
import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmFacets;
+import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
+import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceContent;
+import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceMimeType;
import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
-import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
-import org.apache.olingo.odata2.api.annotation.edm.NavigationEnd;
-import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
/**
*
*/
-@EdmEntityType(name="Employee", namespace=ModelSharedConstants.NAMESPACE_1)
-@EdmEntitySet(name= "Employees")
+@EdmEntityType(name = "Employee", namespace = ModelSharedConstants.NAMESPACE_1)
+@EdmEntitySet(name = "Employees")
public class Employee {
private static int counter = 1;
@EdmKey
- @EdmProperty(name="EmployeeId", type = EdmSimpleTypeKind.String)
+ @EdmProperty(name = "EmployeeId", type = EdmSimpleTypeKind.String)
private String employeeId;
- @EdmProperty(name="EmployeeName")
+ @EdmProperty(name = "EmployeeName")
private String employeeName;
@EdmProperty
private int age;
- @EdmNavigationProperty(name="ne_Manager", association="ManagerEmployees",
- from = @NavigationEnd(role="r_Employees", entitySet=Manager.class, multiplicity=EdmMultiplicity.MANY))//,
-// to = @NavigationEnd(type = "Manager"))
+ @EdmNavigationProperty(name = "ne_Manager", association = "ManagerEmployees")
private Manager manager;
- @EdmNavigationProperty(name = "ne_Team", association="TeamEmployees",
- from = @NavigationEnd(role = "r_Employees", entitySet = Employee.class, multiplicity = EdmMultiplicity.MANY),
- to = @NavigationEnd(role = "r_Team", entitySet = Team.class)
- )
+ @EdmNavigationProperty(name = "ne_Team", association = "TeamEmployees")
private Team team;
+ @EdmNavigationProperty(name = "ne_Room")
private Room room;
+ @EdmMediaResourceMimeType
private String imageType;
+ @EdmMediaResourceContent
private byte[] image;
+ @EdmProperty(name = "ImageUrl")
private String imageUrl;
+ @EdmProperty(name = "EntryDate", type = EdmSimpleTypeKind.DateTime,
+ facets = @EdmFacets(nullable = true))
private Calendar entryDate;
- @EdmProperty(name="Location")
+ @EdmProperty(name = "Location", facets = @EdmFacets(nullable = false))
private Location location;
public String getId() {
@@ -157,7 +160,7 @@ public class Employee {
@Override
public int hashCode() {
- if(employeeId == null) {
+ if (employeeId == null) {
return 0;
}
return employeeId.hashCode();
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/4d80947e/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Manager.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Manager.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Manager.java
index 0fcd152..93974ab 100644
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Manager.java
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Manager.java
@@ -20,10 +20,11 @@ package org.apache.olingo.odata2.ref.annotation.model;
import java.util.ArrayList;
import java.util.List;
+
import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
-import org.apache.olingo.odata2.api.annotation.edm.NavigationEnd;
+import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
/**
*
@@ -33,7 +34,7 @@ import org.apache.olingo.odata2.api.annotation.edm.NavigationEnd;
public class Manager extends Employee {
@EdmNavigationProperty(name = "nm_Employees", association = "ManagerEmployees",
- to = @NavigationEnd(role = "r_Employees", entitySet = Employee.class))
+ toMultiplicity = EdmMultiplicity.MANY)
private List<Employee> employees = new ArrayList<Employee>();
public List<Employee> getEmployees() {
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/4d80947e/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Room.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Room.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Room.java
index 3d61a63..2d9f48e 100644
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Room.java
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Room.java
@@ -20,12 +20,11 @@ package org.apache.olingo.odata2.ref.annotation.model;
import java.util.ArrayList;
import java.util.List;
+
import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
-import org.apache.olingo.odata2.api.annotation.edm.NavigationEnd;
-import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
/**
*
@@ -38,12 +37,9 @@ public class Room extends RefBase {
private Integer seats;
@EdmProperty
private Integer version;
- @EdmNavigationProperty(name="nr_Building", association="BuildingRooms",
- from = @NavigationEnd(role="r_Room", entitySet = Building.class, multiplicity = EdmMultiplicity.MANY))
+ @EdmNavigationProperty(name = "nr_Building", association = "BuildingRooms")
private Building building;
- @EdmNavigationProperty(name="nr_Employees", association="RoomEmployees",
- from = @NavigationEnd(role = "r_Room", entitySet = Room.class, multiplicity = EdmMultiplicity.ONE),
- to = @NavigationEnd(role = "r_Employees", entitySet = Employee.class, multiplicity = EdmMultiplicity.MANY))
+ @EdmNavigationProperty(name = "nr_Employees")
private List<Employee> employees = new ArrayList<Employee>();
public void setSeats(final int seats) {
@@ -82,7 +78,7 @@ public class Room extends RefBase {
@Override
public boolean equals(final Object obj) {
return this == obj
- || obj != null && getClass() == obj.getClass() && id == ((Room) obj).id;
+ || obj != null && getClass() == obj.getClass() && id == ((Room) obj).id;
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/4d80947e/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Team.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Team.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Team.java
index 1b04c32..7cbe321 100644
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Team.java
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Team.java
@@ -20,26 +20,23 @@ package org.apache.olingo.odata2.ref.annotation.model;
import java.util.ArrayList;
import java.util.List;
+
import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
-import org.apache.olingo.odata2.api.annotation.edm.NavigationEnd;
import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
/**
*
*/
-@EdmEntityType(name="Team", namespace = ModelSharedConstants.NAMESPACE_1)
+@EdmEntityType(name = "Team", namespace = ModelSharedConstants.NAMESPACE_1)
@EdmEntitySet(name = "Teams")
public class Team extends RefBase {
@EdmProperty(type = EdmSimpleTypeKind.Boolean)
private Boolean isScrumTeam;
- @EdmNavigationProperty(name = "nt_Employees", association="TeamEmployees",
-// from = @NavigationEnd(role = "r_Team", type = "Team"),
- to = @NavigationEnd(role = "r_Employees", entitySet = Employee.class, multiplicity = EdmMultiplicity.MANY)
- )
+ @EdmNavigationProperty(name = "nt_Employees", association = "TeamEmployees", toMultiplicity = EdmMultiplicity.MANY)
private List<Employee> employees = new ArrayList<Employee>();
public Boolean isScrumTeam() {
@@ -49,7 +46,7 @@ public class Team extends RefBase {
public void setScrumTeam(final Boolean isScrumTeam) {
this.isScrumTeam = isScrumTeam;
}
-
+
public void addEmployee(Employee e) {
this.employees.add(e);
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/4d80947e/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/processor/AnnotationPocServiceFactory.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/processor/AnnotationPocServiceFactory.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/processor/AnnotationPocServiceFactory.java
index 5210466..3870119 100644
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/processor/AnnotationPocServiceFactory.java
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/processor/AnnotationPocServiceFactory.java
@@ -14,8 +14,8 @@
*/
package org.apache.olingo.odata2.ref.annotation.processor;
-import org.apache.olingo.odata2.core.annotation.data.AnnotationValueAccess;
-import org.apache.olingo.odata2.core.annotation.data.AnnotationInMemoryDs;
+import java.util.Calendar;
+
import org.apache.olingo.odata2.api.ODataCallback;
import org.apache.olingo.odata2.api.ODataDebugCallback;
import org.apache.olingo.odata2.api.ODataService;
@@ -28,10 +28,15 @@ import org.apache.olingo.odata2.api.processor.ODataContext;
import org.apache.olingo.odata2.api.processor.ODataErrorCallback;
import org.apache.olingo.odata2.api.processor.ODataErrorContext;
import org.apache.olingo.odata2.api.processor.ODataResponse;
+import org.apache.olingo.odata2.core.annotation.data.AnnotationInMemoryDs;
+import org.apache.olingo.odata2.core.annotation.data.AnnotationValueAccess;
import org.apache.olingo.odata2.core.annotation.data.DataStore;
import org.apache.olingo.odata2.core.annotation.edm.AnnotationEdmProvider;
import org.apache.olingo.odata2.core.annotation.processor.ListsProcessor;
import org.apache.olingo.odata2.ref.annotation.model.Building;
+import org.apache.olingo.odata2.ref.annotation.model.Employee;
+import org.apache.olingo.odata2.ref.annotation.model.Location;
+import org.apache.olingo.odata2.ref.annotation.model.Manager;
import org.apache.olingo.odata2.ref.annotation.model.Photo;
import org.apache.olingo.odata2.ref.annotation.model.ResourceHelper;
import org.apache.olingo.odata2.ref.annotation.model.Room;
@@ -75,7 +80,7 @@ public class AnnotationPocServiceFactory extends ODataServiceFactory {
/*
* Helper classes and methods
*/
-
+
/**
*
*/
@@ -133,6 +138,31 @@ public class AnnotationPocServiceFactory extends ODataServiceFactory {
roomDs.create(createRoom("Big blue room", 40, 1, blueBuilding));
roomDs.create(createRoom("Huge blue room", 120, 1, blueBuilding));
roomDs.create(createRoom("Huge yellow room", 120, 1, yellowBuilding));
+
+ DataStore<Employee> employeeDataStore = dataSource.getDataStore(Employee.class);
+ employeeDataStore.create(createEmployee("first Employee",
+ new Location("Norge", "8392", "Ä"), 42, null,
+ photoDs.read().iterator().next().getImage(), photoDs.read().iterator().next().getImageType(),
+ "http://localhost/image/first.png",
+ null, teamDs.read().iterator().next(), roomDs.read().iterator().next()));
+ }
+
+ private Employee createEmployee(final String name,
+ Location location, final int age, final Calendar date,
+ final byte[] image, final String imageType, final String imageUrl,
+ Manager manager, Team team, Room room) {
+ Employee employee = new Employee();
+ employee.setEmployeeName(name);
+ employee.setLocation(location);
+ employee.setAge(age);
+ employee.setEntryDate(date);
+ employee.setImage(image);
+ employee.setImageType(imageType);
+ employee.setImageUri(imageUrl);
+ employee.setManager(manager);
+ employee.setTeam(team);
+ employee.setRoom(room);
+ return employee;
}
private Team createTeam(String teamName, boolean isScrumTeam) {
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/4d80947e/odata2-edm-annotation/edm-annotation-webref/src/main/webapp/index.jsp
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/webapp/index.jsp b/odata2-edm-annotation/edm-annotation-webref/src/main/webapp/index.jsp
index 2219d10..49cf364 100644
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/webapp/index.jsp
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/webapp/index.jsp
@@ -67,21 +67,27 @@ th, td { border: 1px solid; padding: 20px; }
<li><a href="ReferenceScenario.svc/Employees" target="_blank">Employees</a></li>
<li><a href="ReferenceScenario.svc/Managers" target="_blank">Managers</a></li>
<li><a href="ReferenceScenario.svc/Buildings" target="_blank">Buildings</a></li>
+ <li><a href="ReferenceScenario.svc/Buildings/?$expand=nb_Rooms"
+ target="_blank">Buildings/?$expand=nb_Rooms</a></li>
<li><a href="ReferenceScenario.svc/Rooms" target="_blank">Rooms</a></li>
+ <li><a href="ReferenceScenario.svc/Rooms/?$orderby=Name" target="_blank">Rooms/?$orderby=Name</a></li>
<li><a href="ReferenceScenario.svc/Photos" target="_blank">Photos</a></li>
- </ul>
+ <li><a href="ReferenceScenario.svc/Photos/?$filter=Type%20eq%20'PNG'"
+ target="_blank">Photos/?$filter=Type eq 'PNG'</a></li>
+ </ul>
<h3>Entities</h3>
<ul>
- <li><a href="ReferenceScenario.svc/Employees('1')"
- target="_blank">Employees('1')</a></li>
- <li><a href="ReferenceScenario.svc/Managers('1')"
- target="_blank">Managers('1')</a></li>
- <li><a href="ReferenceScenario.svc/Buildings(1)"
- target="_blank">Buildings(1)</a></li>
+ <li><a href="ReferenceScenario.svc/Employees('1')" target="_blank">Employees('1')</a></li>
+ <li><a href="ReferenceScenario.svc/Managers('1')" target="_blank">Managers('1')</a></li>
+ <li><a href="ReferenceScenario.svc/Buildings(1)" target="_blank">Buildings(1)</a></li>
+ <li><a href="ReferenceScenario.svc/Buildings(1)/nb_Rooms" target="_blank">Buildings(1)/nb_Rooms</a></li>
<li><a href="ReferenceScenario.svc/Rooms('1')" target="_blank">Rooms('1')</a></li>
- <li><a href="ReferenceScenario.svc/Photos(Name='1',Type='2')"
- target="_blank">Photos(Name='1',Type='2')</a></li>
- </ul>
+ <li><a href="ReferenceScenario.svc/Rooms('1')/nr_Building" target="_blank">Rooms('1')/nr_Building</a></li>
+ <li><a href="ReferenceScenario.svc/Photos(Name='Small%20picture',Type='GIF')"
+ target="_blank">Photos(Name='Small%20picture',Type='GIF')</a></li>
+ <li><a href="ReferenceScenario.svc/Photos(Name='Big%20picture',Type='JPEG')/$value"
+ target="_blank">Photos(Name='Big%20picture',Type='JPEG')/$value</a></li>
+ </ul>
</td>
<td valign="top">
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/4d80947e/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmNavigationProperty.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmNavigationProperty.java b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmNavigationProperty.java
index 544471b..7cdad48 100644
--- a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmNavigationProperty.java
+++ b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmNavigationProperty.java
@@ -22,15 +22,16 @@ import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
+
import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface EdmNavigationProperty {
- String name();
- String association() default ""; // if not set -> will be generated
- //
- NavigationEnd from() default @NavigationEnd;
- NavigationEnd to() default @NavigationEnd;
+ String name() default "";
+ Class<?> toType() default Object.class;
+ String association() default ""; // if not set -> will be generated
+ String toRole() default ""; // if not set -> will be generated
+ EdmMultiplicity toMultiplicity() default EdmMultiplicity.ONE;
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/4d80947e/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/NavigationEnd.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/NavigationEnd.java b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/NavigationEnd.java
deleted file mode 100644
index 6846dba..0000000
--- a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/NavigationEnd.java
+++ /dev/null
@@ -1,35 +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.api.annotation.edm;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
-
-@Retention(RetentionPolicy.RUNTIME)
-@Target(ElementType.FIELD)
-public @interface NavigationEnd {
- String role() default "";
- // because entityset is mandatory for some cases set it as default to 'Object.class'
- Class<?> entitySet() default Object.class;
-
- EdmMultiplicity multiplicity() default EdmMultiplicity.ONE;
-}
[17/52] git commit: Fix for rename
Posted by mi...@apache.org.
Fix for rename
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/20d6f029
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/20d6f029
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/20d6f029
Branch: refs/heads/master
Commit: 20d6f029272258d29833cf73a9d4ebddd8461f67
Parents: d83070d
Author: Michael Bolz <mi...@apache.org>
Authored: Tue Nov 12 09:33:06 2013 +0100
Committer: Michael Bolz <mi...@apache.org>
Committed: Tue Nov 12 09:33:06 2013 +0100
----------------------------------------------------------------------
.../edm-annotation-webref/src/main/webapp/WEB-INF/web.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/20d6f029/odata2-edm-annotation/edm-annotation-webref/src/main/webapp/WEB-INF/web.xml
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/webapp/WEB-INF/web.xml b/odata2-edm-annotation/edm-annotation-webref/src/main/webapp/WEB-INF/web.xml
index 1795259..5f7264c 100644
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/webapp/WEB-INF/web.xml
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/webapp/WEB-INF/web.xml
@@ -35,7 +35,7 @@
</init-param>
<init-param>
<param-name>org.apache.olingo.odata2.service.factory</param-name>
- <param-value>org.apache.olingo.odata2.ref.annotation.processor.ScenarioServiceFactory</param-value>
+ <param-value>org.apache.olingo.odata2.ref.annotation.processor.AnnotationPocServiceFactory</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
[40/52] git commit: Renamed multiplicity enum
Posted by mi...@apache.org.
Renamed multiplicity enum
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/a73d1975
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/a73d1975
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/a73d1975
Branch: refs/heads/master
Commit: a73d1975c6106ad2e5f11f2a0ff07f7ce77ba43d
Parents: e7a17fe
Author: Michael Bolz <mi...@apache.org>
Authored: Wed Dec 4 16:02:15 2013 +0100
Committer: Michael Bolz <mi...@apache.org>
Committed: Wed Dec 4 16:02:15 2013 +0100
----------------------------------------------------------------------
.../olingo/odata2/core/annotation/edm/AnnotationHelper.java | 2 +-
.../odata2/api/annotation/edm/EdmNavigationProperty.java | 9 ++++-----
2 files changed, 5 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/a73d1975/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java
index d1dd7cc..2b6675f 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java
@@ -690,7 +690,7 @@ public class AnnotationHelper {
public EdmMultiplicity mapMultiplicity(Multiplicity multiplicity) {
switch (multiplicity) {
- case ZERO_TO_ONE: return EdmMultiplicity.ZERO_TO_ONE;
+ case ZERO_OR_ONE: return EdmMultiplicity.ZERO_TO_ONE;
case ONE: return EdmMultiplicity.ONE;
case MANY: return EdmMultiplicity.MANY;
default: throw new ODataRuntimeException("Unknown type '" + multiplicity + "' for mapping to EdmMultiplicity.");
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/a73d1975/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmNavigationProperty.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmNavigationProperty.java b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmNavigationProperty.java
index 168784c..14b304b 100644
--- a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmNavigationProperty.java
+++ b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmNavigationProperty.java
@@ -35,15 +35,14 @@ public @interface EdmNavigationProperty {
* <p>EdmMultiplicity indicates the number of entity type instances
* an association end can relate to:
* <dl>
- * <dt>0..1</dt><dd>one or none</dd>
- * <dt> 1</dt><dd>exactly one</dd>
- * <dt> *</dt><dd>many</dd>
+ * <dt>ZERO_OR_ONE (0..1)</dt><dd>value is exactly one but can be null (i.e. <code>nullable = true</code>)</dd>
+ * <dt>ONE (1)</dt><dd>value is exactly one (i.e. <code>nullable = false</code>)</dd>
+ * <dt>MANY (*)</dt><dd>many values (which includes zero values (e.g. empty collection))</dd>
* </dl>
* </p>
- *
*/
public enum Multiplicity {
- ZERO_TO_ONE, ONE, MANY;
+ ZERO_OR_ONE, ONE, MANY;
}
[19/52] git commit: Implementation for Binary read
Posted by mi...@apache.org.
Implementation for Binary read
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/0169bfc3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/0169bfc3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/0169bfc3
Branch: refs/heads/master
Commit: 0169bfc386e03306cc92070cb9ec6b6f1a30703a
Parents: 454e178
Author: Michael Bolz <mi...@apache.org>
Authored: Tue Nov 12 16:07:42 2013 +0100
Committer: Michael Bolz <mi...@apache.org>
Committed: Tue Nov 12 16:07:42 2013 +0100
----------------------------------------------------------------------
.../core/annotation/ds/AnnotationInMemoryDs.java | 13 ++++++++-----
.../olingo/odata2/ref/annotation/model/Photo.java | 4 +---
.../odata2/ref/annotation/model/ResourceHelper.java | 13 ++++++++++---
.../processor/AnnotationPocServiceFactory.java | 16 ++++++++++------
4 files changed, 29 insertions(+), 17 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/0169bfc3/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/ds/AnnotationInMemoryDs.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/ds/AnnotationInMemoryDs.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/ds/AnnotationInMemoryDs.java
index 999b2ab..0a467fa 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/ds/AnnotationInMemoryDs.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/ds/AnnotationInMemoryDs.java
@@ -16,16 +16,14 @@ package org.apache.olingo.odata2.core.annotation.ds;
import java.lang.reflect.Field;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.logging.Level;
-import java.util.logging.Logger;
import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
+import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceContent;
+import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceMimeType;
import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
import org.apache.olingo.odata2.api.data.ListsDataSource;
import org.apache.olingo.odata2.api.edm.EdmEntitySet;
@@ -157,7 +155,12 @@ public class AnnotationInMemoryDs implements ListsDataSource {
@Override
public BinaryData readBinaryData(EdmEntitySet entitySet, Object mediaLinkEntryData)
throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException {
- throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
+
+ Object data = ANNOTATION_HELPER.getValueForField(mediaLinkEntryData, EdmMediaResourceContent.class);
+ Object mimeType = ANNOTATION_HELPER.getValueForField(mediaLinkEntryData, EdmMediaResourceMimeType.class);
+
+ BinaryData db = new BinaryData((byte[])data, String.valueOf(mimeType));
+ return db;
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/0169bfc3/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Photo.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Photo.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Photo.java
index fd266ce..432baba 100644
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Photo.java
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Photo.java
@@ -33,8 +33,6 @@ import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
@EdmEntityType(name = "Photo", namespace = ModelSharedConstants.NAMESPACE_1,
entitySetName = "Photos", container = ModelSharedConstants.CONTAINER_1)
public class Photo {
- private static final String RESOURCE = "/male_1_WinterW.jpg";
-
@EdmProperty
@EdmKey
private String name;
@@ -45,7 +43,7 @@ public class Photo {
private String mimeType;
@EdmProperty
@EdmMediaResourceSource
- private String imageUrl = "http://localhost" + RESOURCE;
+ private String imageUrl = "http://localhost/someResource.png";
@EdmProperty(type = EdmSimpleTypeKind.Binary)
@EdmMediaResourceContent
private byte[] image = ResourceHelper.generateImage();
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/0169bfc3/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ResourceHelper.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ResourceHelper.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ResourceHelper.java
index bba1c6b..3d2bb88 100644
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ResourceHelper.java
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ResourceHelper.java
@@ -28,7 +28,7 @@ import javax.imageio.ImageIO;
/**
*
*/
-class ResourceHelper {
+public class ResourceHelper {
public static byte[] loadAsByte(String resource) {
return load(resource, new byte[0]);
@@ -59,16 +59,23 @@ class ResourceHelper {
}
}
+ public enum Format {BMP, JPEG, PNG, GIF};
+
public static byte[] generateImage() {
+ return generateImage(Format.PNG);
+ }
+
+ public static byte[] generateImage(Format format) {
try {
int width = 320;
int height = 320;
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_BINARY);
WritableRaster raster = image.getRaster();
+ int mod = format.ordinal() + 2;
for (int h = 0; h < height; h++) {
for (int w = 0; w < width; w++) {
- if (((h / 32) + (w / 32)) % 2 == 0) {
+ if (((h / 32) + (w / 32)) % mod == 0) {
raster.setSample(w, h, 0, 0);
} else {
raster.setSample(w, h, 0, 1);
@@ -77,7 +84,7 @@ class ResourceHelper {
}
ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
- ImageIO.write(image, "PNG", out);
+ ImageIO.write(image, format.name(), out);
return out.toByteArray();
} catch (IOException ex) {
return new byte[0];
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/0169bfc3/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/processor/AnnotationPocServiceFactory.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/processor/AnnotationPocServiceFactory.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/processor/AnnotationPocServiceFactory.java
index eb1c252..9dcac65 100644
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/processor/AnnotationPocServiceFactory.java
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/processor/AnnotationPocServiceFactory.java
@@ -33,6 +33,8 @@ import org.apache.olingo.odata2.core.annotation.edm.AnnotationEdmProvider;
import org.apache.olingo.odata2.core.annotation.processor.ListsProcessor;
import org.apache.olingo.odata2.ref.annotation.model.Building;
import org.apache.olingo.odata2.ref.annotation.model.Photo;
+import org.apache.olingo.odata2.ref.annotation.model.ResourceHelper;
+import org.apache.olingo.odata2.ref.annotation.model.ResourceHelper;
import org.apache.olingo.odata2.ref.annotation.model.Room;
import org.apache.olingo.odata2.ref.annotation.model.Team;
import org.slf4j.Logger;
@@ -122,9 +124,10 @@ public class AnnotationPocServiceFactory extends ODataServiceFactory {
buildingsDs.create(yellowBuilding);
DataStore<Photo> photoDs = dataSource.getDataStore(Photo.class);
- photoDs.create(createPhoto("Small picture"));
- photoDs.create(createPhoto("Medium picture"));
- photoDs.create(createPhoto("Big picture"));
+ photoDs.create(createPhoto("Small picture", ResourceHelper.Format.GIF));
+ photoDs.create(createPhoto("Medium picture", ResourceHelper.Format.PNG));
+ photoDs.create(createPhoto("Big picture", ResourceHelper.Format.JPEG));
+ photoDs.create(createPhoto("Huge picture", ResourceHelper.Format.BMP));
DataStore<Room> roomDs = dataSource.getDataStore(Room.class);
roomDs.create(createRoom("Tiny red room", 5, 1, redBuilding));
@@ -148,12 +151,13 @@ public class AnnotationPocServiceFactory extends ODataServiceFactory {
return b;
}
- private Photo createPhoto(String name) {
+ private Photo createPhoto(String name, ResourceHelper.Format format) {
Photo p = new Photo();
p.setName(name);
- p.setType("PNG");
- p.setImageType("image/png");
p.setImageUri("http://localhost/image/" + name);
+ p.setType(format.name());
+ p.setImageType("image/" + format.name().toLowerCase());
+ p.setImage(ResourceHelper.generateImage(format));
return p;
}
[26/52] git commit: Fixes for name generation
Posted by mi...@apache.org.
Fixes for name generation
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/014bb975
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/014bb975
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/014bb975
Branch: refs/heads/master
Commit: 014bb9750a05c49879d1ae38a043cb627080bcdb
Parents: 83c2580
Author: Michael Bolz <mi...@apache.org>
Authored: Mon Nov 18 14:03:44 2013 +0100
Committer: Michael Bolz <mi...@apache.org>
Committed: Mon Nov 18 14:03:44 2013 +0100
----------------------------------------------------------------------
.../annotation/data/AnnotationInMemoryDs.java | 4 +-
.../odata2/core/annotation/data/DataStore.java | 4 +
.../annotation/edm/AnnotationEdmProvider.java | 79 ++++-------
.../core/annotation/edm/AnnotationHelper.java | 133 +++++++++++--------
.../src/main/webapp/index.jsp | 5 +-
5 files changed, 115 insertions(+), 110 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/014bb975/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationInMemoryDs.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationInMemoryDs.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationInMemoryDs.java
index b2f2618..3b79e27 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationInMemoryDs.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationInMemoryDs.java
@@ -58,8 +58,8 @@ public class AnnotationInMemoryDs implements ListsDataSource {
for (Class<?> clz : foundClasses) {
DataStore<Object> dhs = (DataStore<Object>) DataStore.createInMemory(clz);
- EdmEntityType entityType = clz.getAnnotation(EdmEntityType.class);
- dataStores.put(entityType.name(), dhs);
+ String entityTypeName = ANNOTATION_HELPER.extractEntityTypeName(clz);
+ dataStores.put(entityTypeName, dhs);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/014bb975/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/DataStore.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/DataStore.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/DataStore.java
index f8045f1..55a839e 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/DataStore.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/DataStore.java
@@ -79,6 +79,10 @@ public class DataStore<T> {
return dataTypeClass;
}
+ public String getEntityTypeName() {
+ return ANNOTATION_HELPER.extractEntityTypeName(dataTypeClass);
+ }
+
public T createInstance() {
try {
return dataTypeClass.newInstance();
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/014bb975/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java
index 75a92a2..dc253d8 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java
@@ -21,6 +21,7 @@ package org.apache.olingo.odata2.core.annotation.edm;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
+import java.util.Calendar;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
@@ -339,17 +340,21 @@ public class AnnotationEdmProvider extends EdmProvider {
private final List<NavigationProperty> navProperties = new ArrayList<NavigationProperty>();
private final List<Association> associations = new ArrayList<Association>();
- public TypeBuilder(String namespace, String name) {
- this.namespace = namespace;
- this.name = name;
+// public TypeBuilder(String namespace, String name) {
+// this.namespace = namespace;
+// this.name = name;
+// }
+ public TypeBuilder(FullQualifiedName fqn) {
+ this.namespace = fqn.getNamespace();
+ this.name = fqn.getName();
}
public static TypeBuilder init(EdmEntityType entity, Class<?> aClass) {
- return new TypeBuilder(entity.namespace(), entity.name()).withClass(aClass);
+ return new TypeBuilder(ANNOTATION_HELPER.extractEntityTypeFqn(aClass)).withClass(aClass);
}
public static TypeBuilder init(EdmComplexType entity, Class<?> aClass) {
- return new TypeBuilder(entity.namespace(), entity.name()).withClass(aClass);
+ return new TypeBuilder(ANNOTATION_HELPER.extractComplexTypeFqn(aClass)).withClass(aClass);
}
private TypeBuilder withClass(Class<?> aClass) {
@@ -517,9 +522,9 @@ public class AnnotationEdmProvider extends EdmProvider {
}
private String getCanonicalRole(NavigationEnd navEnd, Class<?> fallbackClass) {
- String toRole = extractEntitTypeName(navEnd.entitySet());
+ String toRole = ANNOTATION_HELPER.extractEntityTypeName(navEnd.entitySet());
if(toRole == null) {
- toRole = extractEntitTypeName(fallbackClass);
+ toRole = ANNOTATION_HELPER.extractEntityTypeName(fallbackClass);
}
return "r_" + toRole;
}
@@ -527,10 +532,14 @@ public class AnnotationEdmProvider extends EdmProvider {
private EdmSimpleTypeKind getEdmSimpleType(Class<?> type) {
if (type == String.class) {
return EdmSimpleTypeKind.String;
- } else if (type == int.class) {
- return EdmSimpleTypeKind.Int32;
- } else if (type == Integer.class) {
+ } else if (type == int.class || type == Integer.class) {
return EdmSimpleTypeKind.Int32;
+ } else if (type == double.class || type == Double.class) {
+ return EdmSimpleTypeKind.Double;
+ } else if (type == long.class || type == Long.class) {
+ return EdmSimpleTypeKind.Int64;
+ } else if (type == Calendar.class) {
+ return EdmSimpleTypeKind.DateTime;
} else if (type == Byte[].class || type == byte[].class) {
return EdmSimpleTypeKind.Binary;
} else {
@@ -538,30 +547,26 @@ public class AnnotationEdmProvider extends EdmProvider {
}
}
- private EdmEntityType checkForBaseEntity(Class<?> aClass) {
+ private Class<?> checkForBaseEntityClass(Class<?> aClass) {
Class<?> superClass = aClass.getSuperclass();
if (superClass == Object.class) {
return null;
} else {
EdmEntityType edmEntity = superClass.getAnnotation(EdmEntityType.class);
if (edmEntity == null) {
- return checkForBaseEntity(superClass);
+ return checkForBaseEntityClass(superClass);
} else {
- return edmEntity;
+ return superClass;
}
}
}
private FullQualifiedName createBaseEntityFqn(Class<?> aClass) {
- EdmEntityType baseEntity = checkForBaseEntity(aClass);
- if (baseEntity == null) {
+ Class<?> baseEntityClass = checkForBaseEntityClass(aClass);
+ if (baseEntityClass == null) {
return null;
}
- String beName = baseEntity.name();
- if (beName.isEmpty()) {
- beName = aClass.getName();
- }
- return new FullQualifiedName(baseEntity.namespace(), beName);
+ return ANNOTATION_HELPER.extractEntityTypeFqn(baseEntityClass);
}
private Association createAssociation(Field field, NavigationProperty navProperty) {
@@ -573,7 +578,7 @@ public class AnnotationEdmProvider extends EdmProvider {
fromEnd.setRole(navProperty.getFromRole());
String typeName = extractEntitTypeName(from);
if (typeName.isEmpty()) {
- typeName = extractEntitTypeName(field.getDeclaringClass());
+ typeName = ANNOTATION_HELPER.extractEntityTypeName(field.getDeclaringClass());
}
fromEnd.setType(new FullQualifiedName(namespace, typeName));
fromEnd.setMultiplicity(from.multiplicity());
@@ -584,7 +589,7 @@ public class AnnotationEdmProvider extends EdmProvider {
toEnd.setRole(navProperty.getToRole());
String toTypeName = extractEntitTypeName(to);
if (toTypeName.isEmpty()) {
- toTypeName = extractEntitTypeName(field.getType());
+ toTypeName = ANNOTATION_HELPER.extractEntityTypeName(field.getType());
}
toEnd.setType(new FullQualifiedName(namespace, toTypeName));
@@ -608,14 +613,8 @@ public class AnnotationEdmProvider extends EdmProvider {
return ANNOTATION_HELPER.getCanonicalName(field);
}
- private String getCanonicalName(Class<?> clazz) {
- return ANNOTATION_HELPER.getCanonicalName(clazz);
- }
-
private boolean isAnnotatedEntity(Class<?> clazz) {
- boolean isComplexEntity = clazz.getAnnotation(EdmComplexType.class) != null;
- boolean isEntity = clazz.getAnnotation(EdmEntityType.class) != null;
- return isComplexEntity || isEntity;
+ return ANNOTATION_HELPER.isEdmTypeAnnotated(clazz);
}
private String extractEntitTypeName(NavigationEnd navEnd) {
@@ -629,28 +628,6 @@ public class AnnotationEdmProvider extends EdmProvider {
}
return type.name();
}
-
- /**
- * Returns <code>NULL</code> if given class is not annotated.
- * If annotated the set entity type name is returned and if no name is set the
- * default name is generated from the simple class name.
- *
- * @param annotatedClass
- * @return
- */
- private String extractEntitTypeName(Class<?> annotatedClass) {
- if(annotatedClass == Object.class) {
- return null;
- }
- EdmEntityType type = annotatedClass.getAnnotation(EdmEntityType.class);
- if(type == null) {
- return null;
- }
- if(type.name().isEmpty()) {
- return getCanonicalName(annotatedClass);
- }
- return type.name();
- }
}
static class SchemaBuilder {
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/014bb975/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java
index cca0b5e..fbc0c7c 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java
@@ -10,7 +10,7 @@
* 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.core.annotation.edm;
@@ -33,6 +33,7 @@ import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
import org.apache.olingo.odata2.api.edm.EdmLiteralKind;
import org.apache.olingo.odata2.api.edm.EdmSimpleTypeException;
import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
+import org.apache.olingo.odata2.api.edm.FullQualifiedName;
import org.apache.olingo.odata2.api.exception.ODataException;
import org.apache.olingo.odata2.core.exception.ODataRuntimeException;
@@ -79,16 +80,74 @@ public class AnnotationHelper {
}
/**
- * Get the set property name from an EdmProperty or EdmNavigationProperty annotation.
+ * Returns <code>NULL</code> if given class is not annotated. If annotated the set entity type name is returned and if
+ * no name is set the default name is generated from the simple class name.
+ *
+ * @param annotatedClass
+ * @return
+ */
+ public String extractEntityTypeName(Class<?> annotatedClass) {
+ return extractTypeName(annotatedClass, EdmEntityType.class);
+ }
+
+ public FullQualifiedName extractEntityTypeFqn(Class<?> annotatedClass) {
+ EdmEntityType type = annotatedClass.getAnnotation(EdmEntityType.class);
+ return new FullQualifiedName(type.namespace(), extractEntityTypeName(annotatedClass));
+ }
+
+ public FullQualifiedName extractComplexTypeFqn(Class<?> annotatedClass) {
+ EdmComplexType type = annotatedClass.getAnnotation(EdmComplexType.class);
+ return new FullQualifiedName(type.namespace(), extractComplexTypeName(annotatedClass));
+ }
+
+ public String extractComplexTypeName(Class<?> annotatedClass) {
+ return extractTypeName(annotatedClass, EdmComplexType.class);
+ }
+
+ /**
*
+ *
+ * @param <T> must be EdmEntityType or EdmComplexType annotation
+ * @param annotatedClass
+ * @param typeAnnotation
+ * @return null if annotatedClass is not annotated or
+ * name set via annotation or generated via {@link #getCanonicalName(java.lang.Class)}
+ */
+ private <T extends Annotation> String extractTypeName(Class<?> annotatedClass, Class<T> typeAnnotation) {
+ if (annotatedClass == Object.class) {
+ return null;
+ }
+ T type = annotatedClass.getAnnotation(typeAnnotation);
+ if (type == null) {
+ return null;
+ }
+
+ String name;
+ if(typeAnnotation == EdmEntityType.class) {
+ name = ((EdmEntityType)type).name();
+ } else if(typeAnnotation == EdmComplexType.class) {
+ name = ((EdmComplexType)type).name();
+ } else {
+ return null;
+ }
+
+ if (name.isEmpty()) {
+ return getCanonicalName(annotatedClass);
+ }
+ return name;
+ }
+
+ /**
+ * Get the set property name from an EdmProperty or EdmNavigationProperty annotation.
+ *
* @param field
- * @return
+ * @return
*/
public String getPropertyNameFromAnnotation(Field field) {
EdmProperty property = field.getAnnotation(EdmProperty.class);
- if(property == null) {
+ if (property == null) {
EdmNavigationProperty navProperty = field.getAnnotation(EdmNavigationProperty.class);
- if(navProperty == null) {
+ if (navProperty == null) {
throw new EdmAnnotationException("Given field '" + field
+ "' has no EdmProperty or EdmNavigationProperty annotation.");
}
@@ -98,11 +157,11 @@ public class AnnotationHelper {
}
public String getPropertyName(Field field) {
- String propertyName = getPropertyNameFromAnnotation(field);
- if (propertyName.isEmpty()) {
- propertyName = getCanonicalName(field);
- }
- return propertyName;
+ String propertyName = getPropertyNameFromAnnotation(field);
+ if (propertyName.isEmpty()) {
+ propertyName = getCanonicalName(field);
+ }
+ return propertyName;
}
public static final class ODataAnnotationException extends ODataException {
@@ -118,7 +177,7 @@ public class AnnotationHelper {
throw new IllegalStateException("Wrong amount of key properties. Expected read keys = "
+ fields + " given key predicates = " + keys);
}
-
+
for (Field field : fields) {
String propertyName = getPropertyName(field);
Object keyValue = keys.get(propertyName);
@@ -128,20 +187,6 @@ public class AnnotationHelper {
return instance;
}
- public <T> T setKeyFields__(T instance, Object[] keyValues) {
- List<Field> fields = getAnnotatedFields(instance, EdmKey.class);
- if (fields.size() != keyValues.length) {
- throw new IllegalStateException("Wrong amount of key properties. Expected read keys = "
- + fields + " given key predicates = " + Arrays.toString(keyValues));
- }
-
- String propertyName = getCanonicalName(fields.get(0));
- setValueForProperty(instance, propertyName, keyValues[0]);
-
- return instance;
- }
-
-
public Field getCommonNavigationFieldFromTarget(Class<?> sourceClass, Class<?> targetClass) {
List<Field> sourceFields = getAnnotatedFields(sourceClass, EdmNavigationProperty.class);
List<Field> targetFields = getAnnotatedFields(targetClass, EdmNavigationProperty.class);
@@ -158,7 +203,6 @@ public class AnnotationHelper {
return null;
}
-
public Class<?> getFieldTypeForProperty(Object instance, String propertyName) throws ODataAnnotationException {
if (instance == null) {
return null;
@@ -194,31 +238,6 @@ public class AnnotationHelper {
}
}
-// private Object getValueForPropertyName(Object instance, String propertyName,
-// Class<?> resultClass, boolean inherited) {
-// if (instance == null) {
-// return null;
-// }
-//
-// Field[] fields = resultClass.getDeclaredFields();
-// for (Field field : fields) {
-// EdmProperty property = field.getAnnotation(EdmProperty.class);
-// if (property != null) {
-// if(property.name().equals(propertyName)) {
-// return getFieldValue(instance, field);
-// } else if(field.getName().equals(propertyName)) {
-// return getFieldValue(instance, field);
-// }
-// }
-// }
-//
-// Class<?> superClass = resultClass.getSuperclass();
-// if (inherited && superClass != Object.class) {
-// return getValueForPropertyName(instance, propertyName, superClass, true);
-// }
-//
-// return null;
-// }
private Field getFieldForPropertyName(Object instance, String propertyName,
Class<?> resultClass, boolean inherited) {
if (instance == null) {
@@ -309,7 +328,7 @@ public class AnnotationHelper {
}
public List<Field> getAnnotatedFields(Object instance, Class<? extends Annotation> annotation) {
- if(instance == null) {
+ if (instance == null) {
return null;
}
return getAnnotatedFields(instance.getClass(), annotation, true);
@@ -413,7 +432,7 @@ public class AnnotationHelper {
return type.getEdmSimpleTypeInstance().valueOfString(propertyValue,
EdmLiteralKind.DEFAULT, null, fieldClass);
} catch (EdmSimpleTypeException ex) {
- throw new ODataRuntimeException("Conversion failed for string property with error: "
+ throw new ODataRuntimeException("Conversion failed for string property with error: "
+ ex.getMessage(), ex);
}
}
@@ -425,6 +444,12 @@ public class AnnotationHelper {
return isEdmAnnotated(object.getClass());
}
+ public boolean isEdmTypeAnnotated(Class<?> clazz) {
+ boolean isComplexEntity = clazz.getAnnotation(EdmComplexType.class) != null;
+ boolean isEntity = clazz.getAnnotation(EdmEntityType.class) != null;
+ return isComplexEntity || isEntity;
+ }
+
public boolean isEdmAnnotated(Class<?> clazz) {
if (clazz == null) {
return false;
@@ -451,8 +476,8 @@ public class AnnotationHelper {
return content.substring(0, 1).toUpperCase(Locale.ENGLISH) + content.substring(1);
}
-
private static class EdmAnnotationException extends RuntimeException {
+
public EdmAnnotationException(String message) {
super(message);
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/014bb975/odata2-edm-annotation/edm-annotation-webref/src/main/webapp/index.jsp
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/webapp/index.jsp b/odata2-edm-annotation/edm-annotation-webref/src/main/webapp/index.jsp
index dffa84d..2219d10 100644
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/webapp/index.jsp
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/webapp/index.jsp
@@ -68,8 +68,7 @@ th, td { border: 1px solid; padding: 20px; }
<li><a href="ReferenceScenario.svc/Managers" target="_blank">Managers</a></li>
<li><a href="ReferenceScenario.svc/Buildings" target="_blank">Buildings</a></li>
<li><a href="ReferenceScenario.svc/Rooms" target="_blank">Rooms</a></li>
- <li><a href="ReferenceScenario.svc/Container2.Photos"
- target="_blank">Container2.Photos</a></li>
+ <li><a href="ReferenceScenario.svc/Photos" target="_blank">Photos</a></li>
</ul>
<h3>Entities</h3>
<ul>
@@ -81,7 +80,7 @@ th, td { border: 1px solid; padding: 20px; }
target="_blank">Buildings(1)</a></li>
<li><a href="ReferenceScenario.svc/Rooms('1')" target="_blank">Rooms('1')</a></li>
<li><a href="ReferenceScenario.svc/Photos(Name='1',Type='2')"
- target="_blank">Container2.Photos(Name='1',Type='2')</a></li>
+ target="_blank">Photos(Name='1',Type='2')</a></li>
</ul>
</td>
<td valign="top">
[15/52] Poc for ListsDs and Processor
Posted by mi...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d83070de/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java
index e30e382..cc9cd6c 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java
@@ -20,61 +20,274 @@ package org.apache.olingo.odata2.core.annotation.edm;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
import java.util.Locale;
+import java.util.Map;
+
import org.apache.olingo.odata2.api.annotation.edm.EdmComplexEntity;
import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
+import org.apache.olingo.odata2.api.exception.ODataException;
import org.apache.olingo.odata2.core.exception.ODataRuntimeException;
/**
*
*/
public class AnnotationHelper {
-
- public Object getValueForField(Object result, Class<? extends Annotation> annotation) {
- if(result == null) {
+
+ public static final class ODataAnnotationException extends ODataException {
+ public ODataAnnotationException(String message) {
+ super(message);
+ }
+ }
+
+ public Class<?> getFieldTypeForProperty(Object instance, String propertyName) throws ODataAnnotationException {
+ if (instance == null) {
return null;
}
- return getValueForField(result, result.getClass(), annotation, true);
+
+ Field field = getFieldForPropertyName(instance, propertyName, instance.getClass(), true);
+ if(field == null) {
+ throw new ODataAnnotationException("No field for property '" + propertyName
+ + "' found at class '" + instance.getClass() + "'.");
+ }
+ return field.getType();
}
- private Object getValueForField(Object result, Class<?> resultClass,
- Class<? extends Annotation> annotation, boolean inherited) {
- if(result == null) {
+ public Object getValueForProperty(Object instance, String propertyName) throws ODataAnnotationException {
+ if (instance == null) {
return null;
}
+ Field field = getFieldForPropertyName(instance, propertyName, instance.getClass(), true);
+ if(field == null) {
+ throw new ODataAnnotationException("No field for property '" + propertyName
+ + "' found at class '" + instance.getClass() + "'.");
+ }
+ return getFieldValue(instance, field);
+ }
+
+ public void setValueForProperty(Object instance, String propertyName, Object propertyValue) {
+ if (instance != null) {
+ Field field = getFieldForPropertyName(instance, propertyName, instance.getClass(), true);
+ if(field != null) {
+ setFieldValue(instance, field, propertyValue);
+ }
+ }
+ }
+
+// private Object getValueForPropertyName(Object instance, String propertyName,
+// Class<?> resultClass, boolean inherited) {
+// if (instance == null) {
+// return null;
+// }
+//
+// Field[] fields = resultClass.getDeclaredFields();
+// for (Field field : fields) {
+// EdmProperty property = field.getAnnotation(EdmProperty.class);
+// if (property != null) {
+// if(property.name().equals(propertyName)) {
+// return getFieldValue(instance, field);
+// } else if(field.getName().equals(propertyName)) {
+// return getFieldValue(instance, field);
+// }
+// }
+// }
+//
+// Class<?> superClass = resultClass.getSuperclass();
+// if (inherited && superClass != Object.class) {
+// return getValueForPropertyName(instance, propertyName, superClass, true);
+// }
+//
+// return null;
+// }
+
+
+ private Field getFieldForPropertyName(Object instance, String propertyName,
+ Class<?> resultClass, boolean inherited) {
+ if (instance == null) {
+ return null;
+ }
+
Field[] fields = resultClass.getDeclaredFields();
for (Field field : fields) {
- if(field.getAnnotation(annotation) != null) {
- try {
- boolean access = field.isAccessible();
- field.setAccessible(true);
- Object value = field.get(result);
- field.setAccessible(access);
- return value;
- } catch (IllegalArgumentException ex) { // should never happen
- throw new ODataRuntimeException(ex);
- } catch (IllegalAccessException ex) { // should never happen
- throw new ODataRuntimeException(ex);
+ EdmProperty property = field.getAnnotation(EdmProperty.class);
+ if (property != null) {
+ if(property.name().isEmpty() && getCanonicalName(field).equals(propertyName)) {
+ return field;
+ } else if(property.name().equals(propertyName)) {
+ return field;
}
}
}
- Class<?> superClass = result.getClass().getSuperclass();
- if(inherited && superClass != Object.class) {
- return getValueForField(result, superClass, annotation, true);
+ Class<?> superClass = resultClass.getSuperclass();
+ if (inherited && superClass != Object.class) {
+ return getFieldForPropertyName(instance, propertyName, superClass, true);
}
+
+ return null;
+ }
+
+
+ public Object getValueForField(Object instance, String fieldName, Class<? extends Annotation> annotation) {
+ if (instance == null) {
+ return null;
+ }
+ return getValueForField(instance, fieldName, instance.getClass(), annotation, true);
+ }
+
+ public Object getValueForField(Object instance, Class<? extends Annotation> annotation) {
+ if (instance == null) {
+ return null;
+ }
+ return getValueForField(instance, instance.getClass(), annotation, true);
+ }
+
+ private Object getValueForField(Object instance, Class<?> resultClass,
+ Class<? extends Annotation> annotation, boolean inherited) {
+ return getValueForField(instance, null, resultClass, annotation, inherited);
+ }
+
+ public Map<String, Object> getValueForAnnotatedFields(Object instance,
+ Class<? extends Annotation> annotation) {
+ return getValueForAnnotatedFields(instance, instance.getClass(), annotation, true);
+ }
+ private Map<String, Object> getValueForAnnotatedFields(Object instance, Class<?> resultClass,
+ Class<? extends Annotation> annotation, boolean inherited) {
+ if (instance == null) {
+ return null;
+ }
+
+ Field[] fields = resultClass.getDeclaredFields();
+ Map<String, Object> fieldName2Value = new HashMap<String, Object>();
+
+ for (Field field : fields) {
+ if (field.getAnnotation(annotation) != null) {
+ Object value = getFieldValue(instance, field);
+ fieldName2Value.put(field.getName(), value);
+ }
+ }
+
+ Class<?> superClass = resultClass.getSuperclass();
+ if (inherited && superClass != Object.class) {
+ Map<String, Object> tmp = getValueForAnnotatedFields(instance, superClass, annotation, true);
+ fieldName2Value.putAll(tmp);
+ }
+
+ return fieldName2Value;
+ }
+
+ public void setValuesToAnnotatedFields(Map<String, Object> fieldName2Value, Object instance,
+ Class<? extends Annotation> annotation) {
+ List<Field> fields = getAnnotatedFields(instance, instance.getClass(), annotation, true);
+
+ // XXX: refactore
+ for (Field field : fields) {
+ final String canonicalName = getCanonicalName(field);
+ if(fieldName2Value.containsKey(canonicalName)) {
+ Object value = fieldName2Value.get(canonicalName);
+ setFieldValue(instance, field, value);
+ }
+ }
+ }
+
+ public List<Field> getAnnotatedFields(Object instance, Class<? extends Annotation> annotation) {
+ return getAnnotatedFields(instance, instance.getClass(), annotation, true);
+ }
+
+ /**
+ *
+ * @param instance
+ * @param resultClass
+ * @param annotation
+ * @param inherited
+ * @return
+ */
+ private List<Field> getAnnotatedFields(Object instance, Class<?> resultClass,
+ Class<? extends Annotation> annotation, boolean inherited) {
+ if (instance == null) {
+ return null;
+ }
+
+ Field[] fields = resultClass.getDeclaredFields();
+ List<Field> annotatedFields = new ArrayList<Field>();
+
+ for (Field field : fields) {
+ if (field.getAnnotation(annotation) != null) {
+ annotatedFields.add(field);
+ }
+ }
+
+ Class<?> superClass = resultClass.getSuperclass();
+ if (inherited && superClass != Object.class) {
+ List<Field> tmp = getAnnotatedFields(instance, superClass, annotation, true);
+ annotatedFields.addAll(tmp);
+ }
+
+ return annotatedFields;
+ }
+
+ private Object getValueForField(Object instance, String fieldName, Class<?> resultClass,
+ Class<? extends Annotation> annotation, boolean inherited) {
+ if (instance == null) {
+ return null;
+ }
+
+ Field[] fields = resultClass.getDeclaredFields();
+ for (Field field : fields) {
+ if (field.getAnnotation(annotation) != null
+ && (fieldName == null || field.getName().equals(fieldName))) {
+ return getFieldValue(instance, field);
+ }
+ }
+
+ Class<?> superClass = resultClass.getSuperclass();
+ if (inherited && superClass != Object.class) {
+ return getValueForField(instance, fieldName, superClass, annotation, true);
+ }
+
return null;
}
+ private Object getFieldValue(Object instance, Field field) {
+ try {
+ boolean access = field.isAccessible();
+ field.setAccessible(true);
+ Object value = field.get(instance);
+ field.setAccessible(access);
+ return value;
+ } catch (IllegalArgumentException ex) { // should never happen
+ throw new ODataRuntimeException(ex);
+ } catch (IllegalAccessException ex) { // should never happen
+ throw new ODataRuntimeException(ex);
+ }
+ }
+
+ private void setFieldValue(Object instance, Field field, Object propertyValue) {
+ try {
+ boolean access = field.isAccessible();
+ field.setAccessible(true);
+ field.set(instance, propertyValue);
+ field.setAccessible(access);
+ } catch (IllegalArgumentException ex) { // should never happen
+ throw new ODataRuntimeException(ex);
+ } catch (IllegalAccessException ex) { // should never happen
+ throw new ODataRuntimeException(ex);
+ }
+ }
+
+
public boolean isEdmAnnotated(Object object) {
- if(object == null) {
+ if (object == null) {
return false;
}
return isEdmAnnotated(object.getClass());
}
-
+
public boolean isEdmAnnotated(Class<?> clazz) {
if (clazz == null) {
return false;
@@ -84,17 +297,17 @@ public class AnnotationHelper {
return isEntity || isComplexEntity;
}
}
-
+
public String getCanonicalName(Field field) {
return firstCharToUpperCase(field.getName());
}
-
+
public String getCanonicalName(Class<?> clazz) {
return firstCharToUpperCase(clazz.getSimpleName());
}
-
+
private String firstCharToUpperCase(String content) {
- if(content == null || content.isEmpty()) {
+ if (content == null || content.isEmpty()) {
return content;
}
return content.substring(0, 1).toUpperCase(Locale.ENGLISH) + content.substring(1);
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d83070de/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/AnnotationProcessor.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/AnnotationProcessor.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/AnnotationProcessor.java
index d06bd3f..23fc743 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/AnnotationProcessor.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/AnnotationProcessor.java
@@ -21,68 +21,60 @@ package org.apache.olingo.odata2.core.annotation.processor;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
+
import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceContent;
import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceMimeType;
import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
+import org.apache.olingo.odata2.api.annotation.edm.ds.EntityDataSource;
import org.apache.olingo.odata2.api.commons.HttpStatusCodes;
import org.apache.olingo.odata2.api.exception.ODataException;
+import org.apache.olingo.odata2.api.processor.ODataContext;
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.DeleteUriInfo;
import org.apache.olingo.odata2.api.uri.info.GetEntitySetUriInfo;
import org.apache.olingo.odata2.api.uri.info.GetEntityUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetMediaResourceUriInfo;
import org.apache.olingo.odata2.api.uri.info.PostUriInfo;
import org.apache.olingo.odata2.api.uri.info.PutMergePatchUriInfo;
-import org.apache.olingo.odata2.api.annotation.edm.ds.EntityCreate;
-import org.apache.olingo.odata2.api.annotation.edm.ds.EntityDataSource;
-import org.apache.olingo.odata2.api.annotation.edm.ds.EntityDelete;
-import org.apache.olingo.odata2.api.annotation.edm.ds.EntityRead;
-import org.apache.olingo.odata2.api.annotation.edm.ds.EntitySetRead;
-import org.apache.olingo.odata2.api.annotation.edm.ds.EntityUpdate;
-import org.apache.olingo.odata2.api.processor.ODataContext;
-import org.apache.olingo.odata2.api.uri.info.GetMediaResourceUriInfo;
-import org.apache.olingo.odata2.core.exception.ODataRuntimeException;
+import org.apache.olingo.odata2.core.annotation.ds.DataSourceHolder;
import org.apache.olingo.odata2.core.annotation.edm.AnnotationHelper;
import org.apache.olingo.odata2.core.annotation.edm.ClassHelper;
import org.apache.olingo.odata2.core.annotation.processor.json.EdmAnnotationSerializer;
import org.apache.olingo.odata2.core.annotation.processor.json.JsonConsumer;
+import org.apache.olingo.odata2.core.exception.ODataRuntimeException;
/**
*
*/
public class AnnotationProcessor extends ODataSingleProcessor {
- private static final Object[] EMPTY_ARRAY = new Object[0];
private static final AnnotationHelper ANNOTATION_HELPER = new AnnotationHelper();
- private final List<Class<?>> foundClasses;
-
private final Map<String, DataSourceHolder> dataSources = new HashMap<String, DataSourceHolder>();
private ODataContext odataContext;
public AnnotationProcessor(ODataContext context, String packageToScan) {
odataContext = context;
- foundClasses = ClassHelper.loadClasses(packageToScan, new ClassHelper.ClassValidator() {
+ List<Class<?>> foundClasses = ClassHelper.loadClasses(packageToScan, new ClassHelper.ClassValidator() {
@Override
public boolean isClassValid(Class<?> c) {
return null != c.getAnnotation(EntityDataSource.class);
}
});
- init();
+ init(foundClasses);
}
- private void init() {
+ private void init(List<Class<?>> foundClasses) {
for (Class<?> clz : foundClasses) {
DataSourceHolder dhs = new DataSourceHolder(clz);
dataSources.put(dhs.getEntityName(), dhs);
@@ -196,7 +188,7 @@ public class AnnotationProcessor extends ODataSingleProcessor {
throws ODataException {
try {
Object instance = dataSource.createEntityInstance();
- Map<String, FieldHolder> propName2Field = extractPropertyFields(dataSource.entityTypeClass);
+ Map<String, FieldHolder> propName2Field = extractPropertyFields(dataSource.getEntityTypeClass());
Map<String, String> contentAsMap = JsonConsumer.readContent(content);
Set<Map.Entry<String, String>> contentEntries = contentAsMap.entrySet();
for (Map.Entry<String, String> entry : contentEntries) {
@@ -314,157 +306,4 @@ public class AnnotationProcessor extends ODataSingleProcessor {
return "FieldHolder{" + "propertyName=" + propertyName + ", propertyField=" + propertyField + '}';
}
}
-
- /**
- *
- */
- static final class DataSourceHolder {
-
- private final String name;
- private final Object dataSourceInstance;
- private final Class<?> entityTypeClass;
- private Method readMethod;
- private Method createMethod;
- private Method updateMethod;
- private Method deleteMethod;
- private Method setReadMethod;
-
- public DataSourceHolder(Class<?> clz) {
- EntityDataSource eds = clz.getAnnotation(EntityDataSource.class);
- entityTypeClass = eds.entityType();
- EdmEntityType entityType = entityTypeClass.getAnnotation(EdmEntityType.class);
- if (entityType == null) {
- throw new IllegalArgumentException("Missing EdmEntityType Annotation at class " + clz);
- }
-
- if (entityType.name().isEmpty()) {
- name = ANNOTATION_HELPER.getCanonicalName(entityTypeClass);
- } else {
- name = entityType.name();
- }
- dataSourceInstance = createInstance(clz);
- initMethods(clz);
- }
-
- private void initMethods(Class<?> clz) throws IllegalArgumentException, SecurityException {
- Method[] methods = clz.getDeclaredMethods();
- for (Method method : methods) {
- EntityRead ec = method.getAnnotation(EntityRead.class);
- if (ec != null) {
- readMethod = method;
- }
- EntityCreate ep = method.getAnnotation(EntityCreate.class);
- if (ep != null) {
- createMethod = method;
- }
- EntityUpdate update = method.getAnnotation(EntityUpdate.class);
- if (update != null) {
- updateMethod = method;
- }
- EntityDelete delete = method.getAnnotation(EntityDelete.class);
- if (delete != null) {
- deleteMethod = method;
- }
- EntitySetRead readSet = method.getAnnotation(EntitySetRead.class);
- if (readSet != null) {
- setReadMethod = method;
- }
- }
-
- validateMethods(clz);
- }
-
- private void validateMethods(Class<?> clz) throws IllegalArgumentException {
- //
- if (readMethod == null) {
- throw new IllegalArgumentException("Missing " + EntityRead.class
- + " annotation at " + EntityDataSource.class + " annotated class " + clz);
- }
- if (updateMethod == null) {
- throw new IllegalArgumentException("Missing " + EntityUpdate.class
- + " annotation at " + EntityDataSource.class + " annotated class " + clz);
- }
- if (createMethod == null) {
- throw new IllegalArgumentException("Missing " + EntityCreate.class
- + " annotation at " + EntityDataSource.class + " annotated class " + clz);
- }
- }
-
- public Object readEntity(List<KeyPredicate> keys) {
- Object[] parameterKeys = mapParameterKeys(readMethod, keys);
- return invoke(readMethod, parameterKeys);
- }
-
- private Object[] mapParameterKeys(Method method, List<KeyPredicate> keys) throws IllegalStateException {
- if(method == null) {
- return EMPTY_ARRAY;
- }
- Class<?>[] pTypes = method.getParameterTypes();
- if (pTypes.length != keys.size()) {
- throw new IllegalStateException("Wrong amount of key properties. Expected read keys = "
- + Arrays.toString(pTypes) + " given key predicates = " + keys);
- }
- Object[] parameterKeys = new Object[pTypes.length];
- int i = 0;
- for (KeyPredicate keyPredicate : keys) {
- if (matches(pTypes[i], keyPredicate)) {
- parameterKeys[i] = keyPredicate.getLiteral();
- }
- i++;
- }
- return parameterKeys;
- }
-
- public Object createEntity(Object key) {
- return invoke(createMethod, new Object[]{key});
- }
-
- public Object updateEntity(Object key) {
- return invoke(updateMethod, new Object[]{key});
- }
-
- public Object deleteEntity(List<KeyPredicate> keys) {
- Object[] parameterKeys = mapParameterKeys(deleteMethod, keys);
- return invoke(deleteMethod, parameterKeys);
- }
-
- public Object readEntitySet() {
- return invoke(setReadMethod, new Object[0]);
- }
-
- private Object invoke(Method m, Object[] objs) {
- try {
- return m.invoke(dataSourceInstance, objs);
- } catch (Exception ex) {
- return null;
- }
- }
-
- public Object createEntityInstance() {
- return createInstance(this.entityTypeClass);
- }
-
- private static Object createInstance(Class<?> clz) {
- try {
- return clz.newInstance();
- } catch (Exception ex) {
- return null;
- }
- }
-
- public String getEntityName() {
- return this.name;
- }
-
- @Override
- public String toString() {
- return "DataSourceHolder{" + "name=" + name + ", dataSourceInstance=" + dataSourceInstance +
- ", entityTypeClass=" + entityTypeClass + ", consumerMethod=" + readMethod +
- ", createMethod=" + createMethod + ", updateMethod=" + updateMethod + '}';
- }
-
- private boolean matches(Class<?> aClass, KeyPredicate type) {
- return true;
- }
- }
}
[24/52] git commit: Added support for multiple 'EdmKey' annotations
Posted by mi...@apache.org.
Added support for multiple 'EdmKey' annotations
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/b7e7ee0d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/b7e7ee0d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/b7e7ee0d
Branch: refs/heads/master
Commit: b7e7ee0dff43353164816c3210ff3803fd88a634
Parents: a8ff9e2
Author: Michael Bolz <mi...@apache.org>
Authored: Fri Nov 15 09:17:32 2013 +0100
Committer: Michael Bolz <mi...@apache.org>
Committed: Fri Nov 15 12:54:37 2013 +0100
----------------------------------------------------------------------
.../annotation/data/AnnotationInMemoryDs.java | 272 +++++++++++++++++++
.../annotation/data/AnnotationValueAccess.java | 108 ++++++++
.../annotation/data/BeanPropertyAccess.java | 186 +++++++++++++
.../core/annotation/data/DataSourceHolder.java | 212 +++++++++++++++
.../odata2/core/annotation/data/DataStore.java | 182 +++++++++++++
.../annotation/ds/AnnotationInMemoryDs.java | 255 -----------------
.../annotation/ds/AnnotationValueAccess.java | 108 --------
.../core/annotation/ds/BeanPropertyAccess.java | 186 -------------
.../core/annotation/ds/DataSourceHolder.java | 212 ---------------
.../odata2/core/annotation/ds/DataStore.java | 166 -----------
.../annotation/edm/AnnotationEdmProvider.java | 19 +-
.../core/annotation/edm/AnnotationHelper.java | 57 +++-
.../processor/AnnotationProcessor.java | 2 +-
.../data/AnnotationsInMemoryDsTest.java | 157 +++++++++++
.../edm/AnnotationEdmProviderTest.java | 54 +++-
.../odata2/core/annotation/model/Building.java | 17 +-
.../odata2/core/annotation/model/Photo.java | 101 ++++---
.../core/annotation/model/ResourceHelper.java | 64 +++++
.../odata2/ref/annotation/model/Photo.java | 3 +-
.../processor/AnnotationPocServiceFactory.java | 11 +-
.../src/main/webapp/index.jsp | 8 +-
.../olingo/odata2/fit/ref/AbstractRefTest.java | 2 +-
.../AbstractContentNegotiationTest.java | 2 +-
.../ref/processor/ScenarioServiceFactory.java | 2 +-
.../olingo/odata2/ref/read/EntitySetTest.java | 2 +-
.../olingo/odata2/ref/read/EntityTest.java | 2 +-
26 files changed, 1364 insertions(+), 1026 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/b7e7ee0d/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationInMemoryDs.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationInMemoryDs.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationInMemoryDs.java
new file mode 100644
index 0000000..b2f2618
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationInMemoryDs.java
@@ -0,0 +1,272 @@
+/**
+ * *****************************************************************************
+ * 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.core.annotation.data;
+
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceContent;
+import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceMimeType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
+import org.apache.olingo.odata2.api.data.ListsDataSource;
+import org.apache.olingo.odata2.api.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.edm.EdmException;
+import org.apache.olingo.odata2.api.edm.EdmFunctionImport;
+import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
+import org.apache.olingo.odata2.api.exception.ODataApplicationException;
+import org.apache.olingo.odata2.api.exception.ODataNotFoundException;
+import org.apache.olingo.odata2.api.exception.ODataNotImplementedException;
+import org.apache.olingo.odata2.core.annotation.edm.AnnotationHelper;
+import org.apache.olingo.odata2.core.annotation.edm.ClassHelper;
+import org.apache.olingo.odata2.core.exception.ODataRuntimeException;
+
+public class AnnotationInMemoryDs implements ListsDataSource {
+
+ private static final AnnotationHelper ANNOTATION_HELPER = new AnnotationHelper();
+ private final Map<String, DataStore<Object>> dataStores = new HashMap<String, DataStore<Object>>();
+
+ public AnnotationInMemoryDs(String packageToScan) {
+ List<Class<?>> foundClasses = ClassHelper.loadClasses(packageToScan, new ClassHelper.ClassValidator() {
+ @Override
+ public boolean isClassValid(Class<?> c) {
+ return null != c.getAnnotation(EdmEntityType.class);
+ }
+ });
+
+ init(foundClasses);
+ }
+
+ @SuppressWarnings("unchecked")
+ private void init(List<Class<?>> foundClasses) {
+ for (Class<?> clz : foundClasses) {
+
+ DataStore<Object> dhs = (DataStore<Object>) DataStore.createInMemory(clz);
+ EdmEntityType entityType = clz.getAnnotation(EdmEntityType.class);
+ dataStores.put(entityType.name(), dhs);
+ }
+ }
+
+ public <T> DataStore<T> getDataStore(Class<T> clazz) {
+ return DataStore.createInMemory(clazz);
+ }
+
+ @Override
+ public List<?> readData(EdmEntitySet entitySet) throws ODataNotImplementedException,
+ ODataNotFoundException, EdmException, ODataApplicationException {
+
+ DataStore<Object> holder = getDataStore(entitySet);
+ if (holder != null) {
+ return new ArrayList(holder.read());
+ }
+
+ throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
+ }
+
+ @Override
+ public Object readData(EdmEntitySet entitySet, Map<String, Object> keys)
+ throws ODataNotFoundException, EdmException, ODataApplicationException {
+
+ DataStore<Object> store = getDataStore(entitySet);
+ if (store != null) {
+ Object keyInstance = store.createInstance();
+ ANNOTATION_HELPER.setKeyFields(keyInstance, keys);
+
+ Object result = store.read(keyInstance);
+ if (result != null) {
+ return result;
+ }
+ }
+
+ throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
+ }
+
+ @Override
+ public Object readData(EdmFunctionImport function, Map<String, Object> parameters, Map<String, Object> keys)
+ throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException {
+ throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
+ }
+
+ @Override
+ public Object readRelatedData(EdmEntitySet sourceEntitySet, Object sourceData, EdmEntitySet targetEntitySet,
+ Map<String, Object> targetKeys)
+ throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException {
+
+ if (targetKeys.isEmpty()) {
+ String sourceName = sourceEntitySet.getEntityType().getName();
+ DataStore sourceStore = dataStores.get(sourceName);
+
+ String targetName = targetEntitySet.getEntityType().getName();
+ DataStore targetStore = dataStores.get(targetName);
+
+ Field sourceFieldAtTarget = extractSourceField(sourceStore, targetStore);
+ if (sourceFieldAtTarget == null) {
+ throw new ODataRuntimeException("Missing source field for related data.");
+ }
+
+ Collection targetData = targetStore.read();
+ List resultData = new ArrayList();
+ for (Object targetInstance : targetData) {
+ Object targetNavigationInstance = getValue(sourceFieldAtTarget, targetInstance);
+ if(targetNavigationInstance instanceof Collection) {
+ Collection c = (Collection) targetNavigationInstance;
+ for (Object object : c) {
+ if (ANNOTATION_HELPER.keyMatch(sourceData, object)) {
+ resultData.add(targetInstance);
+ }
+ }
+ } else if (ANNOTATION_HELPER.keyMatch(sourceData, targetNavigationInstance)) {
+ resultData.add(targetInstance);
+ }
+ }
+
+ EdmNavigationProperty navProperty = sourceFieldAtTarget.getAnnotation(EdmNavigationProperty.class);
+ if(navProperty.from().multiplicity() == EdmMultiplicity.ONE) {
+ if(resultData.isEmpty()) {
+ return null;
+ }
+ return resultData.get(0);
+ }
+ return resultData;
+ } else {
+ throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
+ }
+ }
+
+ @Override
+ public BinaryData readBinaryData(EdmEntitySet entitySet, Object mediaLinkEntryData)
+ throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException {
+
+ Object data = ANNOTATION_HELPER.getValueForField(mediaLinkEntryData, EdmMediaResourceContent.class);
+ Object mimeType = ANNOTATION_HELPER.getValueForField(mediaLinkEntryData, EdmMediaResourceMimeType.class);
+
+ BinaryData db = new BinaryData((byte[])data, String.valueOf(mimeType));
+ return db;
+ }
+
+ @Override
+ public Object newDataObject(EdmEntitySet entitySet)
+ throws ODataNotImplementedException, EdmException, ODataApplicationException {
+
+ DataStore<Object> dataStore = getDataStore(entitySet);
+ if (dataStore != null) {
+ return dataStore.createInstance();
+ }
+
+ throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
+ }
+
+ @Override
+ public void writeBinaryData(EdmEntitySet entitySet, Object mediaLinkEntryData, BinaryData binaryData)
+ throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException {
+ throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
+
+ }
+
+ /**
+ * <p>Updates a single data object identified by the specified entity set and key fields of
+ * the data object.</p>
+ * @param entitySet the {@link EdmEntitySet} the object must correspond to
+ * @param data the data object of the new entity
+ * @return updated data object instance
+ * @throws org.apache.olingo.odata2.api.exception.ODataNotImplementedException
+ * @throws org.apache.olingo.odata2.api.edm.EdmException
+ * @throws org.apache.olingo.odata2.api.exception.ODataApplicationException
+ */
+ public Object updateData(EdmEntitySet entitySet, Object data)
+ throws ODataNotImplementedException, EdmException, ODataApplicationException {
+
+ DataStore<Object> dataStore = getDataStore(entitySet);
+ return dataStore.update(data);
+ }
+
+ @Override
+ public void deleteData(EdmEntitySet entitySet, Map<String, Object> keys)
+ throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException {
+ DataStore<Object> dataStore = getDataStore(entitySet);
+ Object keyInstance = dataStore.createInstance();
+ ANNOTATION_HELPER.setKeyFields(keyInstance, keys);
+ dataStore.delete(keyInstance);
+ }
+
+ @Override
+ public void createData(EdmEntitySet entitySet, Object data)
+ throws ODataNotImplementedException, EdmException, ODataApplicationException {
+
+ DataStore<Object> dataStore = getDataStore(entitySet);
+ dataStore.create(data);
+ }
+
+ @Override
+ public void deleteRelation(EdmEntitySet sourceEntitySet, Object sourceData, EdmEntitySet targetEntitySet,
+ Map<String, Object> targetKeys)
+ throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException {
+ throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
+ }
+
+ @Override
+ public void writeRelation(EdmEntitySet sourceEntitySet, Object sourceData, EdmEntitySet targetEntitySet,
+ Map<String, Object> targetKeys)
+ throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException {
+ throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
+ }
+
+
+ /**
+ * Returns corresponding DataStore for EdmEntitySet or if no data store is registered an
+ * ODataRuntimeException is thrown.
+ * Never returns NULL.
+ *
+ * @param entitySet for which the corresponding DataStore is returned
+ * @return a DataStore object
+ * @throws EdmException
+ * @throws ODataRuntimeException if no DataStore is found
+ */
+ private DataStore<Object> getDataStore(EdmEntitySet entitySet) throws EdmException {
+ final String name = entitySet.getEntityType().getName();
+ DataStore<Object> dataStore = dataStores.get(name);
+ if(dataStore == null) {
+ throw new ODataRuntimeException("No DataStore found for entity set '" + entitySet + "'.");
+ }
+ return dataStore;
+ }
+
+ private Object getValue(Field field, Object instance) {
+ try {
+ boolean access = field.isAccessible();
+ field.setAccessible(true);
+ Object value = field.get(instance);
+ field.setAccessible(access);
+ return value;
+ } catch (IllegalArgumentException e) {
+ throw new ODataRuntimeException("Error for getting value of field '"
+ + field + "' at instance '" + instance + "'.", e);
+ } catch (IllegalAccessException e) {
+ throw new ODataRuntimeException("Error for getting value of field '"
+ + field + "' at instance '" + instance + "'.", e);
+ }
+ }
+
+ private Field extractSourceField(DataStore sourceStore, DataStore targetStore) {
+ Class sourceDataTypeClass = sourceStore.getDataTypeClass();
+ Class targetDataTypeClass = targetStore.getDataTypeClass();
+
+ return ANNOTATION_HELPER.getCommonNavigationFieldFromTarget(sourceDataTypeClass, targetDataTypeClass);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/b7e7ee0d/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationValueAccess.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationValueAccess.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationValueAccess.java
new file mode 100644
index 0000000..6c65bf8
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationValueAccess.java
@@ -0,0 +1,108 @@
+/*******************************************************************************
+ * 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.core.annotation.data;
+
+import java.util.Collection;
+import org.apache.olingo.odata2.api.data.ValueAccess;
+import org.apache.olingo.odata2.api.edm.EdmMapping;
+import org.apache.olingo.odata2.api.edm.EdmProperty;
+import org.apache.olingo.odata2.api.exception.ODataException;
+import org.apache.olingo.odata2.api.exception.ODataNotImplementedException;
+import org.apache.olingo.odata2.core.annotation.edm.AnnotationHelper;
+
+/**
+ *
+ */
+public class AnnotationValueAccess implements ValueAccess {
+ private final AnnotationHelper annotationHelper = new AnnotationHelper();
+
+ /**
+ * Retrieves the value of an EDM property for the given data object.
+ * @param data the Java data object
+ * @param property the requested {@link EdmProperty}
+ * @return the requested property value
+ */
+ @Override
+ public <T> Object getPropertyValue(final T data, final EdmProperty property) throws ODataException {
+ if(data instanceof Collection) {
+ Collection c = (Collection) data;
+ for (Object object : c) {
+ if(annotationHelper.isEdmAnnotated(data)) {
+ return annotationHelper.getValueForProperty(data, property.getName());
+ }
+ }
+ }
+ if(annotationHelper.isEdmAnnotated(data)) {
+ return annotationHelper.getValueForProperty(data, property.getName());
+ }
+ throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
+ }
+
+ /**
+ * Sets the value of an EDM property for the given data object.
+ * @param data the Java data object
+ * @param property the {@link EdmProperty}
+ * @param value the new value of the property
+ */
+ @Override
+ public <T, V> void setPropertyValue(T data, final EdmProperty property, final V value) throws ODataException {
+ if(annotationHelper.isEdmAnnotated(data)) {
+ annotationHelper.setValueForProperty(data, property.getName(), value);
+ } else {
+ throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
+ }
+ }
+
+ /**
+ * Retrieves the Java type of an EDM property for the given data object.
+ * @param data the Java data object
+ * @param property the requested {@link EdmProperty}
+ * @return the requested Java type
+ */
+ public <T> Class<?> getPropertyType(final T data, final EdmProperty property) throws ODataException {
+ if(annotationHelper.isEdmAnnotated(data)) {
+ Class<?> fieldType = annotationHelper.getFieldTypeForProperty(data, property.getName());
+ if(fieldType == null) {
+ throw new ODataException("No field type found for property " + property);
+ }
+ return fieldType;
+ }
+ throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
+ }
+
+ /**
+ * Retrieves the value defined by a mapping object for the given data object.
+ * @param data the Java data object
+ * @param mapping the requested {@link EdmMapping}
+ * @return the requested value
+ */
+ public <T> Object getMappingValue(final T data, final EdmMapping mapping) throws ODataException {
+ throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
+ }
+
+ /**
+ * Sets the value defined by a mapping object for the given data object.
+ * @param data the Java data object
+ * @param mapping the {@link EdmMapping}
+ * @param value the new value
+ */
+ public <T, V> void setMappingValue(T data, final EdmMapping mapping, final V value) throws ODataException {
+ throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/b7e7ee0d/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/BeanPropertyAccess.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/BeanPropertyAccess.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/BeanPropertyAccess.java
new file mode 100644
index 0000000..be3baac
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/BeanPropertyAccess.java
@@ -0,0 +1,186 @@
+/*******************************************************************************
+ * 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.core.annotation.data;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Arrays;
+
+import org.apache.olingo.odata2.api.data.ValueAccess;
+import org.apache.olingo.odata2.api.edm.EdmException;
+import org.apache.olingo.odata2.api.edm.EdmMapping;
+import org.apache.olingo.odata2.api.edm.EdmProperty;
+import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
+import org.apache.olingo.odata2.api.exception.ODataException;
+import org.apache.olingo.odata2.api.exception.ODataHttpException;
+import org.apache.olingo.odata2.api.exception.ODataNotFoundException;
+
+/**
+ * Data access.
+ */
+public class BeanPropertyAccess implements ValueAccess {
+
+ @Override
+ public <T> Object getPropertyValue(final T data, final EdmProperty property) throws ODataException {
+ return getValue(data, getGetterMethodName(property));
+ }
+
+ @Override
+ public <T, V> void setPropertyValue(T data, final EdmProperty property, final V value) throws ODataException {
+ final String methodName = getSetterMethodName(getGetterMethodName(property));
+ if (methodName != null) {
+ setValue(data, methodName, value);
+ }
+ }
+
+ @Override
+ public <T> Class<?> getPropertyType(final T data, final EdmProperty property) throws ODataException {
+ return getType(data, getGetterMethodName(property));
+ }
+
+ @Override
+ public <T> Object getMappingValue(final T data, final EdmMapping mapping) throws ODataException {
+ if (mapping != null && mapping.getMimeType() != null) {
+ return getValue(data, mapping.getMimeType());
+ }
+ return null;
+ }
+
+ @Override
+ public <T, V> void setMappingValue(T data, final EdmMapping mapping, final V value) throws ODataException {
+ if (mapping != null && mapping.getMimeType() != null) {
+ setValue(data, getSetterMethodName(mapping.getMimeType()), value);
+ }
+ }
+
+ private String getGetterMethodName(final EdmProperty property) throws EdmException {
+ final String prefix = isBooleanProperty(property) ? "is" : "get";
+ final String defaultMethodName = prefix + property.getName();
+ return property.getMapping() == null || property.getMapping().getInternalName() == null ?
+ defaultMethodName : property.getMapping().getInternalName();
+ }
+
+ private boolean isBooleanProperty(final EdmProperty property) throws EdmException {
+ return property.isSimple()
+ && property.getType() == EdmSimpleTypeKind.Boolean.getEdmSimpleTypeInstance();
+ }
+
+ private String getSetterMethodName(final String getterMethodName) {
+ return getterMethodName.contains(".") ?
+ null : getterMethodName.replaceFirst("^is", "set").replaceFirst("^get", "set");
+ }
+
+ private <T> Object getValue(final T data, final String methodName) throws ODataNotFoundException {
+ Object dataObject = data;
+
+ for (final String method : methodName.split("\\.", -1)) {
+ if (dataObject != null) {
+ try {
+ dataObject = dataObject.getClass().getMethod(method).invoke(dataObject);
+ } catch (SecurityException e) {
+ throw new ODataNotFoundException(ODataHttpException.COMMON, e);
+ } catch (NoSuchMethodException e) {
+ throw new ODataNotFoundException(ODataHttpException.COMMON, e);
+ } catch (IllegalArgumentException e) {
+ throw new ODataNotFoundException(ODataHttpException.COMMON, e);
+ } catch (IllegalAccessException e) {
+ throw new ODataNotFoundException(ODataHttpException.COMMON, e);
+ } catch (InvocationTargetException e) {
+ throw new ODataNotFoundException(ODataHttpException.COMMON, e);
+ }
+ }
+ }
+
+ return dataObject;
+ }
+
+ private <T, V> void setValue(final T data, final String methodName, final V value)
+ throws ODataNotFoundException {
+ try {
+ boolean found = false;
+ for (final Method method : Arrays.asList(data.getClass().getMethods())) {
+ if (method.getName().equals(methodName)) {
+ found = true;
+ final Class<?> type = method.getParameterTypes()[0];
+ if (value == null) {
+ if (type.equals(byte.class) || type.equals(short.class) || type.equals(int.class)
+ || type.equals(long.class) || type.equals(char.class)) {
+ method.invoke(data, 0);
+ } else if (type.equals(float.class) || type.equals(double.class)) {
+ method.invoke(data, 0.0);
+ } else if (type.equals(boolean.class)) {
+ method.invoke(data, false);
+ } else {
+ method.invoke(data, value);
+ }
+ } else {
+ method.invoke(data, value);
+ }
+ break;
+ }
+ }
+ if (!found) {
+ throw new ODataNotFoundException(null);
+ }
+ } catch (SecurityException e) {
+ throw new ODataNotFoundException(null, e);
+ } catch (IllegalArgumentException e) {
+ throw new ODataNotFoundException(null, e);
+ } catch (IllegalAccessException e) {
+ throw new ODataNotFoundException(null, e);
+ } catch (InvocationTargetException e) {
+ throw new ODataNotFoundException(null, e);
+ }
+ }
+
+ private <T> Class<?> getType(final T data, final String methodName) throws ODataNotFoundException {
+ if (data == null) {
+ throw new ODataNotFoundException(ODataHttpException.COMMON);
+ }
+
+ Class<?> type = data.getClass();
+ for (final String method : methodName.split("\\.", -1)) {
+ try {
+ type = type.getMethod(method).getReturnType();
+ if (type.isPrimitive()) {
+ if (type == boolean.class) {
+ type = Boolean.class;
+ } else if (type == byte.class) {
+ type = Byte.class;
+ } else if (type == short.class) {
+ type = Short.class;
+ } else if (type == int.class) {
+ type = Integer.class;
+ } else if (type == long.class) {
+ type = Long.class;
+ } else if (type == float.class) {
+ type = Float.class;
+ } else if (type == double.class) {
+ type = Double.class;
+ }
+ }
+ } catch (final SecurityException e) {
+ throw new ODataNotFoundException(ODataHttpException.COMMON, e);
+ } catch (final NoSuchMethodException e) {
+ throw new ODataNotFoundException(ODataHttpException.COMMON, e);
+ }
+ }
+ return type;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/b7e7ee0d/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/DataSourceHolder.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/DataSourceHolder.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/DataSourceHolder.java
new file mode 100644
index 0000000..d4c6f98
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/DataSourceHolder.java
@@ -0,0 +1,212 @@
+/*******************************************************************************
+ * 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.core.annotation.data;
+
+import java.lang.reflect.Method;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.annotation.edm.ds.EntityCreate;
+import org.apache.olingo.odata2.api.annotation.edm.ds.EntityDataSource;
+import org.apache.olingo.odata2.api.annotation.edm.ds.EntityDelete;
+import org.apache.olingo.odata2.api.annotation.edm.ds.EntityRead;
+import org.apache.olingo.odata2.api.annotation.edm.ds.EntitySetRead;
+import org.apache.olingo.odata2.api.annotation.edm.ds.EntityUpdate;
+import org.apache.olingo.odata2.api.uri.KeyPredicate;
+import org.apache.olingo.odata2.core.annotation.edm.AnnotationHelper;
+
+/**
+ *
+ */
+public final class DataSourceHolder {
+
+ private static final AnnotationHelper ANNOTATION_HELPER = new AnnotationHelper();
+ private static final Object[] EMPTY_ARRAY = new Object[0];
+
+ private final String name;
+ private final Object dataSourceInstance;
+ private final Class<?> entityTypeClass;
+ private Method readMethod;
+ private Method createMethod;
+ private Method updateMethod;
+ private Method deleteMethod;
+ private Method readSetMethod;
+
+ public DataSourceHolder(Class<?> clz) {
+ EntityDataSource eds = clz.getAnnotation(EntityDataSource.class);
+ entityTypeClass = eds.entityType();
+ EdmEntityType entityType = entityTypeClass.getAnnotation(EdmEntityType.class);
+ if (entityType == null) {
+ throw new IllegalArgumentException("Missing EdmEntityType Annotation at class " + clz);
+ }
+
+ if (entityType.name().isEmpty()) {
+ name = ANNOTATION_HELPER.getCanonicalName(entityTypeClass);
+ } else {
+ name = entityType.name();
+ }
+ dataSourceInstance = createInstance(clz);
+ initMethods(clz);
+ }
+
+ private void initMethods(Class<?> clz) throws IllegalArgumentException, SecurityException {
+ Method[] methods = clz.getDeclaredMethods();
+ for (Method method : methods) {
+ EntityRead ec = method.getAnnotation(EntityRead.class);
+ if (ec != null) {
+ readMethod = method;
+ }
+ EntityCreate ep = method.getAnnotation(EntityCreate.class);
+ if (ep != null) {
+ createMethod = method;
+ }
+ EntityUpdate update = method.getAnnotation(EntityUpdate.class);
+ if (update != null) {
+ updateMethod = method;
+ }
+ EntityDelete delete = method.getAnnotation(EntityDelete.class);
+ if (delete != null) {
+ deleteMethod = method;
+ }
+ EntitySetRead readSet = method.getAnnotation(EntitySetRead.class);
+ if (readSet != null) {
+ readSetMethod = method;
+ }
+ }
+
+ validateMethods(clz);
+ }
+
+ private void validateMethods(Class<?> clz) throws IllegalArgumentException {
+ //
+ if (readMethod == null) {
+ throw new IllegalArgumentException("Missing " + EntityRead.class
+ + " annotation at " + EntityDataSource.class + " annotated class " + clz);
+ }
+ if (updateMethod == null) {
+ throw new IllegalArgumentException("Missing " + EntityUpdate.class
+ + " annotation at " + EntityDataSource.class + " annotated class " + clz);
+ }
+ if (createMethod == null) {
+ throw new IllegalArgumentException("Missing " + EntityCreate.class
+ + " annotation at " + EntityDataSource.class + " annotated class " + clz);
+ }
+
+ if(readSetMethod != null) {
+ if(!Collection.class.isAssignableFrom(readSetMethod.getReturnType())) {
+ throw new IllegalArgumentException("Read set method must have a return type which is assignable to "
+ + Collection.class + " but return type for annotated method " + readSetMethod + " is "
+ + readSetMethod.getReturnType());
+ }
+ }
+ }
+
+ public Object readEntity(Object[] keyValues) {
+ if (readMethod.getParameterTypes().length != keyValues.length) {
+ throw new IllegalStateException("Wrong amount of key properties. Expected read keys = "
+ + Arrays.toString(readMethod.getParameterTypes()) + " given key predicates = "
+ + Arrays.toString(keyValues));
+ }
+
+ return invoke(readMethod, keyValues);
+ }
+
+ public Object readEntity(List<KeyPredicate> keys) {
+ Object[] parameterKeys = mapParameterKeys(readMethod, keys);
+ return invoke(readMethod, parameterKeys);
+ }
+
+ private Object[] mapParameterKeys(Method method, List<KeyPredicate> keys) throws IllegalStateException {
+ if(method == null) {
+ return EMPTY_ARRAY;
+ }
+ Class<?>[] pTypes = method.getParameterTypes();
+ if (pTypes.length != keys.size()) {
+ throw new IllegalStateException("Wrong amount of key properties. Expected read keys = "
+ + Arrays.toString(pTypes) + " given key predicates = " + keys);
+ }
+ Object[] parameterKeys = new Object[pTypes.length];
+ int i = 0;
+ for (KeyPredicate keyPredicate : keys) {
+ if (matches(pTypes[i], keyPredicate)) {
+ parameterKeys[i] = keyPredicate.getLiteral();
+ }
+ i++;
+ }
+ return parameterKeys;
+ }
+
+ public Object createEntity(Object key) {
+ return invoke(createMethod, new Object[]{key});
+ }
+
+ public Object updateEntity(Object key) {
+ return invoke(updateMethod, new Object[]{key});
+ }
+
+ public Object deleteEntity(List<KeyPredicate> keys) {
+ Object[] parameterKeys = mapParameterKeys(deleteMethod, keys);
+ return invoke(deleteMethod, parameterKeys);
+ }
+
+ public Collection<?> readEntitySet() {
+ return (Collection<?>) invoke(readSetMethod, new Object[0]);
+ }
+
+ private Object invoke(Method m, Object[] objs) {
+ try {
+ return m.invoke(dataSourceInstance, objs);
+ } catch (Exception ex) {
+ return null;
+ }
+ }
+
+ public Object createEntityInstance() {
+ return createInstance(this.entityTypeClass);
+ }
+
+ private static Object createInstance(Class<?> clz) {
+ try {
+ return clz.newInstance();
+ } catch (Exception ex) {
+ return null;
+ }
+ }
+
+ public String getEntityName() {
+ return this.name;
+ }
+
+ public Class<?> getEntityTypeClass() {
+ return entityTypeClass;
+ }
+
+ @Override
+ public String toString() {
+ return "DataSourceHolder{" + "name=" + name + ", dataSourceInstance=" + dataSourceInstance +
+ ", entityTypeClass=" + entityTypeClass + ", consumerMethod=" + readMethod +
+ ", createMethod=" + createMethod + ", updateMethod=" + updateMethod + '}';
+ }
+
+ private boolean matches(Class<?> aClass, KeyPredicate type) {
+ return true;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/b7e7ee0d/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/DataStore.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/DataStore.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/DataStore.java
new file mode 100644
index 0000000..f8045f1
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/DataStore.java
@@ -0,0 +1,182 @@
+/*******************************************************************************
+ * 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.core.annotation.data;
+
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+
+import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
+import org.apache.olingo.odata2.api.annotation.edm.ds.EntityCreate;
+import org.apache.olingo.odata2.api.annotation.edm.ds.EntityDelete;
+import org.apache.olingo.odata2.api.annotation.edm.ds.EntityRead;
+import org.apache.olingo.odata2.api.annotation.edm.ds.EntitySetRead;
+import org.apache.olingo.odata2.api.annotation.edm.ds.EntityUpdate;
+import org.apache.olingo.odata2.api.exception.ODataApplicationException;
+import org.apache.olingo.odata2.core.annotation.edm.AnnotationHelper;
+import org.apache.olingo.odata2.core.exception.ODataRuntimeException;
+
+/**
+ *
+ */
+public class DataStore<T> {
+
+ private static final AnnotationHelper ANNOTATION_HELPER = new AnnotationHelper();
+ private final List<T> dataStore;
+ private final Class<T> dataTypeClass;
+
+ private int idCounter = 1;
+
+ private static class InMemoryDataStore {
+ private static final Map<Class<?>, DataStore<?>> c2ds = new HashMap<Class<?>, DataStore<?>>();
+ @SuppressWarnings("unchecked")
+ static DataStore<?> getInstance(Class<?> clz) {
+ DataStore<?> ds = c2ds.get(clz);
+ if(ds == null) {
+ ds = new DataStore<Object>((Class<Object>) clz);
+ c2ds.put(clz, ds);
+ }
+ return ds;
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ public static <T> DataStore<T> createInMemory(Class<T> clazz) {
+ return (DataStore<T>) InMemoryDataStore.getInstance(clazz);
+ }
+
+ private DataStore(List<T> wrapStore, Class<T> clz) {
+ dataStore = wrapStore;
+ dataTypeClass = clz;
+ }
+
+ private DataStore(Class<T> clz) {
+ this(new ArrayList<T>(), clz);
+ }
+
+ public Class<T> getDataTypeClass() {
+ return dataTypeClass;
+ }
+
+ public T createInstance() {
+ try {
+ return dataTypeClass.newInstance();
+ } catch (InstantiationException e) {
+ throw new ODataRuntimeException("Unable to create instance of class '" + dataTypeClass + "'.", e);
+ } catch (IllegalAccessException e) {
+ throw new ODataRuntimeException("Unable to create instance of class '" + dataTypeClass + "'.", e);
+ }
+ }
+
+ @EntityRead
+ public T read(T obj) {
+ List<Object> objKeys = getKeys(obj);
+ for (T stored : dataStore) {
+ if (objKeys.equals(getKeys(stored))) {
+ return stored;
+ }
+ }
+ return null;
+ }
+
+ @EntitySetRead
+ public Collection<T> read() {
+ return Collections.unmodifiableCollection(dataStore);
+ }
+
+ @EntityCreate
+ public T create(T object) throws DataStoreException {
+ createKeys(object);
+ dataStore.add(object);
+ return object;
+ }
+
+ @EntityUpdate
+ public T update(T object) {
+ T stored = read(object);
+ dataStore.remove(stored);
+ dataStore.add(object);
+ return object;
+ }
+
+ @EntityDelete
+ public T delete(T object) {
+ T stored = read(object);
+ if(stored != null) {
+ dataStore.remove(stored);
+ }
+ return stored;
+ }
+
+ private List<Object> getKeys(T object) {
+ Map<String, Object> keys = ANNOTATION_HELPER.getValueForAnnotatedFields(object, EdmKey.class);
+
+ // XXX: list should be in a defined order -> better to create an 'Key' object which is comparable
+ List<Object> keyList = new ArrayList(keys.values());
+ return keyList;
+ }
+
+ private T createKeys(T object) throws DataStoreException {
+ List<Field> fields = ANNOTATION_HELPER.getAnnotatedFields(object, EdmKey.class);
+ if(fields.isEmpty()) {
+ throw new DataStoreException("No EdmKey annotated fields found for class " + object.getClass());
+ }
+ Map<String, Object> fieldName2KeyValue = new HashMap<String, Object>();
+
+ for (Field field : fields) {
+ Object key = createKey(field);
+ fieldName2KeyValue.put(ANNOTATION_HELPER.getCanonicalName(field), key);
+ }
+
+ ANNOTATION_HELPER.setValuesToAnnotatedFields(fieldName2KeyValue, object, EdmKey.class);
+
+ return object;
+ }
+
+ private Object createKey(Field field) {
+ Class<?> type = field.getType();
+
+ if(type == String.class) {
+ return String.valueOf(idCounter++);
+ } else if(type == Integer.class || type == int.class) {
+ return Integer.valueOf(idCounter++);
+ } else if(type == Long.class || type == long.class) {
+ return Long.valueOf(idCounter++);
+ }
+
+ throw new UnsupportedOperationException("Automated key generation for type '" + type
+ + "' is not supported (caused on field '" + field + "').");
+ }
+
+ public static class DataStoreException extends ODataApplicationException {
+
+ public DataStoreException(String message) {
+ this(message, null);
+ }
+
+ public DataStoreException(String message, Throwable cause) {
+ super(message, Locale.ENGLISH, cause);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/b7e7ee0d/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/ds/AnnotationInMemoryDs.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/ds/AnnotationInMemoryDs.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/ds/AnnotationInMemoryDs.java
deleted file mode 100644
index a07765d..0000000
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/ds/AnnotationInMemoryDs.java
+++ /dev/null
@@ -1,255 +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.core.annotation.ds;
-
-import java.lang.reflect.Field;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceContent;
-import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceMimeType;
-import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
-import org.apache.olingo.odata2.api.data.ListsDataSource;
-import org.apache.olingo.odata2.api.edm.EdmEntitySet;
-import org.apache.olingo.odata2.api.edm.EdmException;
-import org.apache.olingo.odata2.api.edm.EdmFunctionImport;
-import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
-import org.apache.olingo.odata2.api.exception.ODataApplicationException;
-import org.apache.olingo.odata2.api.exception.ODataNotFoundException;
-import org.apache.olingo.odata2.api.exception.ODataNotImplementedException;
-import org.apache.olingo.odata2.core.annotation.edm.AnnotationHelper;
-import org.apache.olingo.odata2.core.annotation.edm.ClassHelper;
-import org.apache.olingo.odata2.core.exception.ODataRuntimeException;
-
-public class AnnotationInMemoryDs implements ListsDataSource {
-
- private static final AnnotationHelper ANNOTATION_HELPER = new AnnotationHelper();
- private final Map<String, DataStore<Object>> dataStores = new HashMap<String, DataStore<Object>>();
-
- public AnnotationInMemoryDs(String packageToScan) {
- List<Class<?>> foundClasses = ClassHelper.loadClasses(packageToScan, new ClassHelper.ClassValidator() {
- @Override
- public boolean isClassValid(Class<?> c) {
- return null != c.getAnnotation(EdmEntityType.class);
- }
- });
-
- init(foundClasses);
- }
-
- @SuppressWarnings("unchecked")
- private void init(List<Class<?>> foundClasses) {
- for (Class<?> clz : foundClasses) {
-
- DataStore<Object> dhs = (DataStore<Object>) DataStore.createInMemory(clz);
- EdmEntityType entityType = clz.getAnnotation(EdmEntityType.class);
- dataStores.put(entityType.name(), dhs);
- }
- }
-
- public <T> DataStore<T> getDataStore(Class<T> clazz) {
- return DataStore.createInMemory(clazz);
- }
-
- @Override
- public List<?> readData(EdmEntitySet entitySet) throws ODataNotImplementedException,
- ODataNotFoundException, EdmException, ODataApplicationException {
-
- DataStore<Object> holder = getDataStore(entitySet);
- if (holder != null) {
- return new ArrayList(holder.read());
- }
-
- throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
- }
-
- @Override
- public Object readData(EdmEntitySet entitySet, Map<String, Object> keys)
- throws ODataNotFoundException, EdmException, ODataApplicationException {
-
- DataStore<Object> store = getDataStore(entitySet);
- if (store != null) {
- Object keyInstance = store.createInstance();
- ANNOTATION_HELPER.setKeyFields(keyInstance, keys.values().toArray());
-
- Object result = store.read(keyInstance);
- if (result != null) {
- return result;
- }
- }
-
- throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
- }
-
- @Override
- public Object readData(EdmFunctionImport function, Map<String, Object> parameters, Map<String, Object> keys)
- throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException {
- throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
- }
-
- @Override
- public Object readRelatedData(EdmEntitySet sourceEntitySet, Object sourceData, EdmEntitySet targetEntitySet,
- Map<String, Object> targetKeys)
- throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException {
-
- if (targetKeys.isEmpty()) {
- String sourceName = sourceEntitySet.getEntityType().getName();
- DataStore sourceStore = dataStores.get(sourceName);
-
- String targetName = targetEntitySet.getEntityType().getName();
- DataStore targetStore = dataStores.get(targetName);
-
- Field sourceFieldAtTarget = extractSourceField(sourceStore, targetStore);
- if (sourceFieldAtTarget == null) {
- throw new ODataRuntimeException("Missing source field for related data.");
- }
-
- Collection targetData = targetStore.read();
- List resultData = new ArrayList();
- for (Object targetInstance : targetData) {
- Object targetNavigationInstance = getValue(sourceFieldAtTarget, targetInstance);
- if(targetNavigationInstance instanceof Collection) {
- Collection c = (Collection) targetNavigationInstance;
- for (Object object : c) {
- if (ANNOTATION_HELPER.keyMatch(sourceData, object)) {
- resultData.add(targetInstance);
- }
- }
- } else if (ANNOTATION_HELPER.keyMatch(sourceData, targetNavigationInstance)) {
- resultData.add(targetInstance);
- }
- }
-
- EdmNavigationProperty navProperty = sourceFieldAtTarget.getAnnotation(EdmNavigationProperty.class);
- if(navProperty.from().multiplicity() == EdmMultiplicity.ONE) {
- if(resultData.isEmpty()) {
- return null;
- }
- return resultData.get(0);
- }
- return resultData;
- } else {
- throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
- }
- }
-
- @Override
- public BinaryData readBinaryData(EdmEntitySet entitySet, Object mediaLinkEntryData)
- throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException {
-
- Object data = ANNOTATION_HELPER.getValueForField(mediaLinkEntryData, EdmMediaResourceContent.class);
- Object mimeType = ANNOTATION_HELPER.getValueForField(mediaLinkEntryData, EdmMediaResourceMimeType.class);
-
- BinaryData db = new BinaryData((byte[])data, String.valueOf(mimeType));
- return db;
- }
-
- @Override
- public Object newDataObject(EdmEntitySet entitySet)
- throws ODataNotImplementedException, EdmException, ODataApplicationException {
-
- DataStore<Object> dataStore = getDataStore(entitySet);
- if (dataStore != null) {
- return dataStore.createInstance();
- }
-
- throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
- }
-
- @Override
- public void writeBinaryData(EdmEntitySet entitySet, Object mediaLinkEntryData, BinaryData binaryData)
- throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException {
- throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
-
- }
-
- @Override
- public void deleteData(EdmEntitySet entitySet, Map<String, Object> keys)
- throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException {
- DataStore<Object> dataStore = getDataStore(entitySet);
- Object keyInstance = dataStore.createInstance();
- ANNOTATION_HELPER.setKeyFields(keyInstance, keys.values().toArray());
- dataStore.delete(keyInstance);
- }
-
- @Override
- public void createData(EdmEntitySet entitySet, Object data)
- throws ODataNotImplementedException, EdmException, ODataApplicationException {
-
- DataStore<Object> dataStore = getDataStore(entitySet);
- dataStore.create(data);
- }
-
- @Override
- public void deleteRelation(EdmEntitySet sourceEntitySet, Object sourceData, EdmEntitySet targetEntitySet,
- Map<String, Object> targetKeys)
- throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException {
- throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
- }
-
- @Override
- public void writeRelation(EdmEntitySet sourceEntitySet, Object sourceData, EdmEntitySet targetEntitySet,
- Map<String, Object> targetKeys)
- throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException {
- throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
- }
-
-
- /**
- * Returns corresponding DataStore for EdmEntitySet or if no data store is registered an
- * ODataRuntimeException is thrown.
- * Never returns NULL.
- *
- * @param entitySet for which the corresponding DataStore is returned
- * @return a DataStore object
- * @throws EdmException
- * @throws ODataRuntimeException if no DataStore is found
- */
- private DataStore<Object> getDataStore(EdmEntitySet entitySet) throws EdmException {
- final String name = entitySet.getEntityType().getName();
- DataStore<Object> dataStore = dataStores.get(name);
- if(dataStore == null) {
- throw new ODataRuntimeException("No DataStore found for entity set '" + entitySet + "'.");
- }
- return dataStore;
- }
-
- private Object getValue(Field field, Object instance) {
- try {
- boolean access = field.isAccessible();
- field.setAccessible(true);
- Object value = field.get(instance);
- field.setAccessible(access);
- return value;
- } catch (IllegalArgumentException e) {
- throw new ODataRuntimeException("Error for getting value of field '"
- + field + "' at instance '" + instance + "'.", e);
- } catch (IllegalAccessException e) {
- throw new ODataRuntimeException("Error for getting value of field '"
- + field + "' at instance '" + instance + "'.", e);
- }
- }
-
- private Field extractSourceField(DataStore sourceStore, DataStore targetStore) {
- Class sourceDataTypeClass = sourceStore.getDataTypeClass();
- Class targetDataTypeClass = targetStore.getDataTypeClass();
-
- return ANNOTATION_HELPER.getCommonNavigationFieldFromTarget(sourceDataTypeClass, targetDataTypeClass);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/b7e7ee0d/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/ds/AnnotationValueAccess.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/ds/AnnotationValueAccess.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/ds/AnnotationValueAccess.java
deleted file mode 100644
index 5963131..0000000
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/ds/AnnotationValueAccess.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/*******************************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- ******************************************************************************/
-package org.apache.olingo.odata2.core.annotation.ds;
-
-import java.util.Collection;
-import org.apache.olingo.odata2.api.data.ValueAccess;
-import org.apache.olingo.odata2.api.edm.EdmMapping;
-import org.apache.olingo.odata2.api.edm.EdmProperty;
-import org.apache.olingo.odata2.api.exception.ODataException;
-import org.apache.olingo.odata2.api.exception.ODataNotImplementedException;
-import org.apache.olingo.odata2.core.annotation.edm.AnnotationHelper;
-
-/**
- *
- */
-public class AnnotationValueAccess implements ValueAccess {
- private final AnnotationHelper annotationHelper = new AnnotationHelper();
-
- /**
- * Retrieves the value of an EDM property for the given data object.
- * @param data the Java data object
- * @param property the requested {@link EdmProperty}
- * @return the requested property value
- */
- @Override
- public <T> Object getPropertyValue(final T data, final EdmProperty property) throws ODataException {
- if(data instanceof Collection) {
- Collection c = (Collection) data;
- for (Object object : c) {
- if(annotationHelper.isEdmAnnotated(data)) {
- return annotationHelper.getValueForProperty(data, property.getName());
- }
- }
- }
- if(annotationHelper.isEdmAnnotated(data)) {
- return annotationHelper.getValueForProperty(data, property.getName());
- }
- throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
- }
-
- /**
- * Sets the value of an EDM property for the given data object.
- * @param data the Java data object
- * @param property the {@link EdmProperty}
- * @param value the new value of the property
- */
- @Override
- public <T, V> void setPropertyValue(T data, final EdmProperty property, final V value) throws ODataException {
- if(annotationHelper.isEdmAnnotated(data)) {
- annotationHelper.setValueForProperty(data, property.getName(), value);
- } else {
- throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
- }
- }
-
- /**
- * Retrieves the Java type of an EDM property for the given data object.
- * @param data the Java data object
- * @param property the requested {@link EdmProperty}
- * @return the requested Java type
- */
- public <T> Class<?> getPropertyType(final T data, final EdmProperty property) throws ODataException {
- if(annotationHelper.isEdmAnnotated(data)) {
- Class<?> fieldType = annotationHelper.getFieldTypeForProperty(data, property.getName());
- if(fieldType == null) {
- throw new ODataException("No field type found for property " + property);
- }
- return fieldType;
- }
- throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
- }
-
- /**
- * Retrieves the value defined by a mapping object for the given data object.
- * @param data the Java data object
- * @param mapping the requested {@link EdmMapping}
- * @return the requested value
- */
- public <T> Object getMappingValue(final T data, final EdmMapping mapping) throws ODataException {
- throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
- }
-
- /**
- * Sets the value defined by a mapping object for the given data object.
- * @param data the Java data object
- * @param mapping the {@link EdmMapping}
- * @param value the new value
- */
- public <T, V> void setMappingValue(T data, final EdmMapping mapping, final V value) throws ODataException {
- throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/b7e7ee0d/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/ds/BeanPropertyAccess.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/ds/BeanPropertyAccess.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/ds/BeanPropertyAccess.java
deleted file mode 100644
index 4b00c40..0000000
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/ds/BeanPropertyAccess.java
+++ /dev/null
@@ -1,186 +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.core.annotation.ds;
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.Arrays;
-
-import org.apache.olingo.odata2.api.data.ValueAccess;
-import org.apache.olingo.odata2.api.edm.EdmException;
-import org.apache.olingo.odata2.api.edm.EdmMapping;
-import org.apache.olingo.odata2.api.edm.EdmProperty;
-import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
-import org.apache.olingo.odata2.api.exception.ODataException;
-import org.apache.olingo.odata2.api.exception.ODataHttpException;
-import org.apache.olingo.odata2.api.exception.ODataNotFoundException;
-
-/**
- * Data access.
- */
-public class BeanPropertyAccess implements ValueAccess {
-
- @Override
- public <T> Object getPropertyValue(final T data, final EdmProperty property) throws ODataException {
- return getValue(data, getGetterMethodName(property));
- }
-
- @Override
- public <T, V> void setPropertyValue(T data, final EdmProperty property, final V value) throws ODataException {
- final String methodName = getSetterMethodName(getGetterMethodName(property));
- if (methodName != null) {
- setValue(data, methodName, value);
- }
- }
-
- @Override
- public <T> Class<?> getPropertyType(final T data, final EdmProperty property) throws ODataException {
- return getType(data, getGetterMethodName(property));
- }
-
- @Override
- public <T> Object getMappingValue(final T data, final EdmMapping mapping) throws ODataException {
- if (mapping != null && mapping.getMimeType() != null) {
- return getValue(data, mapping.getMimeType());
- }
- return null;
- }
-
- @Override
- public <T, V> void setMappingValue(T data, final EdmMapping mapping, final V value) throws ODataException {
- if (mapping != null && mapping.getMimeType() != null) {
- setValue(data, getSetterMethodName(mapping.getMimeType()), value);
- }
- }
-
- private String getGetterMethodName(final EdmProperty property) throws EdmException {
- final String prefix = isBooleanProperty(property) ? "is" : "get";
- final String defaultMethodName = prefix + property.getName();
- return property.getMapping() == null || property.getMapping().getInternalName() == null ?
- defaultMethodName : property.getMapping().getInternalName();
- }
-
- private boolean isBooleanProperty(final EdmProperty property) throws EdmException {
- return property.isSimple()
- && property.getType() == EdmSimpleTypeKind.Boolean.getEdmSimpleTypeInstance();
- }
-
- private String getSetterMethodName(final String getterMethodName) {
- return getterMethodName.contains(".") ?
- null : getterMethodName.replaceFirst("^is", "set").replaceFirst("^get", "set");
- }
-
- private <T> Object getValue(final T data, final String methodName) throws ODataNotFoundException {
- Object dataObject = data;
-
- for (final String method : methodName.split("\\.", -1)) {
- if (dataObject != null) {
- try {
- dataObject = dataObject.getClass().getMethod(method).invoke(dataObject);
- } catch (SecurityException e) {
- throw new ODataNotFoundException(ODataHttpException.COMMON, e);
- } catch (NoSuchMethodException e) {
- throw new ODataNotFoundException(ODataHttpException.COMMON, e);
- } catch (IllegalArgumentException e) {
- throw new ODataNotFoundException(ODataHttpException.COMMON, e);
- } catch (IllegalAccessException e) {
- throw new ODataNotFoundException(ODataHttpException.COMMON, e);
- } catch (InvocationTargetException e) {
- throw new ODataNotFoundException(ODataHttpException.COMMON, e);
- }
- }
- }
-
- return dataObject;
- }
-
- private <T, V> void setValue(final T data, final String methodName, final V value)
- throws ODataNotFoundException {
- try {
- boolean found = false;
- for (final Method method : Arrays.asList(data.getClass().getMethods())) {
- if (method.getName().equals(methodName)) {
- found = true;
- final Class<?> type = method.getParameterTypes()[0];
- if (value == null) {
- if (type.equals(byte.class) || type.equals(short.class) || type.equals(int.class)
- || type.equals(long.class) || type.equals(char.class)) {
- method.invoke(data, 0);
- } else if (type.equals(float.class) || type.equals(double.class)) {
- method.invoke(data, 0.0);
- } else if (type.equals(boolean.class)) {
- method.invoke(data, false);
- } else {
- method.invoke(data, value);
- }
- } else {
- method.invoke(data, value);
- }
- break;
- }
- }
- if (!found) {
- throw new ODataNotFoundException(null);
- }
- } catch (SecurityException e) {
- throw new ODataNotFoundException(null, e);
- } catch (IllegalArgumentException e) {
- throw new ODataNotFoundException(null, e);
- } catch (IllegalAccessException e) {
- throw new ODataNotFoundException(null, e);
- } catch (InvocationTargetException e) {
- throw new ODataNotFoundException(null, e);
- }
- }
-
- private <T> Class<?> getType(final T data, final String methodName) throws ODataNotFoundException {
- if (data == null) {
- throw new ODataNotFoundException(ODataHttpException.COMMON);
- }
-
- Class<?> type = data.getClass();
- for (final String method : methodName.split("\\.", -1)) {
- try {
- type = type.getMethod(method).getReturnType();
- if (type.isPrimitive()) {
- if (type == boolean.class) {
- type = Boolean.class;
- } else if (type == byte.class) {
- type = Byte.class;
- } else if (type == short.class) {
- type = Short.class;
- } else if (type == int.class) {
- type = Integer.class;
- } else if (type == long.class) {
- type = Long.class;
- } else if (type == float.class) {
- type = Float.class;
- } else if (type == double.class) {
- type = Double.class;
- }
- }
- } catch (final SecurityException e) {
- throw new ODataNotFoundException(ODataHttpException.COMMON, e);
- } catch (final NoSuchMethodException e) {
- throw new ODataNotFoundException(ODataHttpException.COMMON, e);
- }
- }
- return type;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/b7e7ee0d/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/ds/DataSourceHolder.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/ds/DataSourceHolder.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/ds/DataSourceHolder.java
deleted file mode 100644
index cb5502b..0000000
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/ds/DataSourceHolder.java
+++ /dev/null
@@ -1,212 +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.core.annotation.ds;
-
-import java.lang.reflect.Method;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.annotation.edm.ds.EntityCreate;
-import org.apache.olingo.odata2.api.annotation.edm.ds.EntityDataSource;
-import org.apache.olingo.odata2.api.annotation.edm.ds.EntityDelete;
-import org.apache.olingo.odata2.api.annotation.edm.ds.EntityRead;
-import org.apache.olingo.odata2.api.annotation.edm.ds.EntitySetRead;
-import org.apache.olingo.odata2.api.annotation.edm.ds.EntityUpdate;
-import org.apache.olingo.odata2.api.uri.KeyPredicate;
-import org.apache.olingo.odata2.core.annotation.edm.AnnotationHelper;
-
-/**
- *
- */
-public final class DataSourceHolder {
-
- private static final AnnotationHelper ANNOTATION_HELPER = new AnnotationHelper();
- private static final Object[] EMPTY_ARRAY = new Object[0];
-
- private final String name;
- private final Object dataSourceInstance;
- private final Class<?> entityTypeClass;
- private Method readMethod;
- private Method createMethod;
- private Method updateMethod;
- private Method deleteMethod;
- private Method readSetMethod;
-
- public DataSourceHolder(Class<?> clz) {
- EntityDataSource eds = clz.getAnnotation(EntityDataSource.class);
- entityTypeClass = eds.entityType();
- EdmEntityType entityType = entityTypeClass.getAnnotation(EdmEntityType.class);
- if (entityType == null) {
- throw new IllegalArgumentException("Missing EdmEntityType Annotation at class " + clz);
- }
-
- if (entityType.name().isEmpty()) {
- name = ANNOTATION_HELPER.getCanonicalName(entityTypeClass);
- } else {
- name = entityType.name();
- }
- dataSourceInstance = createInstance(clz);
- initMethods(clz);
- }
-
- private void initMethods(Class<?> clz) throws IllegalArgumentException, SecurityException {
- Method[] methods = clz.getDeclaredMethods();
- for (Method method : methods) {
- EntityRead ec = method.getAnnotation(EntityRead.class);
- if (ec != null) {
- readMethod = method;
- }
- EntityCreate ep = method.getAnnotation(EntityCreate.class);
- if (ep != null) {
- createMethod = method;
- }
- EntityUpdate update = method.getAnnotation(EntityUpdate.class);
- if (update != null) {
- updateMethod = method;
- }
- EntityDelete delete = method.getAnnotation(EntityDelete.class);
- if (delete != null) {
- deleteMethod = method;
- }
- EntitySetRead readSet = method.getAnnotation(EntitySetRead.class);
- if (readSet != null) {
- readSetMethod = method;
- }
- }
-
- validateMethods(clz);
- }
-
- private void validateMethods(Class<?> clz) throws IllegalArgumentException {
- //
- if (readMethod == null) {
- throw new IllegalArgumentException("Missing " + EntityRead.class
- + " annotation at " + EntityDataSource.class + " annotated class " + clz);
- }
- if (updateMethod == null) {
- throw new IllegalArgumentException("Missing " + EntityUpdate.class
- + " annotation at " + EntityDataSource.class + " annotated class " + clz);
- }
- if (createMethod == null) {
- throw new IllegalArgumentException("Missing " + EntityCreate.class
- + " annotation at " + EntityDataSource.class + " annotated class " + clz);
- }
-
- if(readSetMethod != null) {
- if(!Collection.class.isAssignableFrom(readSetMethod.getReturnType())) {
- throw new IllegalArgumentException("Read set method must have a return type which is assignable to "
- + Collection.class + " but return type for annotated method " + readSetMethod + " is "
- + readSetMethod.getReturnType());
- }
- }
- }
-
- public Object readEntity(Object[] keyValues) {
- if (readMethod.getParameterTypes().length != keyValues.length) {
- throw new IllegalStateException("Wrong amount of key properties. Expected read keys = "
- + Arrays.toString(readMethod.getParameterTypes()) + " given key predicates = "
- + Arrays.toString(keyValues));
- }
-
- return invoke(readMethod, keyValues);
- }
-
- public Object readEntity(List<KeyPredicate> keys) {
- Object[] parameterKeys = mapParameterKeys(readMethod, keys);
- return invoke(readMethod, parameterKeys);
- }
-
- private Object[] mapParameterKeys(Method method, List<KeyPredicate> keys) throws IllegalStateException {
- if(method == null) {
- return EMPTY_ARRAY;
- }
- Class<?>[] pTypes = method.getParameterTypes();
- if (pTypes.length != keys.size()) {
- throw new IllegalStateException("Wrong amount of key properties. Expected read keys = "
- + Arrays.toString(pTypes) + " given key predicates = " + keys);
- }
- Object[] parameterKeys = new Object[pTypes.length];
- int i = 0;
- for (KeyPredicate keyPredicate : keys) {
- if (matches(pTypes[i], keyPredicate)) {
- parameterKeys[i] = keyPredicate.getLiteral();
- }
- i++;
- }
- return parameterKeys;
- }
-
- public Object createEntity(Object key) {
- return invoke(createMethod, new Object[]{key});
- }
-
- public Object updateEntity(Object key) {
- return invoke(updateMethod, new Object[]{key});
- }
-
- public Object deleteEntity(List<KeyPredicate> keys) {
- Object[] parameterKeys = mapParameterKeys(deleteMethod, keys);
- return invoke(deleteMethod, parameterKeys);
- }
-
- public Collection<?> readEntitySet() {
- return (Collection<?>) invoke(readSetMethod, new Object[0]);
- }
-
- private Object invoke(Method m, Object[] objs) {
- try {
- return m.invoke(dataSourceInstance, objs);
- } catch (Exception ex) {
- return null;
- }
- }
-
- public Object createEntityInstance() {
- return createInstance(this.entityTypeClass);
- }
-
- private static Object createInstance(Class<?> clz) {
- try {
- return clz.newInstance();
- } catch (Exception ex) {
- return null;
- }
- }
-
- public String getEntityName() {
- return this.name;
- }
-
- public Class<?> getEntityTypeClass() {
- return entityTypeClass;
- }
-
- @Override
- public String toString() {
- return "DataSourceHolder{" + "name=" + name + ", dataSourceInstance=" + dataSourceInstance +
- ", entityTypeClass=" + entityTypeClass + ", consumerMethod=" + readMethod +
- ", createMethod=" + createMethod + ", updateMethod=" + updateMethod + '}';
- }
-
- private boolean matches(Class<?> aClass, KeyPredicate type) {
- return true;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/b7e7ee0d/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/ds/DataStore.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/ds/DataStore.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/ds/DataStore.java
deleted file mode 100644
index 77eb47d..0000000
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/ds/DataStore.java
+++ /dev/null
@@ -1,166 +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.core.annotation.ds;
-
-import java.lang.reflect.Field;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
-import org.apache.olingo.odata2.api.annotation.edm.ds.EntityCreate;
-import org.apache.olingo.odata2.api.annotation.edm.ds.EntityDelete;
-import org.apache.olingo.odata2.api.annotation.edm.ds.EntityRead;
-import org.apache.olingo.odata2.api.annotation.edm.ds.EntitySetRead;
-import org.apache.olingo.odata2.api.annotation.edm.ds.EntityUpdate;
-import org.apache.olingo.odata2.core.annotation.edm.AnnotationHelper;
-import org.apache.olingo.odata2.core.exception.ODataRuntimeException;
-
-/**
- *
- */
-public class DataStore<T> {
-
- private static final AnnotationHelper ANNOTATION_HELPER = new AnnotationHelper();
- private final List<T> dataStore;
- private final Class<T> dataTypeClass;
-
- private int idCounter = 1;
-
- private static class InMemoryDataStore {
- private static final Map<Class<?>, DataStore<?>> c2ds = new HashMap<Class<?>, DataStore<?>>();
- @SuppressWarnings("unchecked")
- static DataStore<?> getInstance(Class<?> clz) {
- DataStore<?> ds = c2ds.get(clz);
- if(ds == null) {
- ds = new DataStore<Object>((Class<Object>) clz);
- c2ds.put(clz, ds);
- }
- return ds;
- }
- }
-
- @SuppressWarnings("unchecked")
- public static <T> DataStore<T> createInMemory(Class<T> clazz) {
- return (DataStore<T>) InMemoryDataStore.getInstance(clazz);
- }
-
- private DataStore(List<T> wrapStore, Class<T> clz) {
- dataStore = wrapStore;
- dataTypeClass = clz;
- }
-
- private DataStore(Class<T> clz) {
- this(new ArrayList<T>(), clz);
- }
-
- public Class<T> getDataTypeClass() {
- return dataTypeClass;
- }
-
- public T createInstance() {
- try {
- return dataTypeClass.newInstance();
- } catch (InstantiationException e) {
- throw new ODataRuntimeException("Unable to create instance of class '" + dataTypeClass + "'.", e);
- } catch (IllegalAccessException e) {
- throw new ODataRuntimeException("Unable to create instance of class '" + dataTypeClass + "'.", e);
- }
- }
-
- @EntityRead
- public T read(T obj) {
- List<Object> objKeys = getKeys(obj);
- for (T stored : dataStore) {
- if (objKeys.equals(getKeys(stored))) {
- return stored;
- }
- }
- return null;
- }
-
- @EntitySetRead
- public Collection<T> read() {
- return Collections.unmodifiableCollection(dataStore);
- }
-
- @EntityCreate
- public T create(T object) {
- createKeys(object);
- dataStore.add(object);
- return object;
- }
-
- @EntityUpdate
- public T update(T object) {
- T stored = read(object);
- dataStore.remove(stored);
- dataStore.add(object);
- return object;
- }
-
- @EntityDelete
- public T delete(T object) {
- T stored = read(object);
- if(stored != null) {
- dataStore.remove(stored);
- }
- return stored;
- }
-
- private List<Object> getKeys(T object) {
- Map<String, Object> keys = ANNOTATION_HELPER.getValueForAnnotatedFields(object, EdmKey.class);
-
- // XXX: list should be in a defined order -> better to create an 'Key' object which is comparable
- List<Object> keyList = new ArrayList(keys.values());
- return keyList;
- }
-
- private T createKeys(T object) {
- List<Field> fields = ANNOTATION_HELPER.getAnnotatedFields(object, EdmKey.class);
- Map<String, Object> fieldName2KeyValue = new HashMap<String, Object>();
-
- for (Field field : fields) {
- Object key = createKey(field);
- fieldName2KeyValue.put(ANNOTATION_HELPER.getCanonicalName(field), key);
- }
-
- ANNOTATION_HELPER.setValuesToAnnotatedFields(fieldName2KeyValue, object, EdmKey.class);
-
- return object;
- }
-
- private Object createKey(Field field) {
- Class<?> type = field.getType();
-
- if(type == String.class) {
- return String.valueOf(idCounter++);
- } else if(type == Integer.class || type == int.class) {
- return Integer.valueOf(idCounter++);
- } else if(type == Long.class || type == long.class) {
- return Long.valueOf(idCounter++);
- }
-
- throw new UnsupportedOperationException("Automated key generation for type '" + type
- + "' is not supported (caused on field '" + field + "').");
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/b7e7ee0d/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java
index b7aa89b..75a92a2 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java
@@ -446,7 +446,7 @@ public class AnnotationEdmProvider extends EdmProvider {
private Property createProperty(EdmProperty ep, Field field, String defaultNamespace) {
if(isAnnotatedEntity(field.getType())) {
- return createComplexProperty(ep, field, defaultNamespace);
+ return createComplexProperty(field, defaultNamespace);
} else {
return createSimpleProperty(ep, field);
}
@@ -455,10 +455,7 @@ public class AnnotationEdmProvider extends EdmProvider {
private Property createSimpleProperty(EdmProperty ep, Field field) {
SimpleProperty sp = new SimpleProperty();
- String entityName = ep.name();
- if (entityName.isEmpty()) {
- entityName = getCanonicalName(field);
- }
+ String entityName = ANNOTATION_HELPER.getPropertyName(field);
sp.setName(entityName);
//
EdmSimpleTypeKind type = ep.type();
@@ -470,13 +467,10 @@ public class AnnotationEdmProvider extends EdmProvider {
return sp;
}
- private Property createComplexProperty(EdmProperty ep, Field field, String defaultNamespace) {
+ private Property createComplexProperty(Field field, String defaultNamespace) {
ComplexProperty cp = new ComplexProperty();
// settings from property
- String entityName = ep.name();
- if (entityName.isEmpty()) {
- entityName = getCanonicalName(field);
- }
+ String entityName = ANNOTATION_HELPER.getPropertyName(field);
cp.setName(entityName);
// settings from related complex entity
@@ -492,10 +486,7 @@ public class AnnotationEdmProvider extends EdmProvider {
private NavigationProperty createNavigationProperty(String namespace, EdmNavigationProperty enp, Field field) {
NavigationProperty navProp = new NavigationProperty();
- String entityName = enp.name();
- if (entityName.isEmpty()) {
- entityName = getCanonicalName(field);
- }
+ String entityName = ANNOTATION_HELPER.getPropertyName(field);
navProp.setName(entityName);
//
NavigationEnd from = enp.from();
[44/52] Renamed project
Posted by mi...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/ResourceHelper.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/ResourceHelper.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/ResourceHelper.java
deleted file mode 100644
index 73d1218..0000000
--- a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/ResourceHelper.java
+++ /dev/null
@@ -1,64 +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.core.annotation.model;
-
-import java.awt.image.BufferedImage;
-import java.awt.image.WritableRaster;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import javax.imageio.ImageIO;
-
-/**
- *
- */
-public class ResourceHelper {
-
- public enum Format {BMP, JPEG, PNG, GIF};
-
- public static byte[] generateImage() {
- return generateImage(Format.PNG);
- }
-
- public static byte[] generateImage(Format format) {
- try {
- int width = 320;
- int height = 320;
- BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_BINARY);
- WritableRaster raster = image.getRaster();
-
- int mod = format.ordinal() + 2;
- for (int h = 0; h < height; h++) {
- for (int w = 0; w < width; w++) {
- if (((h / 32) + (w / 32)) % mod == 0) {
- raster.setSample(w, h, 0, 0);
- } else {
- raster.setSample(w, h, 0, 1);
- }
- }
- }
-
- ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
- ImageIO.write(image, format.name(), out);
- return out.toByteArray();
- } catch (IOException ex) {
- return new byte[0];
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Room.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Room.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Room.java
deleted file mode 100644
index 7c9e486..0000000
--- a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Room.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Copyright 2013 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * 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.core.annotation.model;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
-import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
-
-/**
- *
- */
-@EdmEntityType(name = "Room", namespace = ModelSharedConstants.NAMESPACE_1)
-@EdmEntitySet(name = "Rooms")
-public class Room extends RefBase {
-
- @EdmProperty
- private Integer seats;
- @EdmProperty
- private Integer version;
- @EdmNavigationProperty(name = "nr_Building", association = "BuildingRooms")
- private Building building;
- @EdmNavigationProperty(name = "nr_Employees")
- private List<Employee> employees = new ArrayList<Employee>();
-
- public Room(final int id, final String name) {
- super(id, name);
- }
-
- public void setSeats(final int seats) {
- this.seats = seats;
- }
-
- public int getSeats() {
- return seats;
- }
-
- public void setVersion(final int version) {
- this.version = version;
- }
-
- public int getVersion() {
- return version;
- }
-
- public void setBuilding(final Building building) {
- this.building = building;
- }
-
- public Building getBuilding() {
- return building;
- }
-
- public List<Employee> getEmployees() {
- return employees;
- }
-
- @Override
- public int hashCode() {
- return id;
- }
-
- @Override
- public boolean equals(final Object obj) {
- return this == obj
- || obj != null && getClass() == obj.getClass() && id == ((Room) obj).id;
- }
-
- @Override
- public String toString() {
- return "{\"Id\":\"" + id + "\",\"Name\":\"" + name + "\",\"Seats\":" + seats + ",\"Version\":" + version + "}";
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Team.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Team.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Team.java
deleted file mode 100644
index e9b296f..0000000
--- a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Team.java
+++ /dev/null
@@ -1,81 +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.core.annotation.model;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
-import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty.Multiplicity;
-import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
-import org.apache.olingo.odata2.api.annotation.edm.EdmType;
-
-/**
-*
-*/
-@EdmEntityType(name = "Team", namespace = ModelSharedConstants.NAMESPACE_1)
-@EdmEntitySet(name = "Teams")
-public class Team extends RefBase {
- @EdmProperty(type = EdmType.BOOLEAN)
- private Boolean isScrumTeam;
- @EdmNavigationProperty(name = "nt_Employees", association = "TeamEmployees", toMultiplicity = Multiplicity.MANY)
- private List<Employee> employees = new ArrayList<Employee>();
-
- public Team() {
- super(-1, null);
- }
-
- public Team(final int id, final String name) {
- super(id, name);
- }
-
- public Boolean isScrumTeam() {
- return isScrumTeam;
- }
-
- public void setScrumTeam(final Boolean isScrumTeam) {
- this.isScrumTeam = isScrumTeam;
- }
-
- public void addEmployee(Employee e) {
- this.employees.add(e);
- }
-
- public List<Employee> getEmployees() {
- return employees;
- }
-
- @Override
- public int hashCode() {
- return id;
- }
-
- @Override
- public boolean equals(final Object obj) {
- return this == obj
- || obj != null && getClass() == obj.getClass() && id == ((Team) obj).id;
- }
-
- @Override
- public String toString() {
- return "{\"Id\":\"" + id + "\",\"Name\":\"" + name + "\",\"IsScrumTeam\":" + isScrumTeam + "}";
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-edm-annotation/edm-annotation-webref/pom.xml
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/pom.xml b/odata2-edm-annotation/edm-annotation-webref/pom.xml
deleted file mode 100644
index 18ff957..0000000
--- a/odata2-edm-annotation/edm-annotation-webref/pom.xml
+++ /dev/null
@@ -1,120 +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>
-
- <artifactId>olingo-odata2-edm-annotation-webref-incubating</artifactId>
- <packaging>war</packaging>
- <name>${project.artifactId}</name>
-
- <parent>
- <groupId>org.apache.olingo</groupId>
- <artifactId>olingo-odata2-edm-annotation-incubating</artifactId>
- <version>1.1.0-SNAPSHOT</version>
- <relativePath>..</relativePath>
- </parent>
-
- <properties>
- <version.slf4j>1.7.1</version.slf4j>
- </properties>
-
- <build>
- <finalName>${project.artifactId}</finalName>
- <resources>
- <resource>
- <directory>src/main/version</directory>
- <filtering>true</filtering>
- <targetPath>../${project.build.finalName}/gen</targetPath>
- </resource>
- <resource>
- <directory>src/main/resources</directory>
- <filtering>true</filtering>
- </resource>
- <resource>
- <directory>target/maven-shared-archive-resources</directory>
- </resource>
- </resources>
-
- <plugins>
- <plugin>
- <groupId>com.sap.research</groupId>
- <artifactId>nwcloud-maven-plugin</artifactId>
- <version>1.0.0.RELEASE</version>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-deploy-plugin</artifactId>
- <configuration>
- <skip>true</skip>
- </configuration>
- </plugin>
- </plugins>
-
- </build>
-
- <dependencies>
- <dependency>
- <!-- required because of auto detection of web facet 2.5 -->
- <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>${cxf.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.olingo</groupId>
- <artifactId>olingo-odata2-api-incubating</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.olingo</groupId>
- <artifactId>olingo-odata2-core-incubating</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.olingo</groupId>
- <artifactId>olingo-odata2-edm-annotation-api-incubating</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.olingo</groupId>
- <artifactId>olingo-odata2-edm-annotation-core-incubating</artifactId>
- <version>${project.version}</version>
- </dependency>
-
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
- <version>${version.slf4j}</version>
- </dependency>
- </dependencies>
-
- <profiles>
- <profile>
- <id>dev</id>
-
- <build>
- <defaultGoal>cargo:run</defaultGoal>
-
- <plugins>
- <plugin>
- <groupId>org.codehaus.cargo</groupId>
- <artifactId>cargo-maven2-plugin</artifactId>
- <version>1.4.2</version>
- </plugin>
- </plugins>
- </build>
- </profile>
- </profiles>
-</project>
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Building.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Building.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Building.java
deleted file mode 100644
index 668ac86..0000000
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Building.java
+++ /dev/null
@@ -1,97 +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.ref.annotation.model;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
-import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
-import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty.Multiplicity;
-import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
-import org.apache.olingo.odata2.api.annotation.edm.EdmType;
-
-/**
- *
- */
-@EdmEntityType(name = "Building", namespace = ModelSharedConstants.NAMESPACE_1)
-@EdmEntitySet(name = "Buildings")
-public class Building {
- @EdmKey
- @EdmProperty(type = EdmType.INT32)
- private int id;
- @EdmProperty
- private String name;
- @EdmProperty(name = "Image", type = EdmType.BINARY)
- private byte[] image;
- @EdmNavigationProperty(name = "nb_Rooms", toType = Room.class,
- association = "BuildingRooms", toMultiplicity = Multiplicity.MANY)
- private List<Room> rooms = new ArrayList<Room>();
-
- public String getId() {
- return Integer.toString(id);
- }
-
- public void setName(final String name) {
- this.name = name;
- }
-
- public String getName() {
- return name;
- }
-
- public void setImage(final byte[] byteArray) {
- image = byteArray;
- }
-
- public byte[] getImage() {
- if (image == null) {
- return null;
- } else {
- return image.clone();
- }
- }
-
- public void addRoom(Room room) {
- rooms.add(room);
- }
-
- public List<Room> getRooms() {
- return rooms;
- }
-
- @Override
- public int hashCode() {
- return id;
- }
-
- @Override
- public boolean equals(final Object obj) {
- return this == obj
- || obj != null && getClass() == obj.getClass() && id == ((Building) obj).id;
- }
-
- @Override
- public String toString() {
- return "{\"Id\":\"" + id + "\",\"Name\":\"" + name + "\",\"Image\":\"" + Arrays.toString(image) + "\"}";
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/City.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/City.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/City.java
deleted file mode 100644
index a4d5a56..0000000
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/City.java
+++ /dev/null
@@ -1,61 +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.ref.annotation.model;
-
-import org.apache.olingo.odata2.api.annotation.edm.EdmComplexType;
-import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
-
-/**
- *
- */
-@EdmComplexType(name="c_City", namespace = ModelSharedConstants.NAMESPACE_1)
-public class City {
-
- @EdmProperty
- private String postalCode;
- @EdmProperty
- private String cityName;
-
- public City(final String postalCode, final String name) {
- this.postalCode = postalCode;
- cityName = name;
- }
-
- public void setPostalCode(final String postalCode) {
- this.postalCode = postalCode;
- }
-
- public String getPostalCode() {
- return postalCode;
- }
-
- public void setCityName(final String cityName) {
- this.cityName = cityName;
- }
-
- public String getCityName() {
- return cityName;
- }
-
- @Override
- public String toString() {
- return String.format("%s, %s", cityName, postalCode);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Employee.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Employee.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Employee.java
deleted file mode 100644
index 2204ee8..0000000
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Employee.java
+++ /dev/null
@@ -1,192 +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.ref.annotation.model;
-
-import java.text.DateFormat;
-import java.util.Calendar;
-
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.annotation.edm.EdmFacets;
-import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
-import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceContent;
-import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceMimeType;
-import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
-import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
-import org.apache.olingo.odata2.api.annotation.edm.EdmType;
-
-/**
- *
- */
-@EdmEntityType(name = "Employee", namespace = ModelSharedConstants.NAMESPACE_1)
-@EdmEntitySet(name = "Employees")
-public class Employee {
- @EdmKey
- @EdmProperty(name = "EmployeeId", type = EdmType.STRING)
- private String employeeId;
- @EdmProperty(name = "EmployeeName")
- private String employeeName;
- @EdmProperty
- private int age;
- @EdmNavigationProperty(name = "ne_Manager", association = "ManagerEmployees")
- private Manager manager;
- @EdmNavigationProperty(name = "ne_Team", association = "TeamEmployees")
- private Team team;
- @EdmNavigationProperty(name = "ne_Room")
- private Room room;
- @EdmMediaResourceMimeType
- private String imageType;
- @EdmMediaResourceContent
- private byte[] image;
- @EdmProperty(name = "ImageUrl")
- private String imageUrl;
- @EdmProperty(name = "EntryDate", type = EdmType.DATE_TIME,
- facets = @EdmFacets(nullable = true))
- private Calendar entryDate;
- @EdmProperty(name = "Location", facets = @EdmFacets(nullable = false))
- private Location location;
-
- public String getId() {
- return employeeId;
- }
-
- public void setEmployeeName(final String employeeName) {
- this.employeeName = employeeName;
- }
-
- public String getEmployeeName() {
- return employeeName;
- }
-
- public void setAge(final int age) {
- this.age = age;
- }
-
- public int getAge() {
- return age;
- }
-
- public void setManager(final Manager manager) {
- this.manager = manager;
- }
-
- public Manager getManager() {
- return manager;
- }
-
- public void setTeam(final Team team) {
- this.team = team;
- }
-
- public Team getTeam() {
- return team;
- }
-
- public void setRoom(final Room room) {
- this.room = room;
- }
-
- public Room getRoom() {
- return room;
- }
-
- public void setImageUri(final String imageUri) {
- imageUrl = imageUri;
- }
-
- public String getImageUri() {
- return imageUrl;
- }
-
- public void setLocation(final Location location) {
- this.location = location;
- }
-
- public Location getLocation() {
- return location;
- }
-
- public void setEntryDate(final Calendar date) {
- entryDate = date;
- }
-
- public Calendar getEntryDate() {
- return entryDate;
- }
-
- public void setImageType(final String imageType) {
- this.imageType = imageType;
- }
-
- public String getImageType() {
- return imageType;
- }
-
- public void setImage(final byte[] image) {
- this.image = image;
- }
-
- public void setImage(final String imageUrl) {
- image = loadImage(imageUrl);
- }
-
- private static byte[] loadImage(final String imageUrl) {
- return ResourceHelper.loadAsByte(imageUrl);
- }
-
- public byte[] getImage() {
- if (image == null) {
- return null;
- }
- return image.clone();
- }
-
- @Override
- public int hashCode() {
- if (employeeId == null) {
- return 0;
- }
- return employeeId.hashCode();
- }
-
- @Override
- public boolean equals(final Object obj) {
- return this == obj
- || obj != null && getClass() == obj.getClass() && employeeId == ((Employee) obj).employeeId;
- }
-
- @Override
- public String toString() {
- return "{\"EmployeeId\":\"" + employeeId + "\","
- + "\"EmployeeName\":\"" + employeeName + "\","
- + "\"ManagerId\":" + (manager == null ? "null" : "\"" + manager.getId() + "\"") + ","
- + "\"RoomId\":" + (room == null ? "null" : "\"" + room.getId() + "\"") + ","
- + "\"TeamId\":" + (team == null ? "null" : "\"" + team.getId() + "\"") + ","
- + "\"Location\":"
- + (location == null ? "null" :
- "{\"City\":" + (location.getCity() == null ? "null" :
- "{\"PostalCode\":\"" + location.getCity().getPostalCode() + "\","
- + "\"CityName\":\"" + location.getCity().getCityName() + "\"}") + ","
- + "\"Country\":\"" + location.getCountry() + "\"}") + ","
- + "\"Age\":" + age + ","
- + "\"EntryDate\":"
- + (entryDate == null ? "null" : "\"" + DateFormat.getInstance().format(entryDate.getTime()) + "\"") + ","
- + "\"ImageUrl\":\"" + imageUrl + "\"}";
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Location.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Location.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Location.java
deleted file mode 100644
index 9b0785c..0000000
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Location.java
+++ /dev/null
@@ -1,60 +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.ref.annotation.model;
-
-import org.apache.olingo.odata2.api.annotation.edm.EdmComplexType;
-import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
-
-/**
- *
- */
-@EdmComplexType(name = "c_Location", namespace = ModelSharedConstants.NAMESPACE_1)
-public class Location {
- @EdmProperty
- private String country;
- @EdmProperty
- private City city;
-
- public Location(final String country, final String postalCode, final String cityName) {
- this.country = country;
- city = new City(postalCode, cityName);
- }
-
- public void setCountry(final String country) {
- this.country = country;
- }
-
- public String getCountry() {
- return country;
- }
-
- public void setCity(final City city) {
- this.city = city;
- }
-
- public City getCity() {
- return city;
- }
-
- @Override
- public String toString() {
- return String.format("%s, %s", country, city.toString());
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Manager.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Manager.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Manager.java
deleted file mode 100644
index 57e6d78..0000000
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Manager.java
+++ /dev/null
@@ -1,43 +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.ref.annotation.model;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
-import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty.Multiplicity;
-
-/**
- *
- */
-@EdmEntityType(name = "Manager", namespace = ModelSharedConstants.NAMESPACE_1)
-@EdmEntitySet(name = "Managers")
-public class Manager extends Employee {
-
- @EdmNavigationProperty(name = "nm_Employees", association = "ManagerEmployees",
- toMultiplicity = Multiplicity.MANY)
- private List<Employee> employees = new ArrayList<Employee>();
-
- public List<Employee> getEmployees() {
- return employees;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ModelSharedConstants.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ModelSharedConstants.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ModelSharedConstants.java
deleted file mode 100644
index ab17fbb..0000000
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ModelSharedConstants.java
+++ /dev/null
@@ -1,25 +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.ref.annotation.model;
-
-public interface ModelSharedConstants {
-
- String NAMESPACE_1 = "RefScenario";
- String CONTAINER_1 = "Container1";
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Photo.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Photo.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Photo.java
deleted file mode 100644
index 52971cd..0000000
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Photo.java
+++ /dev/null
@@ -1,128 +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.ref.annotation.model;
-
-import java.util.Arrays;
-
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
-import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceContent;
-import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceMimeType;
-import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceSource;
-import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
-import org.apache.olingo.odata2.api.annotation.edm.EdmType;
-
-/**
- *
- */
-@EdmEntityType(name = "Photo", namespace = ModelSharedConstants.NAMESPACE_1)
-@EdmEntitySet(name = "Photos")
-public class Photo {
- @EdmKey
- @EdmProperty
- private String name;
- @EdmKey
- @EdmProperty
- private String type;
- @EdmProperty
- @EdmMediaResourceMimeType
- private String mimeType;
- @EdmProperty
- @EdmMediaResourceSource
- private String imageUrl = "http://localhost/someResource.png";
- @EdmProperty(type = EdmType.BINARY)
- @EdmMediaResourceContent
- private byte[] image = ResourceHelper.generateImage();
-
- public String getName() {
- return name;
- }
-
- public void setName(final String name) {
- this.name = name;
- }
-
- public String getType() {
- return type;
- }
-
- public void setType(final String type) {
- this.type = type;
- }
-
- public String getImageUri() {
- return imageUrl;
- }
-
- public void setImageUri(final String uri) {
- imageUrl = uri;
- }
-
- public byte[] getImage() {
- return image.clone();
- }
-
- public void setImage(final byte[] image) {
- this.image = image;
- }
-
- public String getImageType() {
- return mimeType;
- }
-
- public void setImageType(final String imageType) {
- this.mimeType = imageType;
- }
-
- @Override
- public int hashCode() {
- int hash = 5;
- hash = 83 * hash + (this.name != null ? this.name.hashCode() : 0);
- hash = 83 * hash + (this.type != null ? this.type.hashCode() : 0);
- return hash;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- final Photo other = (Photo) obj;
- if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) {
- return false;
- }
- if ((this.type == null) ? (other.type != null) : !this.type.equals(other.type)) {
- return false;
- }
- return true;
- }
-
- @Override
- public String toString() {
- return "{\"Name\":\"" + name + "\","
- + "\"Type\":\"" + type + "\","
- + "\"ImageUrl\":\"" + imageUrl + "\","
- + "\"Image\":\"" + Arrays.toString(image) + "\","
- + "\"MimeType\":\"" + mimeType + "\"";
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/RefBase.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/RefBase.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/RefBase.java
deleted file mode 100644
index 727b8c3..0000000
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/RefBase.java
+++ /dev/null
@@ -1,78 +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.ref.annotation.model;
-
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
-import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
-import org.apache.olingo.odata2.api.annotation.edm.EdmType;
-
-/**
- *
- */
-@EdmEntityType(name="Base", namespace=ModelSharedConstants.NAMESPACE_1)
-public abstract class RefBase {
- @EdmProperty(name="Name")
- protected String name;
- @EdmProperty(name="Id", type = EdmType.STRING)
- @EdmKey
- protected String id;
-
- public String getName() {
- return name;
- }
-
- public String getId() {
- return id;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public void setId(int id) {
- this.id = String.valueOf(id);
- }
-
- @Override
- public int hashCode() {
- if(id == null) {
- return -1;
- }
- return id.hashCode();
- }
-
- @Override
- public boolean equals(Object obj) {
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- final RefBase other = (RefBase) obj;
- if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) {
- return false;
- }
- if ((this.id == null) ? (other.id != null) : !this.id.equals(other.id)) {
- return false;
- }
- return true;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ResourceHelper.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ResourceHelper.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ResourceHelper.java
deleted file mode 100644
index 3d2bb88..0000000
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ResourceHelper.java
+++ /dev/null
@@ -1,93 +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.ref.annotation.model;
-
-import java.awt.image.BufferedImage;
-import java.awt.image.WritableRaster;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import javax.imageio.ImageIO;
-
-/**
- *
- */
-public class ResourceHelper {
-
- public static byte[] loadAsByte(String resource) {
- return load(resource, new byte[0]);
- }
-
- public static byte[] load(String resource, byte[] defaultResult) {
- InputStream instream = null;
- try {
- instream = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource);
- if (instream == null) {
- return defaultResult;
- }
- ByteArrayOutputStream stream = new ByteArrayOutputStream();
- int b = 0;
- while ((b = instream.read()) != -1) {
- stream.write(b);
- }
-
- return stream.toByteArray();
- } catch (IOException e) {
- throw new RuntimeException(e);
- } finally {
- if(instream != null) {
- try {
- instream.close();
- } catch (IOException ex) { }
- }
- }
- }
-
- public enum Format {BMP, JPEG, PNG, GIF};
-
- public static byte[] generateImage() {
- return generateImage(Format.PNG);
- }
-
- public static byte[] generateImage(Format format) {
- try {
- int width = 320;
- int height = 320;
- BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_BINARY);
- WritableRaster raster = image.getRaster();
-
- int mod = format.ordinal() + 2;
- for (int h = 0; h < height; h++) {
- for (int w = 0; w < width; w++) {
- if (((h / 32) + (w / 32)) % mod == 0) {
- raster.setSample(w, h, 0, 0);
- } else {
- raster.setSample(w, h, 0, 1);
- }
- }
- }
-
- ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
- ImageIO.write(image, format.name(), out);
- return out.toByteArray();
- } catch (IOException ex) {
- return new byte[0];
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Room.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Room.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Room.java
deleted file mode 100644
index 2d9f48e..0000000
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Room.java
+++ /dev/null
@@ -1,88 +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.ref.annotation.model;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
-import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
-
-/**
- *
- */
-@EdmEntityType(name = "Room", namespace = ModelSharedConstants.NAMESPACE_1)
-@EdmEntitySet(name = "Rooms")
-public class Room extends RefBase {
-
- @EdmProperty
- private Integer seats;
- @EdmProperty
- private Integer version;
- @EdmNavigationProperty(name = "nr_Building", association = "BuildingRooms")
- private Building building;
- @EdmNavigationProperty(name = "nr_Employees")
- private List<Employee> employees = new ArrayList<Employee>();
-
- public void setSeats(final int seats) {
- this.seats = seats;
- }
-
- public int getSeats() {
- return seats;
- }
-
- public void setVersion(final int version) {
- this.version = version;
- }
-
- public int getVersion() {
- return version;
- }
-
- public void setBuilding(final Building building) {
- this.building = building;
- }
-
- public Building getBuilding() {
- return building;
- }
-
- public List<Employee> getEmployees() {
- return employees;
- }
-
- @Override
- public int hashCode() {
- return super.hashCode();
- }
-
- @Override
- public boolean equals(final Object obj) {
- return this == obj
- || obj != null && getClass() == obj.getClass() && id == ((Room) obj).id;
- }
-
- @Override
- public String toString() {
- return "{\"Id\":\"" + id + "\",\"Name\":\"" + name + "\",\"Seats\":" + seats + ",\"Version\":" + version + "}";
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Team.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Team.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Team.java
deleted file mode 100644
index 50d2ad2..0000000
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Team.java
+++ /dev/null
@@ -1,73 +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.ref.annotation.model;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
-import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty.Multiplicity;
-import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
-import org.apache.olingo.odata2.api.annotation.edm.EdmType;
-
-/**
-*
-*/
-@EdmEntityType(name = "Team", namespace = ModelSharedConstants.NAMESPACE_1)
-@EdmEntitySet(name = "Teams")
-public class Team extends RefBase {
- @EdmProperty(type = EdmType.BOOLEAN)
- private Boolean isScrumTeam;
- @EdmNavigationProperty(name = "nt_Employees", association = "TeamEmployees", toMultiplicity = Multiplicity.MANY)
- private List<Employee> employees = new ArrayList<Employee>();
-
- public Boolean isScrumTeam() {
- return isScrumTeam;
- }
-
- public void setScrumTeam(final Boolean isScrumTeam) {
- this.isScrumTeam = isScrumTeam;
- }
-
- public void addEmployee(Employee e) {
- this.employees.add(e);
- }
-
- public List<Employee> getEmployees() {
- return employees;
- }
-
- @Override
- public int hashCode() {
- return super.hashCode();
- }
-
- @Override
- public boolean equals(final Object obj) {
- return this == obj
- || obj != null && getClass() == obj.getClass() && id == ((Team) obj).id;
- }
-
- @Override
- public String toString() {
- return "{\"Id\":\"" + id + "\",\"Name\":\"" + name + "\",\"IsScrumTeam\":" + isScrumTeam + "}";
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/processor/AnnotationPocServiceFactory.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/processor/AnnotationPocServiceFactory.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/processor/AnnotationPocServiceFactory.java
deleted file mode 100644
index 3870119..0000000
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/processor/AnnotationPocServiceFactory.java
+++ /dev/null
@@ -1,202 +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.ref.annotation.processor;
-
-import java.util.Calendar;
-
-import org.apache.olingo.odata2.api.ODataCallback;
-import org.apache.olingo.odata2.api.ODataDebugCallback;
-import org.apache.olingo.odata2.api.ODataService;
-import org.apache.olingo.odata2.api.ODataServiceFactory;
-import org.apache.olingo.odata2.api.commons.HttpStatusCodes;
-import org.apache.olingo.odata2.api.ep.EntityProvider;
-import org.apache.olingo.odata2.api.exception.ODataApplicationException;
-import org.apache.olingo.odata2.api.exception.ODataException;
-import org.apache.olingo.odata2.api.processor.ODataContext;
-import org.apache.olingo.odata2.api.processor.ODataErrorCallback;
-import org.apache.olingo.odata2.api.processor.ODataErrorContext;
-import org.apache.olingo.odata2.api.processor.ODataResponse;
-import org.apache.olingo.odata2.core.annotation.data.AnnotationInMemoryDs;
-import org.apache.olingo.odata2.core.annotation.data.AnnotationValueAccess;
-import org.apache.olingo.odata2.core.annotation.data.DataStore;
-import org.apache.olingo.odata2.core.annotation.edm.AnnotationEdmProvider;
-import org.apache.olingo.odata2.core.annotation.processor.ListsProcessor;
-import org.apache.olingo.odata2.ref.annotation.model.Building;
-import org.apache.olingo.odata2.ref.annotation.model.Employee;
-import org.apache.olingo.odata2.ref.annotation.model.Location;
-import org.apache.olingo.odata2.ref.annotation.model.Manager;
-import org.apache.olingo.odata2.ref.annotation.model.Photo;
-import org.apache.olingo.odata2.ref.annotation.model.ResourceHelper;
-import org.apache.olingo.odata2.ref.annotation.model.Room;
-import org.apache.olingo.odata2.ref.annotation.model.Team;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- *
- */
-public class AnnotationPocServiceFactory extends ODataServiceFactory {
-
- private static boolean isInitialized = false;
-
- @Override
- public ODataService createService(final ODataContext context) throws ODataException {
-
- String modelPackage = "org.apache.olingo.odata2.ref.annotation.model";
- AnnotationEdmProvider annotationEdmProvider = new AnnotationEdmProvider(modelPackage);
- AnnotationInMemoryDs annotationScenarioDs = new AnnotationInMemoryDs(modelPackage);
- AnnotationValueAccess annotationValueAccess = new AnnotationValueAccess();
-
- if (!isInitialized) {
- initializeSampleData(annotationScenarioDs);
- isInitialized = true;
- }
-
- // Edm via Annotations and ListProcessor via AnnotationDS with AnnotationsValueAccess
- return createODataSingleProcessorService(annotationEdmProvider,
- new ListsProcessor(annotationScenarioDs, annotationValueAccess));
- }
-
- @SuppressWarnings("unchecked")
- @Override
- public <T extends ODataCallback> T getCallback(final Class<? extends ODataCallback> callbackInterface) {
- return (T) (callbackInterface.isAssignableFrom(ScenarioErrorCallback.class)
- ? new ScenarioErrorCallback() : callbackInterface.isAssignableFrom(ODataDebugCallback.class)
- ? new ScenarioDebugCallback() : super.getCallback(callbackInterface));
- }
-
- /*
- * Helper classes and methods
- */
-
- /**
- *
- */
- private final class ScenarioDebugCallback implements ODataDebugCallback {
-
- @Override
- public boolean isDebugEnabled() {
- return true;
- }
- }
-
- private class ScenarioErrorCallback implements ODataErrorCallback {
-
- private final Logger LOG = LoggerFactory.getLogger(ScenarioErrorCallback.class);
-
- @Override
- public ODataResponse handleError(final ODataErrorContext context) throws ODataApplicationException {
- if (context.getHttpStatus() == HttpStatusCodes.INTERNAL_SERVER_ERROR) {
- LOG.error("Internal Server Error", context.getException());
- }
-
- return EntityProvider.writeErrorDocument(context);
- }
-
- }
-
- private void initializeSampleData(AnnotationInMemoryDs dataSource) throws ODataApplicationException {
- DataStore<Team> teamDs = dataSource.getDataStore(Team.class);
- teamDs.create(createTeam("Team Alpha", true));
- teamDs.create(createTeam("Team Beta", false));
- teamDs.create(createTeam("Team Gamma", false));
- teamDs.create(createTeam("Team Omega", true));
- teamDs.create(createTeam("Team Zeta", true));
-
- DataStore<Building> buildingsDs = dataSource.getDataStore(Building.class);
- Building redBuilding = createBuilding("Red Building");
- buildingsDs.create(redBuilding);
- Building greenBuilding = createBuilding("Green Building");
- buildingsDs.create(greenBuilding);
- Building blueBuilding = createBuilding("Blue Building");
- buildingsDs.create(blueBuilding);
- Building yellowBuilding = createBuilding("Yellow Building");
- buildingsDs.create(yellowBuilding);
-
- DataStore<Photo> photoDs = dataSource.getDataStore(Photo.class);
- photoDs.create(createPhoto("Small picture", ResourceHelper.Format.GIF));
- photoDs.create(createPhoto("Medium picture", ResourceHelper.Format.PNG));
- photoDs.create(createPhoto("Big picture", ResourceHelper.Format.JPEG));
- photoDs.create(createPhoto("Huge picture", ResourceHelper.Format.BMP));
-
- DataStore<Room> roomDs = dataSource.getDataStore(Room.class);
- roomDs.create(createRoom("Tiny red room", 5, 1, redBuilding));
- roomDs.create(createRoom("Small red room", 20, 1, redBuilding));
- roomDs.create(createRoom("Small green room", 20, 1, greenBuilding));
- roomDs.create(createRoom("Big blue room", 40, 1, blueBuilding));
- roomDs.create(createRoom("Huge blue room", 120, 1, blueBuilding));
- roomDs.create(createRoom("Huge yellow room", 120, 1, yellowBuilding));
-
- DataStore<Employee> employeeDataStore = dataSource.getDataStore(Employee.class);
- employeeDataStore.create(createEmployee("first Employee",
- new Location("Norge", "8392", "Ä"), 42, null,
- photoDs.read().iterator().next().getImage(), photoDs.read().iterator().next().getImageType(),
- "http://localhost/image/first.png",
- null, teamDs.read().iterator().next(), roomDs.read().iterator().next()));
- }
-
- private Employee createEmployee(final String name,
- Location location, final int age, final Calendar date,
- final byte[] image, final String imageType, final String imageUrl,
- Manager manager, Team team, Room room) {
- Employee employee = new Employee();
- employee.setEmployeeName(name);
- employee.setLocation(location);
- employee.setAge(age);
- employee.setEntryDate(date);
- employee.setImage(image);
- employee.setImageType(imageType);
- employee.setImageUri(imageUrl);
- employee.setManager(manager);
- employee.setTeam(team);
- employee.setRoom(room);
- return employee;
- }
-
- private Team createTeam(String teamName, boolean isScrumTeam) {
- Team team = new Team();
- team.setName(teamName);
- team.setScrumTeam(isScrumTeam);
- return team;
- }
-
- private Building createBuilding(String buildingName) {
- Building b = new Building();
- b.setName(buildingName);
- return b;
- }
-
- private Photo createPhoto(String name, ResourceHelper.Format format) {
- Photo p = new Photo();
- p.setName(name);
- p.setImageUri("http://localhost/image/" + name);
- p.setType(format.name());
- p.setImageType("image/" + format.name().toLowerCase());
- p.setImage(ResourceHelper.generateImage(format));
- return p;
- }
-
- private Room createRoom(String name, int seats, int version, Building building) {
- Room r = new Room();
- r.setName(name);
- r.setSeats(seats);
- r.setVersion(version);
- r.setBuilding(building);
-
- building.addRoom(r);
-
- return r;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-edm-annotation/edm-annotation-webref/src/main/resources/log4j.xml
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/resources/log4j.xml b/odata2-edm-annotation/edm-annotation-webref/src/main/resources/log4j.xml
deleted file mode 100644
index 90a4706..0000000
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/resources/log4j.xml
+++ /dev/null
@@ -1,39 +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>
-
- <logger name="org.apache.olingo.odata2.ref" additivity="false">
- <level value="trace" />
- <appender-ref ref="console" />
- </logger>
-
- <root>
- <priority value="error" />
- <appender-ref ref="console" />
- </root>
-</log4j:configuration>
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-edm-annotation/edm-annotation-webref/src/main/version/version.html
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/version/version.html b/odata2-edm-annotation/edm-annotation-webref/src/main/version/version.html
deleted file mode 100644
index 6d76d0b..0000000
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/version/version.html
+++ /dev/null
@@ -1,27 +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.
-
--->
-
-<table border="1">
-<tr><td>name</td><td>${name}</td></tr>
-<tr><td>version</td><td>${version}</td></tr>
-<tr><td>timestamp</td><td>${timestamp}</td></tr>
-<tr><td>project.build.finalName</td><td>${project.build.finalName}</td></tr>
-</table>
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-edm-annotation/edm-annotation-webref/src/main/webapp/WEB-INF/web.xml
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/webapp/WEB-INF/web.xml b/odata2-edm-annotation/edm-annotation-webref/src/main/webapp/WEB-INF/web.xml
deleted file mode 100644
index 5f7264c..0000000
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/webapp/WEB-INF/web.xml
+++ /dev/null
@@ -1,48 +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.ref.annotations.web</display-name>
- <welcome-file-list>
- <welcome-file>index.jsp</welcome-file>
- </welcome-file-list>
-
- <servlet>
- <servlet-name>ReferenceScenarioServlet</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.ref.annotation.processor.AnnotationPocServiceFactory</param-value>
- </init-param>
- <load-on-startup>1</load-on-startup>
- </servlet>
-
- <servlet-mapping>
- <servlet-name>ReferenceScenarioServlet</servlet-name>
- <url-pattern>/ReferenceScenario.svc/*</url-pattern>
- </servlet-mapping>
-
-</web-app>
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-edm-annotation/edm-annotation-webref/src/main/webapp/index.jsp
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/webapp/index.jsp b/odata2-edm-annotation/edm-annotation-webref/src/main/webapp/index.jsp
deleted file mode 100644
index 49cf364..0000000
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/webapp/index.jsp
+++ /dev/null
@@ -1,116 +0,0 @@
-<%@ page language="java" contentType="text/html; UTF-8" pageEncoding="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 html>
-<html>
-<head>
-<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
-<title>Apache Olingo - OData2 Library</title>
-<style type="text/css">
-body { font-family: Arial, sans-serif; font-size: 13px; line-height: 18px;
- color: blue; background-color: #ffffff; }
-a { color: blue; text-decoration: none; }
-a:focus { outline: thin dotted #4076cb; outline-offset: -1px; }
-a:hover, a:active { outline: 0; }
-a:hover { color: #404a7e; text-decoration: underline; }
-h1, h2, h3, h4, h5, h6 { margin: 9px 0; font-family: inherit; font-weight: bold;
- line-height: 1; color: blue; }
-h1 { font-size: 36px; line-height: 40px; }
-h2 { font-size: 30px; line-height: 40px; }
-h3 { font-size: 24px; line-height: 40px; }
-h4 { font-size: 18px; line-height: 20px; }
-h5 { font-size: 14px; line-height: 20px; }
-h6 { font-size: 12px; line-height: 20px; }
-.logo { float: right; }
-ul { padding: 0; margin: 0 0 9px 25px; }
-ul ul { margin-bottom: 0; }
-li { line-height: 18px; }
-hr { margin: 18px 0;
- border: 0; border-top: 1px solid #cccccc; border-bottom: 1px solid #ffffff; }
-table { border-collapse: collapse; border-spacing: 10px; }
-th, td { border: 1px solid; padding: 20px; }
-.code { font-family: "Courier New", monospace; font-size: 13px; line-height: 18px; }
-</style>
-</head>
-<body>
- <h1>Apache Olingo - OData2 Library</h1>
- <hr />
- <h2>Reference Scenario</h2>
- <table>
- <tr>
- <td valign="top">
- <h3>Service Document and Metadata</h3>
- <ul>
- <li><a href="ReferenceScenario.svc?_wadl" target="_blank">wadl</a></li>
- <li><a href="ReferenceScenario.svc/" target="_blank">service
- document</a></li>
- <li><a href="ReferenceScenario.svc/$metadata" target="_blank">metadata</a></li>
- </ul>
- <h3>EntitySets</h3>
- <ul>
- <li><a href="ReferenceScenario.svc/Employees" target="_blank">Employees</a></li>
- <li><a href="ReferenceScenario.svc/Managers" target="_blank">Managers</a></li>
- <li><a href="ReferenceScenario.svc/Buildings" target="_blank">Buildings</a></li>
- <li><a href="ReferenceScenario.svc/Buildings/?$expand=nb_Rooms"
- target="_blank">Buildings/?$expand=nb_Rooms</a></li>
- <li><a href="ReferenceScenario.svc/Rooms" target="_blank">Rooms</a></li>
- <li><a href="ReferenceScenario.svc/Rooms/?$orderby=Name" target="_blank">Rooms/?$orderby=Name</a></li>
- <li><a href="ReferenceScenario.svc/Photos" target="_blank">Photos</a></li>
- <li><a href="ReferenceScenario.svc/Photos/?$filter=Type%20eq%20'PNG'"
- target="_blank">Photos/?$filter=Type eq 'PNG'</a></li>
- </ul>
- <h3>Entities</h3>
- <ul>
- <li><a href="ReferenceScenario.svc/Employees('1')" target="_blank">Employees('1')</a></li>
- <li><a href="ReferenceScenario.svc/Managers('1')" target="_blank">Managers('1')</a></li>
- <li><a href="ReferenceScenario.svc/Buildings(1)" target="_blank">Buildings(1)</a></li>
- <li><a href="ReferenceScenario.svc/Buildings(1)/nb_Rooms" target="_blank">Buildings(1)/nb_Rooms</a></li>
- <li><a href="ReferenceScenario.svc/Rooms('1')" target="_blank">Rooms('1')</a></li>
- <li><a href="ReferenceScenario.svc/Rooms('1')/nr_Building" target="_blank">Rooms('1')/nr_Building</a></li>
- <li><a href="ReferenceScenario.svc/Photos(Name='Small%20picture',Type='GIF')"
- target="_blank">Photos(Name='Small%20picture',Type='GIF')</a></li>
- <li><a href="ReferenceScenario.svc/Photos(Name='Big%20picture',Type='JPEG')/$value"
- target="_blank">Photos(Name='Big%20picture',Type='JPEG')/$value</a></li>
- </ul>
- </td>
- <td valign="top">
-
- </td>
- <td valign="bottom">
- <div class="code">
- <%
- String version = "gen/version.html";
- %>
- <%
- try {
- %>
- <jsp:include page='<%=version%>' />
- <%
- } catch (Exception e) {
- %>
- <p>IDE Build</p>
- <%
- }
- %>
- </div>
- </td>
- </tr>
- </table>
-</body>
-</html>
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-edm-annotation/pom.xml
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/pom.xml b/odata2-edm-annotation/pom.xml
deleted file mode 100644
index 436576f..0000000
--- a/odata2-edm-annotation/pom.xml
+++ /dev/null
@@ -1,30 +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-edm-annotation-incubating</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>edm-annotation-api</module>
- <module>edm-annotation-core</module>
- <module>edm-annotation-webref</module>
- </modules>
-</project>
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-lib/odata-ref/pom.xml
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-ref/pom.xml b/odata2-lib/odata-ref/pom.xml
index 7b71a66..27cc47c 100644
--- a/odata2-lib/odata-ref/pom.xml
+++ b/odata2-lib/odata-ref/pom.xml
@@ -93,7 +93,7 @@
</dependency>
<dependency>
<groupId>org.apache.olingo</groupId>
- <artifactId>olingo-odata2-edm-annotation-core-incubating</artifactId>
+ <artifactId>olingo-odata2-annotation-processor-core-incubating</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index a195e82..19c21a0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -75,7 +75,7 @@
<modules>
<module>odata2-lib</module>
<module>odata2-processor-jpa</module>
- <module>odata2-edm-annotation</module>
+ <module>odata2-annotation-processor</module>
<module>odata2-dist</module>
<module>odata2-sample</module>
</modules>
[07/52] git commit: OLINGO-30 Use EdmMapping instead of write
properties
Posted by mi...@apache.org.
OLINGO-30 Use EdmMapping instead of write properties
Deleted new fields at the write properties and used edm mapping object
instead.
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/5ab0c609
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/5ab0c609
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/5ab0c609
Branch: refs/heads/master
Commit: 5ab0c609524cdacc6330bc6226bd22920ecab338
Parents: cf3f45b
Author: Christian Amend <ch...@apache.org>
Authored: Mon Oct 14 16:43:12 2013 +0200
Committer: Michael Bolz <mi...@sap.com>
Committed: Tue Oct 15 21:58:17 2013 +0200
----------------------------------------------------------------------
.../olingo/odata2/api/edm/EdmMapping.java | 13 ++
.../olingo/odata2/api/edm/provider/Mapping.java | 31 +++++
.../api/ep/EntityProviderWriteProperties.java | 39 +-----
.../ep/producer/AtomEntryEntityProducer.java | 59 +++++----
.../ep/producer/JsonEntryEntityProducer.java | 32 +++--
.../ep/ODataEntityProviderPropertiesTest.java | 14 +-
.../core/ep/producer/AtomEntryProducerTest.java | 84 +++++++-----
.../producer/JsonEntryEntityProducerTest.java | 131 +++++++++++++------
.../ep/producer/JsonFunctionImportTest.java | 2 +-
.../odata2/ref/processor/ListsProcessor.java | 20 +--
10 files changed, 252 insertions(+), 173 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/5ab0c609/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/edm/EdmMapping.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/edm/EdmMapping.java b/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/edm/EdmMapping.java
index 750b407..c810fca 100644
--- a/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/edm/EdmMapping.java
+++ b/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/edm/EdmMapping.java
@@ -37,9 +37,22 @@ public interface EdmMapping {
*
* @return mapping name as String
*/
+ @Deprecated
String getMimeType();
/**
+ * Gets the key under which the resource source value can be found in the data map.
+ * @return the key of the media resource source
+ */
+ String getMediaResourceSourceKey();
+
+ /**
+ * Gets the key under which the resource mime type can be found in the data map.
+ * @return the key of the media resource type
+ */
+ String getMediaResourceMimeTypeKey();
+
+ /**
* Get the set object for this mapping
*
* @return {@link Object} object
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/5ab0c609/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/edm/provider/Mapping.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/edm/provider/Mapping.java b/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/edm/provider/Mapping.java
index f7f0f00..4cdb6de 100644
--- a/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/edm/provider/Mapping.java
+++ b/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/edm/provider/Mapping.java
@@ -29,6 +29,8 @@ public class Mapping implements EdmMapping {
private String value;
private String mimeType;
private Object object;
+ private String mediaResourceSourceKey;
+ private String mediaResourceMimeTypeKey;
@Override
public String getInternalName() {
@@ -44,6 +46,16 @@ public class Mapping implements EdmMapping {
public Object getObject() {
return object;
}
+
+ @Override
+ public String getMediaResourceSourceKey() {
+ return mediaResourceSourceKey;
+ }
+
+ @Override
+ public String getMediaResourceMimeTypeKey() {
+ return mediaResourceMimeTypeKey;
+ }
/**
* Sets the value for this {@link Mapping}.
@@ -60,6 +72,7 @@ public class Mapping implements EdmMapping {
* @param mimeType
* @return {@link Mapping} for method chaining
*/
+ @Deprecated
public Mapping setMimeType(final String mimeType) {
this.mimeType = mimeType;
return this;
@@ -74,4 +87,22 @@ public class Mapping implements EdmMapping {
this.object = object;
return this;
}
+
+ /**
+ * Sets the key for the resource source key which is used for the lookup in the data map
+ * @param mediaResourceSourceKey under which the source can be found in the data map
+ */
+ public void setMediaResourceSourceKey(String mediaResourceSourceKey) {
+ this.mediaResourceSourceKey = mediaResourceSourceKey;
+ }
+
+ /**
+ * Sets the key for the resource mime type key which is used for the lookup in the data map
+ * @param mediaResourceMimeTypeKey under which the mime type can be found in the data map
+ */
+ public void setMediaResourceMimeTypeKey(String mediaResourceMimeTypeKey) {
+ this.mediaResourceMimeTypeKey = mediaResourceMimeTypeKey;
+ }
+
+
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/5ab0c609/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/ep/EntityProviderWriteProperties.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/ep/EntityProviderWriteProperties.java b/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/ep/EntityProviderWriteProperties.java
index 227e1ef..2a7e978 100644
--- a/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/ep/EntityProviderWriteProperties.java
+++ b/odata2-lib/odata-api/src/main/java/org/apache/olingo/odata2/api/ep/EntityProviderWriteProperties.java
@@ -34,6 +34,7 @@ import org.apache.olingo.odata2.api.uri.ExpandSelectTreeNode;
public class EntityProviderWriteProperties {
private URI serviceRoot;
+ @Deprecated
private String mediaResourceMimeType;
private InlineCount inlineCountType;
private Integer inlineCount;
@@ -41,8 +42,6 @@ public class EntityProviderWriteProperties {
private ExpandSelectTreeNode expandSelectTree;
private Map<String, ODataCallback> callbacks = Collections.emptyMap();
private URI selfLink;
- private String mediaResourceSourceKey;
- private String mediaResourceTypeKey;
private EntityProviderWriteProperties() {}
@@ -66,6 +65,7 @@ public class EntityProviderWriteProperties {
* Gets the MIME type of the media resource.
* @return the MIME type of the media resource
*/
+ @Deprecated
public final String getMediaResourceMimeType() {
return mediaResourceMimeType;
}
@@ -106,22 +106,6 @@ public class EntityProviderWriteProperties {
public final String getNextLink() {
return nextLink;
}
-
- /**
- * Gets the key under which the resource source value can be found in the data map.
- * @return the key of the media resource source
- */
- public final String getMediaResourceSourceKey() {
- return mediaResourceSourceKey;
- }
-
- /**
- * Gets the key under which the resource mime type can be found in the data map.
- * @return the key of the media resource type
- */
- public final String getMediaResourceTypeKey() {
- return mediaResourceTypeKey;
- }
public static ODataEntityProviderPropertiesBuilder serviceRoot(final URI serviceRoot) {
return new ODataEntityProviderPropertiesBuilder().serviceRoot(serviceRoot);
@@ -134,28 +118,13 @@ public class EntityProviderWriteProperties {
/**
* @param mediaResourceMimeType the mediaResourceMimeType to set
*/
+ @Deprecated
public final ODataEntityProviderPropertiesBuilder mediaResourceMimeType(final String mediaResourceMimeType) {
properties.mediaResourceMimeType = mediaResourceMimeType;
return this;
}
/**
- * @param mediaResourceSourceKey the mediaResourceSourceKey to set
- */
- public final ODataEntityProviderPropertiesBuilder mediaResourceSourceKey(final String mediaResourceSourceKey) {
- properties.mediaResourceSourceKey = mediaResourceSourceKey;
- return this;
- }
-
- /**
- * @param mediaResourceTypeKey the mediaResourceTypeKey to set
- */
- public ODataEntityProviderPropertiesBuilder mediaResourceTypeKey(String mediaResourceTypeKey) {
- properties.mediaResourceTypeKey = mediaResourceTypeKey;
- return this;
- }
-
- /**
* @param inlineCountType the inlineCountType to set
*/
public final ODataEntityProviderPropertiesBuilder inlineCountType(final InlineCount inlineCountType) {
@@ -219,8 +188,6 @@ public class EntityProviderWriteProperties {
public ODataEntityProviderPropertiesBuilder fromProperties(final EntityProviderWriteProperties properties) {
this.properties.mediaResourceMimeType = properties.getMediaResourceMimeType();
- this.properties.mediaResourceTypeKey = properties.getMediaResourceTypeKey();
- this.properties.mediaResourceSourceKey = properties.getMediaResourceSourceKey();
this.properties.inlineCountType = properties.getInlineCountType();
this.properties.inlineCount = properties.getInlineCount();
this.properties.nextLink = properties.getNextLink();
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/5ab0c609/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/producer/AtomEntryEntityProducer.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/producer/AtomEntryEntityProducer.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/producer/AtomEntryEntityProducer.java
index 4da4ab1..1b24a9a 100644
--- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/producer/AtomEntryEntityProducer.java
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/producer/AtomEntryEntityProducer.java
@@ -36,6 +36,7 @@ import org.apache.olingo.odata2.api.edm.EdmEntitySet;
import org.apache.olingo.odata2.api.edm.EdmException;
import org.apache.olingo.odata2.api.edm.EdmFacets;
import org.apache.olingo.odata2.api.edm.EdmLiteralKind;
+import org.apache.olingo.odata2.api.edm.EdmMapping;
import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
import org.apache.olingo.odata2.api.edm.EdmNavigationProperty;
import org.apache.olingo.odata2.api.edm.EdmSimpleType;
@@ -312,13 +313,16 @@ public class AtomEntryEntityProducer {
}
private void appendAtomContentLink(final XMLStreamWriter writer, final EntityInfoAggregator eia,
- final Map<String, Object> data, final String selfLink) throws EntityProviderException {
+ final Map<String, Object> data, final String selfLink) throws EntityProviderException, EdmException {
try {
String mediaResourceMimeType = properties.getMediaResourceMimeType();
if (mediaResourceMimeType == null) {
- String mediaResourceMimeTypeKey = properties.getMediaResourceTypeKey();
- if (mediaResourceMimeTypeKey != null) {
- mediaResourceMimeType = extractKey(data, mediaResourceMimeTypeKey);
+ EdmMapping entityTypeMapping = eia.getEntityType().getMapping();
+ if (entityTypeMapping != null) {
+ String mediaResourceMimeTypeKey = entityTypeMapping.getMediaResourceMimeTypeKey();
+ if (mediaResourceMimeTypeKey != null) {
+ mediaResourceMimeType = (String) data.get(mediaResourceMimeTypeKey);
+ }
}
if (mediaResourceMimeType == null) {
mediaResourceMimeType = ContentType.APPLICATION_OCTET_STREAM.toString();
@@ -336,26 +340,36 @@ public class AtomEntryEntityProducer {
}
private void appendAtomContentPart(final XMLStreamWriter writer, final EntityInfoAggregator eia,
- final Map<String, Object> data, final String selfLink) throws EntityProviderException {
+ final Map<String, Object> data, final String selfLink) throws EntityProviderException, EdmException {
try {
- String mediaResourceSourceKey = properties.getMediaResourceSourceKey();
+ // We have to support the media resource mime type at the properties till version 1.2 then this can be refactored
String mediaResourceMimeType = properties.getMediaResourceMimeType();
-
+ EdmMapping entityTypeMapping = eia.getEntityType().getMapping();
String self = null;
- if (mediaResourceSourceKey != null) {
- self = extractKey(data, mediaResourceSourceKey);
- }
- if (self == null) {
- self = selfLink + "/$value";
- }
- if (mediaResourceMimeType == null) {
- String mediaResourceMimeTypeKey = properties.getMediaResourceTypeKey();
- if (mediaResourceMimeTypeKey != null) {
- mediaResourceMimeType = extractKey(data, mediaResourceMimeTypeKey);
+ if (entityTypeMapping != null) {
+ String mediaResourceSourceKey = entityTypeMapping.getMediaResourceSourceKey();
+ if (mediaResourceSourceKey != null) {
+ self = (String) data.get(mediaResourceSourceKey);
+ }
+ if (self == null) {
+ self = selfLink + "/$value";
}
if (mediaResourceMimeType == null) {
+ String mediaResourceMimeTypeKey =
+ entityTypeMapping.getMimeType() != null ? entityTypeMapping.getMimeType()
+ : entityTypeMapping.getMediaResourceMimeTypeKey();
+ if (mediaResourceMimeTypeKey != null) {
+ mediaResourceMimeType = (String) data.get(mediaResourceMimeTypeKey);
+ }
+ if (mediaResourceMimeType == null) {
+ mediaResourceMimeType = ContentType.APPLICATION_OCTET_STREAM.toString();
+ }
+ }
+ } else {
+ self = selfLink + "/$value";
+ if (mediaResourceMimeType == null) {
mediaResourceMimeType = ContentType.APPLICATION_OCTET_STREAM.toString();
}
}
@@ -369,17 +383,6 @@ public class AtomEntryEntityProducer {
}
}
- private String extractKey(final Map<String, Object> data, final String mediaResourceMimeTypeKey)
- throws EntityProviderException {
- Object key = data.get(mediaResourceMimeTypeKey);
- if (key == null || key instanceof String) {
- return (String) key;
- } else {
- throw new EntityProviderException(EntityProviderException.ILLEGAL_ARGUMENT
- .addContent("Key must be of type String"));
- }
- }
-
private void appendAtomMandatoryParts(final XMLStreamWriter writer, final EntityInfoAggregator eia,
final Map<String, Object> data, final String selfLink) throws EntityProviderException {
try {
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/5ab0c609/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/producer/JsonEntryEntityProducer.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/producer/JsonEntryEntityProducer.java b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/producer/JsonEntryEntityProducer.java
index 0659ad8..783aca3 100644
--- a/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/producer/JsonEntryEntityProducer.java
+++ b/odata2-lib/odata-core/src/main/java/org/apache/olingo/odata2/core/ep/producer/JsonEntryEntityProducer.java
@@ -29,6 +29,7 @@ import org.apache.olingo.odata2.api.edm.Edm;
import org.apache.olingo.odata2.api.edm.EdmEntitySet;
import org.apache.olingo.odata2.api.edm.EdmEntityType;
import org.apache.olingo.odata2.api.edm.EdmException;
+import org.apache.olingo.odata2.api.edm.EdmMapping;
import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
import org.apache.olingo.odata2.api.edm.EdmNavigationProperty;
import org.apache.olingo.odata2.api.ep.EntityProviderException;
@@ -200,23 +201,38 @@ public class JsonEntryEntityProducer {
}
if (type.hasStream()) {
jsonStreamWriter.separator();
+
+ // We have to support the media resource mime type at the properties till version 1.2 then this can be refactored
String mediaResourceMimeType = properties.getMediaResourceMimeType();
- if (mediaResourceMimeType == null) {
- String mediaResourceMimeTypeKey = properties.getMediaResourceTypeKey();
- if (mediaResourceMimeTypeKey != null) {
- mediaResourceMimeType = extractKey(data, mediaResourceMimeTypeKey);
+ EdmMapping entityTypeMapping = entityInfo.getEntityType().getMapping();
+ String mediaSrc = null;
+
+ if (entityTypeMapping != null) {
+ String mediaResourceSourceKey = entityTypeMapping.getMediaResourceSourceKey();
+ if (mediaResourceSourceKey != null) {
+ mediaSrc = (String) data.get(mediaResourceSourceKey);
+ }
+ if (mediaSrc == null) {
+ mediaSrc = self + "/$value";
}
if (mediaResourceMimeType == null) {
+ mediaResourceMimeType =
+ entityTypeMapping.getMimeType() != null ? (String) data.get(entityTypeMapping.getMimeType())
+ : (String) data.get(entityTypeMapping.getMediaResourceMimeTypeKey());
+ if (mediaResourceMimeType == null) {
+ mediaResourceMimeType = ContentType.APPLICATION_OCTET_STREAM.toString();
+ }
+ }
+ } else {
+ mediaSrc = self + "/$value";
+ if (mediaResourceMimeType == null) {
mediaResourceMimeType = ContentType.APPLICATION_OCTET_STREAM.toString();
}
}
+
jsonStreamWriter.namedStringValueRaw(FormatJson.CONTENT_TYPE, mediaResourceMimeType);
jsonStreamWriter.separator();
- String mediaSrc = self + "/$value";
- if (properties.getMediaResourceSourceKey() != null) {
- mediaSrc = (String) data.get(properties.getMediaResourceSourceKey());
- }
jsonStreamWriter.namedStringValue(FormatJson.MEDIA_SRC, mediaSrc);
jsonStreamWriter.separator();
jsonStreamWriter.namedStringValue(FormatJson.EDIT_MEDIA, location + "/$value");
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/5ab0c609/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/ODataEntityProviderPropertiesTest.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/ODataEntityProviderPropertiesTest.java b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/ODataEntityProviderPropertiesTest.java
index 04ecea1..0605628 100644
--- a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/ODataEntityProviderPropertiesTest.java
+++ b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/ODataEntityProviderPropertiesTest.java
@@ -66,8 +66,6 @@ public class ODataEntityProviderPropertiesTest extends BaseTest {
.expandSelectTree(expandSelectTree)
.inlineCount(1)
.inlineCountType(InlineCount.ALLPAGES)
- .mediaResourceTypeKey("~typeKey")
- .mediaResourceSourceKey("~srcKey")
.mediaResourceMimeType("image/png")
.nextLink("http://localhost")
.selfLink(selfLink)
@@ -78,8 +76,6 @@ public class ODataEntityProviderPropertiesTest extends BaseTest {
assertEquals("Wrong expand select tree.", expandSelectTree, properties.getExpandSelectTree());
assertEquals("Wrong self link.", selfLink, properties.getSelfLink());
assertEquals("Wrong media resource mime type.", "image/png", properties.getMediaResourceMimeType());
- assertEquals("Wrong media resource type key.", "~typeKey", properties.getMediaResourceTypeKey());
- assertEquals("Wrong media resource src key.", "~srcKey", properties.getMediaResourceSourceKey());
assertEquals("Wrong base uri.", "http://localhost:80/", properties.getServiceRoot().toASCIIString());
assertEquals("Wrong inline count type.", InlineCount.ALLPAGES, properties.getInlineCountType());
assertEquals("Wrong inline count.", Integer.valueOf(1), properties.getInlineCount());
@@ -95,7 +91,7 @@ public class ODataEntityProviderPropertiesTest extends BaseTest {
.build();
assertEquals("Wrong mime type.", "text/html", properties.getMediaResourceMimeType());
}
-
+
@Test
public void buildEntryPropertiesFromExisting() throws Exception {
URI serviceRoot = new URI("http://localhost:80/");
@@ -108,25 +104,21 @@ public class ODataEntityProviderPropertiesTest extends BaseTest {
.expandSelectTree(expandSelectTree)
.inlineCount(1)
.inlineCountType(InlineCount.ALLPAGES)
- .mediaResourceTypeKey("~typeKey")
- .mediaResourceSourceKey("~srcKey")
.mediaResourceMimeType("image/png")
.nextLink("http://localhost")
.selfLink(selfLink)
.build();
//
- final EntityProviderWriteProperties fromProperties =
+ final EntityProviderWriteProperties fromProperties =
EntityProviderWriteProperties.fromProperties(properties).build();
-
+
//
assertEquals(1, fromProperties.getCallbacks().size());
assertTrue(fromProperties.getCallbacks().containsKey("aCallback"));
assertEquals(expandSelectTree, fromProperties.getExpandSelectTree());
assertEquals(selfLink, fromProperties.getSelfLink());
assertEquals("image/png", fromProperties.getMediaResourceMimeType());
- assertEquals("~typeKey", fromProperties.getMediaResourceTypeKey());
- assertEquals("~srcKey", fromProperties.getMediaResourceSourceKey());
assertEquals("Wrong base uri.", "http://localhost:80/", fromProperties.getServiceRoot().toASCIIString());
assertEquals("Wrong inline count type.", InlineCount.ALLPAGES, fromProperties.getInlineCountType());
assertEquals("Wrong inline count.", Integer.valueOf(1), fromProperties.getInlineCount());
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/5ab0c609/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/AtomEntryProducerTest.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/AtomEntryProducerTest.java b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/AtomEntryProducerTest.java
index 9cc296e..b50a072 100644
--- a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/AtomEntryProducerTest.java
+++ b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/AtomEntryProducerTest.java
@@ -42,7 +42,9 @@ import org.apache.olingo.odata2.api.edm.Edm;
import org.apache.olingo.odata2.api.edm.EdmConcurrencyMode;
import org.apache.olingo.odata2.api.edm.EdmCustomizableFeedMappings;
import org.apache.olingo.odata2.api.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.edm.EdmEntityType;
import org.apache.olingo.odata2.api.edm.EdmFacets;
+import org.apache.olingo.odata2.api.edm.EdmMapping;
import org.apache.olingo.odata2.api.edm.EdmProperty;
import org.apache.olingo.odata2.api.edm.EdmTargetPath;
import org.apache.olingo.odata2.api.edm.EdmTyped;
@@ -707,13 +709,11 @@ public class AtomEntryProducerTest extends AbstractProviderTest {
Map<String, Object> localEmployeeData = new HashMap<String, Object>(employeeData);
String mediaResourceSourceKey = "~src";
localEmployeeData.put(mediaResourceSourceKey, "http://localhost:8080/images/image1");
- EntityProviderWriteProperties localProperties =
- EntityProviderWriteProperties.fromProperties(DEFAULT_PROPERTIES).mediaResourceSourceKey(mediaResourceSourceKey
- ).build();
- ODataResponse response =
- ser.writeEntry(MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees"),
- localEmployeeData,
- localProperties);
+ EdmEntitySet employeesSet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees");
+ EdmMapping mapping = employeesSet.getEntityType().getMapping();
+ when(mapping.getMediaResourceSourceKey()).thenReturn(mediaResourceSourceKey);
+
+ ODataResponse response = ser.writeEntry(employeesSet, localEmployeeData, DEFAULT_PROPERTIES);
String xmlString = verifyResponse(response);
assertXpathExists(
@@ -729,15 +729,14 @@ public class AtomEntryProducerTest extends AbstractProviderTest {
Map<String, Object> localEmployeeData = new HashMap<String, Object>(employeeData);
String mediaResourceSourceKey = "~src";
localEmployeeData.put(mediaResourceSourceKey, "http://localhost:8080/images/image1");
- String mediaResourceTypeKey = "~type";
- localEmployeeData.put(mediaResourceTypeKey, "image/jpeg");
- EntityProviderWriteProperties localProperties =
- EntityProviderWriteProperties.fromProperties(DEFAULT_PROPERTIES).mediaResourceSourceKey(mediaResourceSourceKey
- ).mediaResourceTypeKey(mediaResourceTypeKey).build();
- ODataResponse response =
- ser.writeEntry(MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees"),
- localEmployeeData,
- localProperties);
+ String mediaResourceMimeTypeKey = "~type";
+ localEmployeeData.put(mediaResourceMimeTypeKey, "image/jpeg");
+ EdmEntitySet employeesSet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees");
+ EdmMapping mapping = employeesSet.getEntityType().getMapping();
+ when(mapping.getMediaResourceSourceKey()).thenReturn(mediaResourceSourceKey);
+ when(mapping.getMediaResourceMimeTypeKey()).thenReturn(mediaResourceMimeTypeKey);
+ when(mapping.getMimeType()).thenReturn(null);
+ ODataResponse response = ser.writeEntry(employeesSet, localEmployeeData, DEFAULT_PROPERTIES);
String xmlString = verifyResponse(response);
assertXpathExists(
@@ -753,13 +752,13 @@ public class AtomEntryProducerTest extends AbstractProviderTest {
Map<String, Object> localRoomData = new HashMap<String, Object>(roomData);
String mediaResourceSourceKey = "~src";
localRoomData.put(mediaResourceSourceKey, "http://localhost:8080/images/image1");
- EntityProviderWriteProperties localProperties =
- EntityProviderWriteProperties.fromProperties(DEFAULT_PROPERTIES).mediaResourceSourceKey(mediaResourceSourceKey
- ).build();
- ODataResponse response =
- ser.writeEntry(MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Rooms"),
- localRoomData,
- localProperties);
+ EdmEntitySet roomsSet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Rooms");
+ EdmEntityType roomType = roomsSet.getEntityType();
+ EdmMapping mapping = mock(EdmMapping.class);
+ when(roomType.getMapping()).thenReturn(mapping);
+ when(mapping.getMediaResourceSourceKey()).thenReturn(mediaResourceSourceKey);
+
+ ODataResponse response = ser.writeEntry(roomsSet, localRoomData, DEFAULT_PROPERTIES);
String xmlString = verifyResponse(response);
assertXpathNotExists(
@@ -775,15 +774,16 @@ public class AtomEntryProducerTest extends AbstractProviderTest {
Map<String, Object> localRoomData = new HashMap<String, Object>(roomData);
String mediaResourceSourceKey = "~src";
localRoomData.put(mediaResourceSourceKey, "http://localhost:8080/images/image1");
- String mediaResourceTypeKey = "~type";
- localRoomData.put(mediaResourceTypeKey, "image/jpeg");
- EntityProviderWriteProperties localProperties =
- EntityProviderWriteProperties.fromProperties(DEFAULT_PROPERTIES).mediaResourceSourceKey(mediaResourceSourceKey
- ).mediaResourceTypeKey(mediaResourceTypeKey).build();
- ODataResponse response =
- ser.writeEntry(MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Rooms"),
- localRoomData,
- localProperties);
+ String mediaResourceMimeTypeKey = "~type";
+ localRoomData.put(mediaResourceMimeTypeKey, "image/jpeg");
+ EdmEntitySet roomsSet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Rooms");
+ EdmEntityType roomType = roomsSet.getEntityType();
+ EdmMapping mapping = mock(EdmMapping.class);
+ when(roomType.getMapping()).thenReturn(mapping);
+ when(mapping.getMediaResourceSourceKey()).thenReturn(mediaResourceSourceKey);
+ when(mapping.getMediaResourceMimeTypeKey()).thenReturn(mediaResourceMimeTypeKey);
+
+ ODataResponse response = ser.writeEntry(roomsSet, localRoomData, DEFAULT_PROPERTIES);
String xmlString = verifyResponse(response);
assertXpathNotExists(
@@ -793,6 +793,26 @@ public class AtomEntryProducerTest extends AbstractProviderTest {
assertXpathNotExists("/a:entry/a:content[@src=\"http://localhost:8080/images/image1\"]", xmlString);
}
+ @Test
+ public void assureGetMimeTypeWinsOverGetMediaResourceMimeTypeKey() throws Exception {
+ // Keep this test till version 1.2
+ AtomEntityProvider ser = createAtomEntityProvider();
+ Map<String, Object> localEmployeeData = new HashMap<String, Object>(employeeData);
+ String mediaResourceMimeTypeKey = "~type";
+ localEmployeeData.put(mediaResourceMimeTypeKey, "wrong");
+ String originalMimeTypeKey = "~originalType";
+ localEmployeeData.put(originalMimeTypeKey, "right");
+ EdmEntitySet employeesSet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees");
+ EdmMapping mapping = employeesSet.getEntityType().getMapping();
+ when(mapping.getMediaResourceMimeTypeKey()).thenReturn(mediaResourceMimeTypeKey);
+ when(mapping.getMimeType()).thenReturn(originalMimeTypeKey);
+ ODataResponse response = ser.writeEntry(employeesSet, localEmployeeData, DEFAULT_PROPERTIES);
+ String xmlString = verifyResponse(response);
+
+ assertXpathExists("/a:entry/a:content[@type=\"right\"]", xmlString);
+ assertXpathNotExists("/a:entry/a:content[@type=\"wrong\"]", xmlString);
+ }
+
private void verifyTagOrdering(final String xmlString, final String... toCheckTags) {
XMLUnitHelper.verifyTagOrdering(xmlString, toCheckTags);
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/5ab0c609/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/JsonEntryEntityProducerTest.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/JsonEntryEntityProducerTest.java b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/JsonEntryEntityProducerTest.java
index 0ce9980..8f53d84 100644
--- a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/JsonEntryEntityProducerTest.java
+++ b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/JsonEntryEntityProducerTest.java
@@ -22,6 +22,8 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
import java.io.IOException;
import java.io.InputStream;
@@ -37,6 +39,8 @@ import java.util.TimeZone;
import org.apache.olingo.odata2.api.ODataCallback;
import org.apache.olingo.odata2.api.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.edm.EdmMapping;
import org.apache.olingo.odata2.api.edm.EdmProperty;
import org.apache.olingo.odata2.api.ep.EntityProviderException;
import org.apache.olingo.odata2.api.ep.EntityProviderWriteProperties;
@@ -124,11 +128,9 @@ public class JsonEntryEntityProducerTest extends BaseTest {
photoData.put("Id", 1);
photoData.put("Type", "image/png");
photoData.put("BinaryData", new byte[] { -1, 0, 1, 2 });
+ photoData.put("getType", "image/png");
- EntityProviderWriteProperties writeProperties =
- EntityProviderWriteProperties.fromProperties(DEFAULT_PROPERTIES).mediaResourceTypeKey("Type").build();
-
- final ODataResponse response = new JsonEntityProvider().writeEntry(entitySet, photoData, writeProperties);
+ final ODataResponse response = new JsonEntityProvider().writeEntry(entitySet, photoData, DEFAULT_PROPERTIES);
final String json = verifyResponse(response);
assertEquals("{\"d\":{\"__metadata\":{"
+ "\"id\":\"" + BASE_URI + "Container2.Photos(Id=1,Type='image%2Fpng')\","
@@ -154,8 +156,8 @@ public class JsonEntryEntityProducerTest extends BaseTest {
Mockito.when(node.getProperties()).thenReturn(Arrays.asList(property));
EntityProviderWriteProperties writeProperties =
- EntityProviderWriteProperties.fromProperties(DEFAULT_PROPERTIES).mediaResourceTypeKey("getImageType")
- .serviceRoot(URI.create(BASE_URI)).expandSelectTree(node).build();
+ EntityProviderWriteProperties.fromProperties(DEFAULT_PROPERTIES).serviceRoot(URI.create(BASE_URI))
+ .expandSelectTree(node).build();
final ODataResponse response = new JsonEntityProvider().writeEntry(entitySet, employeeData,
writeProperties);
@@ -557,14 +559,12 @@ public class JsonEntryEntityProducerTest extends BaseTest {
String mediaResourceSourceKey = "~src";
employeeData.put(mediaResourceSourceKey, "http://localhost:8080/images/image1");
- EntityProviderWriteProperties localProperties =
- EntityProviderWriteProperties.fromProperties(DEFAULT_PROPERTIES).mediaResourceSourceKey(mediaResourceSourceKey
- ).build();
- ODataResponse response =
- new JsonEntityProvider().writeEntry(MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet(
- "Employees"),
- employeeData,
- localProperties);
+
+ EdmEntitySet employeesSet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees");
+ EdmMapping mapping = employeesSet.getEntityType().getMapping();
+ when(mapping.getMediaResourceSourceKey()).thenReturn(mediaResourceSourceKey);
+
+ ODataResponse response = new JsonEntityProvider().writeEntry(employeesSet, employeeData, DEFAULT_PROPERTIES);
String jsonString = verifyResponse(response);
Gson gson = new Gson();
StringMap<Object> jsonMap = gson.fromJson(jsonString, StringMap.class);
@@ -604,16 +604,16 @@ public class JsonEntryEntityProducerTest extends BaseTest {
employeeData.put("Location", locationData);
String mediaResourceSourceKey = "~src";
employeeData.put(mediaResourceSourceKey, "http://localhost:8080/images/image1");
- String mediaResourceTypeKey = "~type";
- employeeData.put(mediaResourceTypeKey, "image/jpeg");
- EntityProviderWriteProperties localProperties =
- EntityProviderWriteProperties.fromProperties(DEFAULT_PROPERTIES).mediaResourceSourceKey(mediaResourceSourceKey
- ).mediaResourceTypeKey(mediaResourceTypeKey).build();
- ODataResponse response =
- new JsonEntityProvider().writeEntry(MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet(
- "Employees"),
- employeeData,
- localProperties);
+ String mediaResourceMimeTypeKey = "~type";
+ employeeData.put(mediaResourceMimeTypeKey, "image/jpeg");
+
+ EdmEntitySet employeesSet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees");
+ EdmMapping mapping = employeesSet.getEntityType().getMapping();
+ when(mapping.getMediaResourceSourceKey()).thenReturn(mediaResourceSourceKey);
+ when(mapping.getMediaResourceMimeTypeKey()).thenReturn(mediaResourceMimeTypeKey);
+ when(mapping.getMimeType()).thenReturn(null);
+
+ ODataResponse response = new JsonEntityProvider().writeEntry(employeesSet, employeeData, DEFAULT_PROPERTIES);
String jsonString = verifyResponse(response);
Gson gson = new Gson();
@@ -637,13 +637,14 @@ public class JsonEntryEntityProducerTest extends BaseTest {
String mediaResourceSourceKey = "~src";
roomData.put(mediaResourceSourceKey, "http://localhost:8080/images/image1");
- EntityProviderWriteProperties localProperties =
- EntityProviderWriteProperties.fromProperties(DEFAULT_PROPERTIES).mediaResourceSourceKey(mediaResourceSourceKey
- ).build();
- ODataResponse response =
- new JsonEntityProvider().writeEntry(MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Rooms"),
- roomData,
- localProperties);
+
+ EdmEntitySet roomsSet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Rooms");
+ EdmEntityType roomType = roomsSet.getEntityType();
+ EdmMapping mapping = mock(EdmMapping.class);
+ when(roomType.getMapping()).thenReturn(mapping);
+ when(mapping.getMediaResourceSourceKey()).thenReturn(mediaResourceSourceKey);
+
+ ODataResponse response = new JsonEntityProvider().writeEntry(roomsSet, roomData, DEFAULT_PROPERTIES);
String jsonString = verifyResponse(response);
Gson gson = new Gson();
StringMap<Object> jsonMap = gson.fromJson(jsonString, StringMap.class);
@@ -666,15 +667,17 @@ public class JsonEntryEntityProducerTest extends BaseTest {
String mediaResourceSourceKey = "~src";
roomData.put(mediaResourceSourceKey, "http://localhost:8080/images/image1");
- String mediaResourceTypeKey = "~type";
- roomData.put(mediaResourceTypeKey, "image/jpeg");
- EntityProviderWriteProperties localProperties =
- EntityProviderWriteProperties.fromProperties(DEFAULT_PROPERTIES).mediaResourceSourceKey(mediaResourceSourceKey
- ).mediaResourceTypeKey(mediaResourceTypeKey).build();
- ODataResponse response =
- new JsonEntityProvider().writeEntry(MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Rooms"),
- roomData,
- localProperties);
+ String mediaResourceMimeTypeKey = "~type";
+ roomData.put(mediaResourceMimeTypeKey, "image/jpeg");
+
+ EdmEntitySet roomsSet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Rooms");
+ EdmEntityType roomType = roomsSet.getEntityType();
+ EdmMapping mapping = mock(EdmMapping.class);
+ when(roomType.getMapping()).thenReturn(mapping);
+ when(mapping.getMediaResourceSourceKey()).thenReturn(mediaResourceSourceKey);
+ when(mapping.getMediaResourceMimeTypeKey()).thenReturn(mediaResourceMimeTypeKey);
+
+ ODataResponse response = new JsonEntityProvider().writeEntry(roomsSet, roomData, DEFAULT_PROPERTIES);
String jsonString = verifyResponse(response);
Gson gson = new Gson();
StringMap<Object> jsonMap = gson.fromJson(jsonString, StringMap.class);
@@ -685,6 +688,54 @@ public class JsonEntryEntityProducerTest extends BaseTest {
assertNull(jsonMap.get("content_type"));
assertNull(jsonMap.get("edit_media"));
}
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void assureGetMimeTypeWinsOverGetMediaResourceMimeTypeKey() throws Exception {
+ // Keep this test till version 1.2
+ Map<String, Object> employeeData = new HashMap<String, Object>();
+
+ Calendar date = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
+ date.clear();
+ date.set(1999, 0, 1);
+
+ employeeData.put("EmployeeId", "1");
+ employeeData.put("ImmageUrl", null);
+ employeeData.put("ManagerId", "1");
+ employeeData.put("Age", new Integer(52));
+ employeeData.put("RoomId", "1");
+ employeeData.put("EntryDate", date);
+ employeeData.put("TeamId", "42");
+ employeeData.put("EmployeeName", "Walter Winter");
+
+ Map<String, Object> locationData = new HashMap<String, Object>();
+ Map<String, Object> cityData = new HashMap<String, Object>();
+ cityData.put("PostalCode", "33470");
+ cityData.put("CityName", "Duckburg");
+ locationData.put("City", cityData);
+ locationData.put("Country", "Calisota");
+
+ employeeData.put("Location", locationData);
+ String mediaResourceMimeTypeKey = "~type";
+ employeeData.put(mediaResourceMimeTypeKey, "wrong");
+ String originalMimeTypeKey = "~originalType";
+ employeeData.put(originalMimeTypeKey, "right");
+
+ EdmEntitySet employeesSet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees");
+ EdmMapping mapping = employeesSet.getEntityType().getMapping();
+ when(mapping.getMediaResourceMimeTypeKey()).thenReturn(mediaResourceMimeTypeKey);
+ when(mapping.getMimeType()).thenReturn(originalMimeTypeKey);
+
+ ODataResponse response = new JsonEntityProvider().writeEntry(employeesSet, employeeData, DEFAULT_PROPERTIES);
+ String jsonString = verifyResponse(response);
+
+ Gson gson = new Gson();
+ StringMap<Object> jsonMap = gson.fromJson(jsonString, StringMap.class);
+ jsonMap = (StringMap<Object>) jsonMap.get("d");
+ jsonMap = (StringMap<Object>) jsonMap.get("__metadata");
+
+ assertEquals("right", jsonMap.get("content_type"));
+ }
private String verifyResponse(final ODataResponse response) throws IOException {
assertNotNull(response);
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/5ab0c609/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/JsonFunctionImportTest.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/JsonFunctionImportTest.java b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/JsonFunctionImportTest.java
index 97314fd..001e7f1 100644
--- a/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/JsonFunctionImportTest.java
+++ b/odata2-lib/odata-core/src/test/java/org/apache/olingo/odata2/core/ep/producer/JsonFunctionImportTest.java
@@ -131,7 +131,7 @@ public class JsonFunctionImportTest extends BaseTest {
MockFacade.getMockEdm().getDefaultEntityContainer().getFunctionImport("OldestEmployee");
final String uri = "http://host:80/service/";
final EntityProviderWriteProperties properties =
- EntityProviderWriteProperties.serviceRoot(URI.create(uri)).mediaResourceTypeKey("getImageType").build();
+ EntityProviderWriteProperties.serviceRoot(URI.create(uri)).build();
Map<String, Object> employeeData = new HashMap<String, Object>();
employeeData.put("EmployeeId", "1");
employeeData.put("getImageType", "image/jpeg");
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/5ab0c609/odata2-lib/odata-ref/src/main/java/org/apache/olingo/odata2/ref/processor/ListsProcessor.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-ref/src/main/java/org/apache/olingo/odata2/ref/processor/ListsProcessor.java b/odata2-lib/odata-ref/src/main/java/org/apache/olingo/odata2/ref/processor/ListsProcessor.java
index 16a9c8c..901fe59 100644
--- a/odata2-lib/odata-ref/src/main/java/org/apache/olingo/odata2/ref/processor/ListsProcessor.java
+++ b/odata2-lib/odata-ref/src/main/java/org/apache/olingo/odata2/ref/processor/ListsProcessor.java
@@ -194,7 +194,6 @@ public class ListsProcessor extends ODataSingleProcessor {
values.add(getStructuralTypeValueMap(entryData, entityType));
}
- String mediaTypeKey = entityType.getMapping() == null ? null : entityType.getMapping().getMimeType();
final EntityProviderWriteProperties feedProperties = EntityProviderWriteProperties
.serviceRoot(context.getPathInfo().getServiceRoot())
.inlineCountType(inlineCountType)
@@ -202,7 +201,6 @@ public class ListsProcessor extends ODataSingleProcessor {
.expandSelectTree(UriParser.createExpandSelectTree(uriInfo.getSelect(), uriInfo.getExpand()))
.callbacks(getCallbacks(data, entityType))
.nextLink(nextLink)
- .mediaResourceTypeKey(mediaTypeKey)
.build();
final int timingHandle = context.startRuntimeMeasurement("EntityProvider", "writeFeed");
@@ -828,14 +826,9 @@ public class ListsProcessor extends ODataSingleProcessor {
}
ODataContext context = getContext();
- String mediaTypeKey = null;
- if (type instanceof EdmStructuralType) {
- EdmStructuralType structType = (EdmStructuralType) type;
- mediaTypeKey = structType.getMapping() == null ? null : structType.getMapping().getMimeType();
- }
final EntityProviderWriteProperties entryProperties = EntityProviderWriteProperties
- .serviceRoot(context.getPathInfo().getServiceRoot()).mediaResourceTypeKey(mediaTypeKey).build();
+ .serviceRoot(context.getPathInfo().getServiceRoot()).build();
final int timingHandle = context.startRuntimeMeasurement("EntityProvider", "writeFunctionImport");
@@ -984,12 +977,10 @@ public class ListsProcessor extends ODataSingleProcessor {
}
WriteFeedCallbackResult result = new WriteFeedCallbackResult();
result.setFeedData(values);
- String mimeTypeKey =
- entityType.getMapping() == null ? null : entityType.getMapping().getMimeType();
EntityProviderWriteProperties inlineProperties =
EntityProviderWriteProperties.serviceRoot(getContext().getPathInfo().getServiceRoot()).callbacks(
getCallbacks(relatedData, entityType)).expandSelectTree(context.getCurrentExpandSelectTreeNode())
- .selfLink(context.getSelfLink()).mediaResourceTypeKey(mimeTypeKey).build();
+ .selfLink(context.getSelfLink()).build();
result.setInlineProperties(inlineProperties);
return result;
} catch (final ODataException e) {
@@ -1011,12 +1002,10 @@ public class ListsProcessor extends ODataSingleProcessor {
relatedData = null;
}
result.setEntryData(getStructuralTypeValueMap(relatedData, entityType));
- String mimeTypeKey =
- entityType.getMapping() == null ? null : entityType.getMapping().getMimeType();
+
EntityProviderWriteProperties inlineProperties =
EntityProviderWriteProperties.serviceRoot(getContext().getPathInfo().getServiceRoot()).callbacks(
getCallbacks(relatedData, entityType)).expandSelectTree(context.getCurrentExpandSelectTreeNode())
- .mediaResourceTypeKey(mimeTypeKey)
.build();
result.setInlineProperties(inlineProperties);
return result;
@@ -1059,13 +1048,10 @@ public class ListsProcessor extends ODataSingleProcessor {
final Map<String, Object> values = getStructuralTypeValueMap(data, entityType);
ODataContext context = getContext();
- String mimeTypeKey =
- entitySet.getEntityType().getMapping() == null ? null : entitySet.getEntityType().getMapping().getMimeType();
EntityProviderWriteProperties writeProperties = EntityProviderWriteProperties
.serviceRoot(context.getPathInfo().getServiceRoot())
.expandSelectTree(expandSelectTree)
.callbacks(getCallbacks(data, entityType))
- .mediaResourceTypeKey(mimeTypeKey)
.build();
final int timingHandle = context.startRuntimeMeasurement("EntityProvider", "writeEntry");
[20/52] git commit: Implementation for 'create/update/delete'
Posted by mi...@apache.org.
Implementation for 'create/update/delete'
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/d641fd16
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/d641fd16
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/d641fd16
Branch: refs/heads/master
Commit: d641fd1632b7c226a89413d64f417fa2d80ef2b7
Parents: 0169bfc
Author: Michael Bolz <mi...@apache.org>
Authored: Wed Nov 13 08:52:39 2013 +0100
Committer: Michael Bolz <mi...@apache.org>
Committed: Wed Nov 13 08:52:39 2013 +0100
----------------------------------------------------------------------
.../annotation/ds/AnnotationInMemoryDs.java | 43 ++++++++++++++++----
1 file changed, 34 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d641fd16/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/ds/AnnotationInMemoryDs.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/ds/AnnotationInMemoryDs.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/ds/AnnotationInMemoryDs.java
index 0a467fa..a07765d 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/ds/AnnotationInMemoryDs.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/ds/AnnotationInMemoryDs.java
@@ -71,9 +71,7 @@ public class AnnotationInMemoryDs implements ListsDataSource {
public List<?> readData(EdmEntitySet entitySet) throws ODataNotImplementedException,
ODataNotFoundException, EdmException, ODataApplicationException {
- final String name = entitySet.getEntityType().getName();
-
- DataStore<Object> holder = dataStores.get(name);
+ DataStore<Object> holder = getDataStore(entitySet);
if (holder != null) {
return new ArrayList(holder.read());
}
@@ -84,9 +82,8 @@ public class AnnotationInMemoryDs implements ListsDataSource {
@Override
public Object readData(EdmEntitySet entitySet, Map<String, Object> keys)
throws ODataNotFoundException, EdmException, ODataApplicationException {
- final String name = entitySet.getEntityType().getName();
- DataStore<Object> store = dataStores.get(name);
+ DataStore<Object> store = getDataStore(entitySet);
if (store != null) {
Object keyInstance = store.createInstance();
ANNOTATION_HELPER.setKeyFields(keyInstance, keys.values().toArray());
@@ -166,6 +163,12 @@ public class AnnotationInMemoryDs implements ListsDataSource {
@Override
public Object newDataObject(EdmEntitySet entitySet)
throws ODataNotImplementedException, EdmException, ODataApplicationException {
+
+ DataStore<Object> dataStore = getDataStore(entitySet);
+ if (dataStore != null) {
+ return dataStore.createInstance();
+ }
+
throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
}
@@ -179,15 +182,18 @@ public class AnnotationInMemoryDs implements ListsDataSource {
@Override
public void deleteData(EdmEntitySet entitySet, Map<String, Object> keys)
throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException {
- throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
-
+ DataStore<Object> dataStore = getDataStore(entitySet);
+ Object keyInstance = dataStore.createInstance();
+ ANNOTATION_HELPER.setKeyFields(keyInstance, keys.values().toArray());
+ dataStore.delete(keyInstance);
}
@Override
public void createData(EdmEntitySet entitySet, Object data)
throws ODataNotImplementedException, EdmException, ODataApplicationException {
- throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
+ DataStore<Object> dataStore = getDataStore(entitySet);
+ dataStore.create(data);
}
@Override
@@ -195,7 +201,6 @@ public class AnnotationInMemoryDs implements ListsDataSource {
Map<String, Object> targetKeys)
throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException {
throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
-
}
@Override
@@ -205,6 +210,26 @@ public class AnnotationInMemoryDs implements ListsDataSource {
throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
}
+
+ /**
+ * Returns corresponding DataStore for EdmEntitySet or if no data store is registered an
+ * ODataRuntimeException is thrown.
+ * Never returns NULL.
+ *
+ * @param entitySet for which the corresponding DataStore is returned
+ * @return a DataStore object
+ * @throws EdmException
+ * @throws ODataRuntimeException if no DataStore is found
+ */
+ private DataStore<Object> getDataStore(EdmEntitySet entitySet) throws EdmException {
+ final String name = entitySet.getEntityType().getName();
+ DataStore<Object> dataStore = dataStores.get(name);
+ if(dataStore == null) {
+ throw new ODataRuntimeException("No DataStore found for entity set '" + entitySet + "'.");
+ }
+ return dataStore;
+ }
+
private Object getValue(Field field, Object instance) {
try {
boolean access = field.isAccessible();
[49/52] Renamed project
Posted by mi...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/core/annotation/util/AnnotationHelper.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/core/annotation/util/AnnotationHelper.java b/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/core/annotation/util/AnnotationHelper.java
new file mode 100644
index 0000000..0c81fb1
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/core/annotation/util/AnnotationHelper.java
@@ -0,0 +1,726 @@
+/**
+ * *****************************************************************************
+ * 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.core.annotation.util;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Field;
+import java.lang.reflect.ParameterizedType;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.olingo.odata2.api.annotation.edm.EdmComplexType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
+import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty.Multiplicity;
+import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
+import org.apache.olingo.odata2.api.edm.EdmLiteralKind;
+import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
+import org.apache.olingo.odata2.api.edm.EdmSimpleTypeException;
+import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
+import org.apache.olingo.odata2.api.edm.FullQualifiedName;
+import org.apache.olingo.odata2.api.exception.ODataException;
+import org.apache.olingo.odata2.core.exception.ODataRuntimeException;
+
+/**
+ *
+ */
+public class AnnotationHelper {
+
+ public static final String DEFAULT_CONTAINER_NAME = "DefaultContainer";
+
+ /**
+ * Compare keys of both instances.
+ *
+ * @param firstInstance
+ * @param secondInstance
+ * @return
+ */
+ public boolean keyMatch(Object firstInstance, Object secondInstance) {
+ if (firstInstance == null || secondInstance == null) {
+ return false;
+ } else if (firstInstance.getClass() != secondInstance.getClass()) {
+ return false;
+ }
+
+ Map<String, Object> firstKeyFields = getValueForAnnotatedFields(firstInstance, EdmKey.class);
+ Map<String, Object> secondKeyFields = getValueForAnnotatedFields(secondInstance, EdmKey.class);
+
+ return keyValuesMatch(firstKeyFields, secondKeyFields);
+ }
+
+ /**
+ * Compare keys of instance with key values in map.
+ *
+ * @param instance
+ * @param keyName2Value
+ * @return
+ */
+ public boolean keyMatch(Object instance, Map<String, Object> keyName2Value) {
+ Map<String, Object> instanceKeyFields = getValueForAnnotatedFields(instance, EdmKey.class);
+ return keyValuesMatch(instanceKeyFields, keyName2Value);
+ }
+
+ private boolean keyValuesMatch(Map<String, Object> firstKeyValues, Map<String, Object> secondKeyValues) {
+ if (firstKeyValues.size() != secondKeyValues.size()) {
+ return false;
+ } else {
+ Set<Map.Entry<String, Object>> entries = firstKeyValues.entrySet();
+ for (Map.Entry<String, Object> entry : entries) {
+ Object firstKey = entry.getValue();
+ Object secondKey = secondKeyValues.get(entry.getKey());
+ if (!isEqual(firstKey, secondKey)) {
+ return false;
+ }
+ }
+ return true;
+ }
+ }
+
+ private boolean isEqual(Object firstKey, Object secondKey) {
+ if (firstKey == null) {
+ if (secondKey == null) {
+ return true;
+ } else {
+ return secondKey.equals(firstKey);
+ }
+ } else {
+ return firstKey.equals(secondKey);
+ }
+ }
+
+ public String extractEntitTypeName(EdmNavigationProperty enp, Class<?> fallbackClass) {
+ Class<?> entityTypeClass = enp.toType();
+ return extractEntityTypeName(entityTypeClass == Object.class ? fallbackClass : entityTypeClass);
+ }
+
+ public String extractEntitTypeName(EdmNavigationProperty enp, Field field) {
+ Class<?> entityTypeClass = enp.toType();
+ if (entityTypeClass == Object.class) {
+ Class<?> toClass = field.getType();
+ return extractEntityTypeName((toClass.isArray() || Collection.class.isAssignableFrom(toClass) ?
+ (Class<?>) ((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0] : toClass));
+ } else {
+ return extractEntityTypeName(entityTypeClass);
+ }
+ }
+
+ /**
+ * Returns <code>NULL</code> if given class is not annotated. If annotated the set entity type name is returned and if
+ * no name is set the default name is generated from the simple class name.
+ *
+ * @param annotatedClass
+ * @return
+ */
+ public String extractEntityTypeName(Class<?> annotatedClass) {
+ return extractTypeName(annotatedClass, EdmEntityType.class);
+ }
+
+ public FullQualifiedName extractEntityTypeFqn(EdmEntityType type, Class<?> annotatedClass) {
+ if(type.namespace().isEmpty()) {
+ return new FullQualifiedName(generateNamespace(annotatedClass), extractEntityTypeName(annotatedClass));
+ }
+ return new FullQualifiedName(type.namespace(), extractEntityTypeName(annotatedClass));
+ }
+
+ public FullQualifiedName extractEntityTypeFqn(Class<?> annotatedClass) {
+ EdmEntityType type = annotatedClass.getAnnotation(EdmEntityType.class);
+ if(type == null) {
+ return null;
+ }
+ return extractEntityTypeFqn(type, annotatedClass);
+ }
+
+ public FullQualifiedName extractComplexTypeFqn(Class<?> annotatedClass) {
+ EdmComplexType type = annotatedClass.getAnnotation(EdmComplexType.class);
+ if(type == null) {
+ return null;
+ }
+ return extractComplexTypeFqn(type, annotatedClass);
+ }
+
+ public FullQualifiedName extractComplexTypeFqn(EdmComplexType type, Class<?> annotatedClass) {
+ if(type.namespace().isEmpty()) {
+ return new FullQualifiedName(generateNamespace(annotatedClass), extractComplexTypeName(annotatedClass));
+ }
+ return new FullQualifiedName(type.namespace(), extractComplexTypeName(annotatedClass));
+ }
+
+ public String extractComplexTypeName(Class<?> annotatedClass) {
+ return extractTypeName(annotatedClass, EdmComplexType.class);
+ }
+
+ public String generateNamespace(Class<?> annotatedClass) {
+ String packageName = annotatedClass.getPackage().getName();
+ return packageName;
+ }
+
+ /**
+ *
+ *
+ * @param <T> must be EdmEntityType or EdmComplexType annotation
+ * @param annotatedClass
+ * @param typeAnnotation
+ * @return null if annotatedClass is not annotated or name set via annotation or generated via
+ * {@link #getCanonicalName(java.lang.Class)}
+ */
+ private <T extends Annotation> String extractTypeName(Class<?> annotatedClass, Class<T> typeAnnotation) {
+ if (annotatedClass == Object.class) {
+ return null;
+ }
+ T type = annotatedClass.getAnnotation(typeAnnotation);
+ if (type == null) {
+ return null;
+ }
+
+ String name;
+ if (typeAnnotation == EdmEntityType.class) {
+ name = ((EdmEntityType) type).name();
+ } else if (typeAnnotation == EdmComplexType.class) {
+ name = ((EdmComplexType) type).name();
+ } else {
+ return null;
+ }
+
+ if (name.isEmpty()) {
+ return getCanonicalName(annotatedClass);
+ }
+ return name;
+ }
+
+ /**
+ * Get the set property name from an EdmProperty or EdmNavigationProperty annotation.
+ *
+ * @param field
+ * @return
+ */
+ public String getPropertyNameFromAnnotation(Field field) {
+ EdmProperty property = field.getAnnotation(EdmProperty.class);
+ if (property == null) {
+ EdmNavigationProperty navProperty = field.getAnnotation(EdmNavigationProperty.class);
+ if (navProperty == null) {
+ throw new EdmAnnotationException("Given field '" + field
+ + "' has no EdmProperty or EdmNavigationProperty annotation.");
+ }
+ return navProperty.name();
+ }
+ return property.name();
+ }
+
+ public String getPropertyName(Field field) {
+ String propertyName = getPropertyNameFromAnnotation(field);
+ if (propertyName.isEmpty()) {
+ propertyName = getCanonicalName(field);
+ }
+ return propertyName;
+ }
+
+ public String extractFromRoleName(EdmNavigationProperty enp, Field field) {
+ return getCanonicalRole(field.getDeclaringClass());
+ }
+
+ public String extractToRoleName(EdmNavigationProperty enp, Field field) {
+ String role = enp.toRole();
+ if (role.isEmpty()) {
+ role = getCanonicalRole(
+ field.getType().isArray() || Collection.class.isAssignableFrom(field.getType()) ?
+ (Class<?>) ((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0] : field.getType());
+ }
+ return role;
+ }
+
+ public String getCanonicalRole(Class<?> fallbackClass) {
+ String toRole = extractEntityTypeName(fallbackClass);
+ return "r_" + toRole;
+ }
+
+ public String extractRelationshipName(EdmNavigationProperty enp, Field field) {
+ String relationshipName = enp.association();
+ if (relationshipName.isEmpty()) {
+ final String fromRole = extractFromRoleName(enp, field);
+ final String toRole = extractToRoleName(enp, field);
+ if (fromRole.compareTo(toRole) > 0) {
+ relationshipName = toRole + "-" + fromRole;
+ } else {
+ relationshipName = fromRole + "-" + toRole;
+ }
+ }
+ return relationshipName;
+ }
+
+ public EdmMultiplicity getMultiplicity(EdmNavigationProperty enp, Field field) {
+ EdmMultiplicity multiplicity = mapMultiplicity(enp.toMultiplicity());
+ final boolean isCollectionType = field.getType().isArray() || Collection.class.isAssignableFrom(field.getType());
+
+ if (multiplicity == EdmMultiplicity.ONE && isCollectionType) {
+ return EdmMultiplicity.MANY;
+ }
+ return multiplicity;
+ }
+
+
+ /**
+ * Set key fields based on values in map.
+ * If an key field is not available or <code>NULL</code> in the map
+ * it will be not set as <code>NULL</code> at the instance object.
+ *
+ * @param instance
+ * @param keys
+ * @return
+ */
+ public <T> T setKeyFields(T instance, Map<String, Object> keys) {
+ List<Field> fields = getAnnotatedFields(instance, EdmKey.class);
+
+ for (Field field : fields) {
+ String propertyName = getPropertyName(field);
+ Object keyValue = keys.get(propertyName);
+ setValueForProperty(instance, propertyName, keyValue);
+ }
+
+ return instance;
+ }
+
+ public static final class ODataAnnotationException extends ODataException {
+ private static final long serialVersionUID = 1L;
+
+ public ODataAnnotationException(String message) {
+ super(message);
+ }
+ }
+
+
+ public class AnnotatedNavInfo {
+ private final Field fromField;
+ private final Field toField;
+ private final EdmNavigationProperty fromNavigation;
+ private final EdmNavigationProperty toNavigation;
+
+ public AnnotatedNavInfo(Field fromField, Field toField, EdmNavigationProperty fromNavigation,
+ EdmNavigationProperty toNavigation) {
+ this.fromField = fromField;
+ this.toField = toField;
+ this.fromNavigation = fromNavigation;
+ this.toNavigation = toNavigation;
+ }
+
+ public Field getFromField() {
+ return fromField;
+ }
+
+ public Field getToField() {
+ return toField;
+ }
+
+ public EdmMultiplicity getFromMultiplicity() {
+ return getMultiplicity(toNavigation, toField);
+ }
+
+ public EdmMultiplicity getToMultiplicity() {
+ return getMultiplicity(fromNavigation, fromField);
+ }
+
+ public boolean isBiDirectional() {
+ return toNavigation != null;
+ }
+ }
+
+ public AnnotatedNavInfo getCommonNavigationInfo(Class<?> sourceClass, Class<?> targetClass) {
+ List<Field> sourceFields = getAnnotatedFields(sourceClass, EdmNavigationProperty.class);
+ List<Field> targetFields = getAnnotatedFields(targetClass, EdmNavigationProperty.class);
+
+ // first try via association name to get full navigation information
+ for (Field sourceField : sourceFields) {
+ final EdmNavigationProperty sourceNav = sourceField.getAnnotation(EdmNavigationProperty.class);
+ final String sourceAssociation = extractRelationshipName(sourceNav, sourceField);
+ for (Field targetField : targetFields) {
+ final EdmNavigationProperty targetNav = targetField.getAnnotation(EdmNavigationProperty.class);
+ final String targetAssociation = extractRelationshipName(targetNav, targetField);
+ if (sourceAssociation.equals(targetAssociation)) {
+ return new AnnotatedNavInfo(sourceField, targetField, sourceNav, targetNav);
+ }
+ }
+ }
+
+ // if nothing was found assume none bi-directinal navigation
+ String targetEntityTypeName = extractEntityTypeName(targetClass);
+ for (Field sourceField : sourceFields) {
+ final EdmNavigationProperty sourceNav = sourceField.getAnnotation(EdmNavigationProperty.class);
+ final String navTargetEntityName = extractEntitTypeName(sourceNav, sourceField);
+
+ if (navTargetEntityName.equals(targetEntityTypeName)) {
+ return new AnnotatedNavInfo(sourceField, null, sourceNav, null);
+ }
+ }
+
+ return null;
+ }
+
+ public Class<?> getFieldTypeForProperty(Object instance, String propertyName) throws ODataAnnotationException {
+ if (instance == null) {
+ return null;
+ }
+
+ Field field = getFieldForPropertyName(instance, propertyName, instance.getClass(), true);
+ if (field == null) {
+ throw new ODataAnnotationException("No field for property '" + propertyName
+ + "' found at class '" + instance.getClass() + "'.");
+ }
+ return field.getType();
+ }
+
+ public Object getValueForProperty(Object instance, String propertyName) throws ODataAnnotationException {
+ if (instance == null) {
+ return null;
+ }
+
+ Field field = getFieldForPropertyName(instance, propertyName, instance.getClass(), true);
+ if (field == null) {
+ throw new ODataAnnotationException("No field for property '" + propertyName
+ + "' found at class '" + instance.getClass() + "'.");
+ }
+ return getFieldValue(instance, field);
+ }
+
+ public void setValueForProperty(Object instance, String propertyName, Object propertyValue) {
+ if (instance != null) {
+ Field field = getFieldForPropertyName(instance, propertyName, instance.getClass(), true);
+ if (field != null) {
+ setFieldValue(instance, field, propertyValue);
+ }
+ }
+ }
+
+ private Field getFieldForPropertyName(Object instance, String propertyName,
+ Class<?> resultClass, boolean inherited) {
+ if (instance == null) {
+ return null;
+ }
+
+ Field[] fields = resultClass.getDeclaredFields();
+ for (Field field : fields) {
+ EdmProperty property = field.getAnnotation(EdmProperty.class);
+ if (property != null) {
+ if (property.name().isEmpty() && getCanonicalName(field).equals(propertyName)) {
+ return field;
+ } else if (property.name().equals(propertyName)) {
+ return field;
+ }
+ }
+ }
+
+ Class<?> superClass = resultClass.getSuperclass();
+ if (inherited && superClass != Object.class) {
+ return getFieldForPropertyName(instance, propertyName, superClass, true);
+ }
+
+ return null;
+ }
+
+ public Object getValueForField(Object instance, String fieldName, Class<? extends Annotation> annotation) {
+ if (instance == null) {
+ return null;
+ }
+ return getValueForField(instance, fieldName, instance.getClass(), annotation, true);
+ }
+
+ public Object getValueForField(Object instance, Class<? extends Annotation> annotation) {
+ if (instance == null) {
+ return null;
+ }
+ return getValueForField(instance, instance.getClass(), annotation, true);
+ }
+
+ private Object getValueForField(Object instance, Class<?> resultClass,
+ Class<? extends Annotation> annotation, boolean inherited) {
+ return getValueForField(instance, null, resultClass, annotation, inherited);
+ }
+
+ public Map<String, Object> getValueForAnnotatedFields(Object instance,
+ Class<? extends Annotation> annotation) {
+ return getValueForAnnotatedFields(instance, instance.getClass(), annotation, true);
+ }
+
+ private Map<String, Object> getValueForAnnotatedFields(Object instance, Class<?> resultClass,
+ Class<? extends Annotation> annotation, boolean inherited) {
+ if (instance == null) {
+ return null;
+ }
+
+ Field[] fields = resultClass.getDeclaredFields();
+ Map<String, Object> fieldName2Value = new HashMap<String, Object>();
+
+ for (Field field : fields) {
+ if (field.getAnnotation(annotation) != null) {
+ Object value = getFieldValue(instance, field);
+ final EdmProperty property = field.getAnnotation(EdmProperty.class);
+ final String name = property == null || property.name().isEmpty() ? field.getName() : property.name();
+ fieldName2Value.put(name, value);
+ }
+ }
+
+ Class<?> superClass = resultClass.getSuperclass();
+ if (inherited && superClass != Object.class) {
+ Map<String, Object> tmp = getValueForAnnotatedFields(instance, superClass, annotation, true);
+ fieldName2Value.putAll(tmp);
+ }
+
+ return fieldName2Value;
+ }
+
+ public void setValueForAnnotatedField(Object instance, Class<? extends Annotation> annotation, Object value)
+ throws ODataAnnotationException {
+ List<Field> fields = getAnnotatedFields(instance, annotation);
+
+ if(fields.isEmpty()) {
+ throw new ODataAnnotationException("No field found for annotation '" + annotation
+ + "' on instance '" + instance + "'.");
+ } else if(fields.size() > 1) {
+ throw new ODataAnnotationException("More then one field found for annotation '" + annotation
+ + "' on instance '" + instance + "'.");
+ }
+
+ setFieldValue(instance, fields.get(0), value);
+ }
+
+ public void setValuesToAnnotatedFields(Object instance,
+ Class<? extends Annotation> annotation, Map<String, Object> fieldName2Value) {
+ List<Field> fields = getAnnotatedFields(instance, annotation);
+
+ // XXX: refactore
+ for (Field field : fields) {
+ final String canonicalName = getCanonicalName(field);
+ if (fieldName2Value.containsKey(canonicalName)) {
+ Object value = fieldName2Value.get(canonicalName);
+ setFieldValue(instance, field, value);
+ }
+ }
+ }
+
+ public List<Field> getAnnotatedFields(Object instance, Class<? extends Annotation> annotation) {
+ if (instance == null) {
+ return null;
+ }
+ return getAnnotatedFields(instance.getClass(), annotation, true);
+ }
+
+ public List<Field> getAnnotatedFields(Class<?> fieldClass, Class<? extends Annotation> annotation) {
+ return getAnnotatedFields(fieldClass, annotation, true);
+ }
+
+ /**
+ *
+ * @param instance
+ * @param resultClass
+ * @param annotation
+ * @param inherited
+ * @return
+ */
+ private List<Field> getAnnotatedFields(Class<?> resultClass,
+ Class<? extends Annotation> annotation, boolean inherited) {
+ if (resultClass == null) {
+ return null;
+ }
+
+ Field[] fields = resultClass.getDeclaredFields();
+ List<Field> annotatedFields = new ArrayList<Field>();
+
+ for (Field field : fields) {
+ if (field.getAnnotation(annotation) != null) {
+ annotatedFields.add(field);
+ }
+ }
+
+ Class<?> superClass = resultClass.getSuperclass();
+ if (inherited && superClass != Object.class) {
+ List<Field> tmp = getAnnotatedFields(superClass, annotation, true);
+ annotatedFields.addAll(tmp);
+ }
+
+ return annotatedFields;
+ }
+
+ private Object getValueForField(Object instance, String fieldName, Class<?> resultClass,
+ Class<? extends Annotation> annotation, boolean inherited) {
+ if (instance == null) {
+ return null;
+ }
+
+ Field[] fields = resultClass.getDeclaredFields();
+ for (Field field : fields) {
+ if (field.getAnnotation(annotation) != null
+ && (fieldName == null || field.getName().equals(fieldName))) {
+ return getFieldValue(instance, field);
+ }
+ }
+
+ Class<?> superClass = resultClass.getSuperclass();
+ if (inherited && superClass != Object.class) {
+ return getValueForField(instance, fieldName, superClass, annotation, true);
+ }
+
+ return null;
+ }
+
+ private Object getFieldValue(Object instance, Field field) {
+ try {
+ boolean access = field.isAccessible();
+ field.setAccessible(true);
+ Object value = field.get(instance);
+ field.setAccessible(access);
+ return value;
+ } catch (IllegalArgumentException ex) { // should never happen
+ throw new ODataRuntimeException(ex);
+ } catch (IllegalAccessException ex) { // should never happen
+ throw new ODataRuntimeException(ex);
+ }
+ }
+
+ private void setFieldValue(Object instance, Field field, Object value) {
+ try {
+ Object usedValue = value;
+ if (value != null
+ && field.getType() != value.getClass()
+ && value.getClass() == String.class) {
+ usedValue = convert(field, (String) value);
+ }
+ boolean access = field.isAccessible();
+ field.setAccessible(true);
+ field.set(instance, usedValue);
+ field.setAccessible(access);
+ } catch (IllegalArgumentException ex) { // should never happen
+ throw new ODataRuntimeException(ex);
+ } catch (IllegalAccessException ex) { // should never happen
+ throw new ODataRuntimeException(ex);
+ }
+ }
+
+ public Object convert(Field field, String propertyValue) {
+ Class<?> fieldClass = field.getType();
+ try {
+ EdmProperty property = field.getAnnotation(EdmProperty.class);
+ EdmSimpleTypeKind type = mapTypeKind(property.type());
+ return type.getEdmSimpleTypeInstance().valueOfString(propertyValue,
+ EdmLiteralKind.DEFAULT, null, fieldClass);
+ } catch (EdmSimpleTypeException ex) {
+ throw new ODataRuntimeException("Conversion failed for string property with error: "
+ + ex.getMessage(), ex);
+ }
+ }
+
+ public boolean isEdmAnnotated(Object object) {
+ if (object == null) {
+ return false;
+ }
+ return isEdmAnnotated(object.getClass());
+ }
+
+ public boolean isEdmTypeAnnotated(Class<?> clazz) {
+ boolean isComplexEntity = clazz.getAnnotation(EdmComplexType.class) != null;
+ boolean isEntity = clazz.getAnnotation(EdmEntityType.class) != null;
+ return isComplexEntity || isEntity;
+ }
+
+ public boolean isEdmAnnotated(Class<?> clazz) {
+ if (clazz == null) {
+ return false;
+ } else {
+ final boolean isEntity = null != clazz.getAnnotation(EdmEntityType.class);
+ final boolean isEntitySet = null != clazz.getAnnotation(EdmEntitySet.class);
+ final boolean isComplexEntity = null != clazz.getAnnotation(EdmComplexType.class);
+ return isEntity || isComplexEntity || isEntitySet;
+ }
+ }
+
+ public String getCanonicalName(Field field) {
+ return firstCharToUpperCase(field.getName());
+ }
+
+ public String getCanonicalName(Class<?> clazz) {
+ return firstCharToUpperCase(clazz.getSimpleName());
+ }
+
+ private String firstCharToUpperCase(String content) {
+ if (content == null || content.isEmpty()) {
+ return content;
+ }
+ return content.substring(0, 1).toUpperCase(Locale.ENGLISH) + content.substring(1);
+ }
+
+ public EdmSimpleTypeKind mapTypeKind(org.apache.olingo.odata2.api.annotation.edm.EdmType type) {
+ switch (type) {
+ case BINARY: return EdmSimpleTypeKind.Binary;
+ case BOOLEAN: return EdmSimpleTypeKind.Boolean;
+ case BYTE: return EdmSimpleTypeKind.Byte;
+ case COMPLEX: return EdmSimpleTypeKind.Null;
+ case DATE_TIME: return EdmSimpleTypeKind.DateTime;
+ case DATE_TIME_OFFSET: return EdmSimpleTypeKind.DateTimeOffset;
+ case DECIMAL: return EdmSimpleTypeKind.Decimal;
+ case DOUBLE: return EdmSimpleTypeKind.Double;
+ case GUID: return EdmSimpleTypeKind.Guid;
+ case INT16: return EdmSimpleTypeKind.Int16;
+ case INT32: return EdmSimpleTypeKind.Int32;
+ case INT64: return EdmSimpleTypeKind.Int64;
+ case NULL: return EdmSimpleTypeKind.Null;
+ case SBYTE: return EdmSimpleTypeKind.SByte;
+ case SINGLE: return EdmSimpleTypeKind.Single;
+ case STRING: return EdmSimpleTypeKind.String;
+ case TIME: return EdmSimpleTypeKind.Time;
+ default: throw new ODataRuntimeException("Unknown type '" + type
+ + "' for mapping to EdmSimpleTypeKind.");
+ }
+ }
+
+ public EdmMultiplicity mapMultiplicity(Multiplicity multiplicity) {
+ switch (multiplicity) {
+ case ZERO_OR_ONE: return EdmMultiplicity.ZERO_TO_ONE;
+ case ONE: return EdmMultiplicity.ONE;
+ case MANY: return EdmMultiplicity.MANY;
+ default: throw new ODataRuntimeException("Unknown type '" + multiplicity + "' for mapping to EdmMultiplicity.");
+ }
+ }
+
+ /**
+ *
+ */
+ private static class EdmAnnotationException extends RuntimeException {
+
+ private static final long serialVersionUID = 42L;
+
+ public EdmAnnotationException(String message) {
+ super(message);
+ }
+ }
+
+ public String getCanonicalNamespace(Class<?> aClass) {
+ return generateNamespace(aClass);
+ }
+
+ public String extractContainerName(Class<?> aClass) {
+ EdmEntitySet entitySet = aClass.getAnnotation(EdmEntitySet.class);
+ if(entitySet != null) {
+ String containerName = entitySet.container();
+ if(!containerName.isEmpty()) {
+ return containerName;
+ }
+ }
+ return DEFAULT_CONTAINER_NAME;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/core/annotation/util/ClassHelper.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/core/annotation/util/ClassHelper.java b/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/core/annotation/util/ClassHelper.java
new file mode 100644
index 0000000..5e9fcdb
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-core/src/main/java/org/apache/olingo/odata2/core/annotation/util/ClassHelper.java
@@ -0,0 +1,105 @@
+/*******************************************************************************
+ * 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.core.annotation.util;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.io.FilenameFilter;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ *
+ */
+public class ClassHelper {
+
+ private static final File[] EMPTY_FILE_ARRAY = new File[0];
+
+ private static final FilenameFilter CLASSFILE_FILTER = new FilenameFilter() {
+ @Override
+ public boolean accept(File dir, String name) {
+ return name.endsWith(CLASSFILE_ENDING);
+ }
+ public static final String CLASSFILE_ENDING = ".class";
+ };
+
+ private static final FileFilter FOLDER_FILTER = new FileFilter() {
+ @Override
+ public boolean accept(File pathname) {
+ return pathname.isDirectory();
+ }
+ };
+
+ public static final List<Class<?>> loadClasses(String packageToScan, ClassValidator cv) {
+ return loadClasses(packageToScan, CLASSFILE_FILTER, cv);
+ }
+
+
+ public static final List<Class<?>> loadClasses(String packageToScan, FilenameFilter ff, ClassValidator cv) {
+ final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ String folderToScan = packageToScan.replace(".", "/");
+ URL url = classLoader.getResource(folderToScan);
+ if(url == null) {
+ throw new IllegalArgumentException("No folder to scan found for package '" + packageToScan + "'.");
+ }
+ File folder = new File(url.getFile());
+ File[] classFiles = folder.listFiles(ff);
+ if(classFiles == null) {
+ classFiles = EMPTY_FILE_ARRAY;
+ }
+
+ List<Class<?>> annotatedClasses = new ArrayList<Class<?>>(classFiles.length);
+ for (File file : classFiles) {
+ String name = file.getName();
+ String fqn = packageToScan + "." + name.substring(0, name.length() - 6);
+ try {
+ Class<?> c = classLoader.loadClass(fqn);
+ if (cv.isClassValid(c)) {
+ annotatedClasses.add(c);
+ }
+ } catch (ClassNotFoundException ex) {
+ throw new IllegalArgumentException("Exception during class loading of class '" + fqn +
+ "' with message '" + ex.getMessage() + "'.");
+ }
+ }
+
+ // recursive search
+ File[] subfolders = listSubFolder(folder);
+ for (File file : subfolders) {
+ List<Class<?>> subFolderClazzes = loadClasses(packageToScan + "." + file.getName(), ff, cv);
+ annotatedClasses.addAll(subFolderClazzes);
+ }
+ //
+
+ return annotatedClasses;
+ }
+
+ private static File[] listSubFolder(File folder) {
+ File[] subfolders = folder.listFiles(FOLDER_FILTER);
+ if(subfolders == null) {
+ return EMPTY_FILE_ARRAY;
+ }
+ return subfolders;
+ }
+
+ public interface ClassValidator {
+ boolean isClassValid(Class<?> c);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/data/AnnotationsInMemoryDsTest.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/data/AnnotationsInMemoryDsTest.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/data/AnnotationsInMemoryDsTest.java
new file mode 100644
index 0000000..04dbefc
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/data/AnnotationsInMemoryDsTest.java
@@ -0,0 +1,190 @@
+/*
+ * Copyright 2013 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * 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.core.annotation.data;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.olingo.odata2.api.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.edm.FullQualifiedName;
+import org.apache.olingo.odata2.api.edm.provider.EntitySet;
+import org.apache.olingo.odata2.api.exception.ODataException;
+import org.apache.olingo.odata2.core.annotation.edm.AnnotationEdmProvider;
+import org.apache.olingo.odata2.core.annotation.model.Building;
+import org.apache.olingo.odata2.core.annotation.model.ModelSharedConstants;
+import org.apache.olingo.odata2.core.annotation.model.Photo;
+import org.apache.olingo.odata2.core.annotation.util.AnnotationHelper;
+import org.junit.Assert;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+/**
+ *
+ */
+public class AnnotationsInMemoryDsTest {
+
+ private final AnnotationInMemoryDs datasource;
+ private AnnotationEdmProvider edmProvider;
+ private static final String DEFAULT_CONTAINER = ModelSharedConstants.CONTAINER_1;
+
+ public AnnotationsInMemoryDsTest() {
+ datasource = new AnnotationInMemoryDs(Building.class.getPackage().getName(), false);
+ edmProvider = new AnnotationEdmProvider(Building.class.getPackage().getName());
+ }
+
+ @Test
+ public void createSimpleEntity() throws Exception {
+ EdmEntitySet edmEntitySet = createMockedEdmEntitySet("Buildings");
+
+ Building building = new Building();
+ building.setName("Common Building");
+ datasource.createData(edmEntitySet, building);
+
+ Map<String, Object> keys = new HashMap<String, Object>();
+ keys.put("Id", "1");
+
+ Building read = (Building) datasource.readData(edmEntitySet, keys);
+ Assert.assertEquals("Common Building", read.getName());
+ Assert.assertEquals("1", read.getId());
+ }
+
+
+ @Test
+ public void createSimpleEntityWithOwnKey() throws Exception {
+ EdmEntitySet edmEntitySet = createMockedEdmEntitySet("Buildings");
+
+ Building building = new Building();
+ building.setName("Common Building");
+ AnnotationHelper ah = new AnnotationHelper();
+ ah.setValueForProperty(building, "Id", "42");
+ datasource.createData(edmEntitySet, building);
+
+ Map<String, Object> keys = new HashMap<String, Object>();
+ keys.put("Id", "42");
+
+ Building read = (Building) datasource.readData(edmEntitySet, keys);
+ Assert.assertEquals("Common Building", read.getName());
+ Assert.assertEquals("42", read.getId());
+ }
+
+ @Test
+ public void createSimpleEntityWithDuplicateKey() throws Exception {
+ EdmEntitySet edmEntitySet = createMockedEdmEntitySet("Buildings");
+ AnnotationHelper ah = new AnnotationHelper();
+
+ Building building = new Building();
+ building.setName("Common Building");
+ ah.setValueForProperty(building, "Id", "42");
+ datasource.createData(edmEntitySet, building);
+ //
+ Building buildingDuplicate = new Building();
+ buildingDuplicate.setName("Duplicate Building");
+ ah.setValueForProperty(buildingDuplicate, "Id", "42");
+ datasource.createData(edmEntitySet, buildingDuplicate);
+
+ Map<String, Object> keys42 = new HashMap<String, Object>();
+ keys42.put("Id", "42");
+ Building read42 = (Building) datasource.readData(edmEntitySet, keys42);
+ Assert.assertEquals("Common Building", read42.getName());
+ Assert.assertEquals("42", read42.getId());
+
+ Map<String, Object> keys = new HashMap<String, Object>();
+ keys.put("Id", "1");
+ Building read = (Building) datasource.readData(edmEntitySet, keys);
+ Assert.assertEquals("Duplicate Building", read.getName());
+ Assert.assertEquals("1", read.getId());
+}
+
+
+ @Test
+ public void createEntityTwoKeys() throws Exception {
+ EdmEntitySet edmEntitySet = createMockedEdmEntitySet("Photos");
+
+ Photo photo = new Photo();
+ photo.setName("BigPicture");
+ photo.setType("PNG");
+ photo.setImageUri("https://localhost/image.png");
+ photo.setImageType("image/png");
+ datasource.createData(edmEntitySet, photo);
+
+ Map<String, Object> keys = new HashMap<String, Object>();
+ keys.put("ImageFormat", "PNG");
+ keys.put("Name", "BigPicture");
+
+ Photo read = (Photo) datasource.readData(edmEntitySet, keys);
+ Assert.assertEquals("BigPicture", read.getName());
+ Assert.assertEquals("PNG", read.getType());
+ Assert.assertEquals("image/png", read.getImageType());
+ Assert.assertEquals("https://localhost/image.png", read.getImageUri());
+ }
+
+ @Test
+ // @Ignore("Rethink update method")
+ public void createAndUpdateEntityTwoKeys() throws Exception {
+ EdmEntitySet edmEntitySet = createMockedEdmEntitySet("Photos");
+
+ Photo photo = new Photo();
+ final String nameKeyValue = "BigPicture";
+ final String typeKeyValue = "PNG";
+ photo.setName(nameKeyValue);
+ photo.setType(typeKeyValue);
+ photo.setImageUri("https://localhost/image.png");
+ photo.setImageType("image/png");
+ datasource.createData(edmEntitySet, photo);
+
+ Map<String, Object> keys = new HashMap<String, Object>();
+ keys.put("Name", "BigPicture");
+ keys.put("ImageFormat", "PNG");
+
+ Photo read = (Photo) datasource.readData(edmEntitySet, keys);
+ Assert.assertEquals("BigPicture", read.getName());
+ Assert.assertEquals("PNG", read.getType());
+ Assert.assertEquals("image/png", read.getImageType());
+ Assert.assertEquals("https://localhost/image.png", read.getImageUri());
+
+ // update
+ Photo updatedPhoto = new Photo();
+ updatedPhoto.setName(nameKeyValue);
+ updatedPhoto.setType(typeKeyValue);
+ updatedPhoto.setImageUri("https://localhost/image.jpg");
+ updatedPhoto.setImageType("image/jpg");
+ datasource.updateData(edmEntitySet, updatedPhoto);
+
+ Map<String, Object> updatedKeys = new HashMap<String, Object>();
+ updatedKeys.put("Name", nameKeyValue);
+ updatedKeys.put("ImageFormat", typeKeyValue);
+
+ Photo readUpdated = (Photo) datasource.readData(edmEntitySet, updatedKeys);
+ Assert.assertEquals("BigPicture", readUpdated.getName());
+ Assert.assertEquals("PNG", readUpdated.getType());
+ Assert.assertEquals("image/jpg", readUpdated.getImageType());
+ Assert.assertEquals("https://localhost/image.jpg", readUpdated.getImageUri());
+ }
+
+ private EdmEntitySet createMockedEdmEntitySet(String entitySetName) throws ODataException {
+ EntitySet entitySet = edmProvider.getEntitySet(DEFAULT_CONTAINER, entitySetName);
+ FullQualifiedName entityType = entitySet.getEntityType();
+
+ EdmEntitySet edmEntitySet = Mockito.mock(EdmEntitySet.class);
+ Mockito.when(edmEntitySet.getName()).thenReturn(entitySetName);
+ EdmEntityType edmEntityType = Mockito.mock(EdmEntityType.class);
+ Mockito.when(edmEntitySet.getEntityType()).thenReturn(edmEntityType);
+ Mockito.when(edmEntityType.getName()).thenReturn(entityType.getName());
+
+ return edmEntitySet;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProviderTest.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProviderTest.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProviderTest.java
new file mode 100644
index 0000000..494a090
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProviderTest.java
@@ -0,0 +1,463 @@
+/*
+ * Copyright 2013 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * 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.core.annotation.edm;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.olingo.odata2.api.annotation.edm.EdmComplexType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
+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.ComplexType;
+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.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.Schema;
+import org.apache.olingo.odata2.api.exception.ODataException;
+import org.apache.olingo.odata2.core.annotation.model.Building;
+import org.apache.olingo.odata2.core.annotation.model.City;
+import org.apache.olingo.odata2.core.annotation.model.Employee;
+import org.apache.olingo.odata2.core.annotation.model.Location;
+import org.apache.olingo.odata2.core.annotation.model.Manager;
+import org.apache.olingo.odata2.core.annotation.model.ModelSharedConstants;
+import org.apache.olingo.odata2.core.annotation.model.Photo;
+import org.apache.olingo.odata2.core.annotation.model.RefBase;
+import org.apache.olingo.odata2.core.annotation.model.Room;
+import org.apache.olingo.odata2.core.annotation.model.Team;
+import org.junit.Test;
+
+/**
+ *
+ */
+public class AnnotationEdmProviderTest {
+
+ @EdmEntityType
+ @EdmEntitySet
+ private static final class GeneratedNamesTestClass {}
+
+ @EdmComplexType
+ private static final class GeneratedNamesComplexTestClass {}
+
+ @EdmEntityType(namespace="MyTestNamespace")
+ @EdmEntitySet(container="MyTestContainer")
+ private static final class DefinedNamesTestClass {}
+
+ private final AnnotationEdmProvider aep;
+ private final Collection<Class<?>> annotatedClasses = new ArrayList<Class<?>>();
+
+ public AnnotationEdmProviderTest() {
+ annotatedClasses.add(RefBase.class);
+ annotatedClasses.add(Building.class);
+ annotatedClasses.add(City.class);
+ annotatedClasses.add(Employee.class);
+ annotatedClasses.add(Location.class);
+ annotatedClasses.add(Manager.class);
+ annotatedClasses.add(Photo.class);
+ annotatedClasses.add(Room.class);
+ annotatedClasses.add(Team.class);
+
+ aep = new AnnotationEdmProvider(annotatedClasses);
+ }
+
+ @Test
+ public void defaultNamespaceGeneration() throws ODataException {
+ Collection<Class<?>> localAnnotatedClasses = new ArrayList<Class<?>>();
+ localAnnotatedClasses.add(GeneratedNamesTestClass.class);
+ AnnotationEdmProvider localAep = new AnnotationEdmProvider(localAnnotatedClasses);
+ // validate
+ EntityType testType = localAep.getEntityType(new FullQualifiedName(
+ GeneratedNamesTestClass.class.getPackage().getName(),
+ GeneratedNamesTestClass.class.getSimpleName()));
+ assertNotNull("Requested entity not found.", testType);
+ assertEquals("GeneratedNamesTestClass", testType.getName());
+ assertNull("This should not have a base type", testType.getBaseType());
+ }
+
+ @Test
+ public void defaultNamespaceGenerationComplexType() throws ODataException {
+ Collection<Class<?>> localAnnotatedClasses = new ArrayList<Class<?>>();
+ localAnnotatedClasses.add(GeneratedNamesComplexTestClass.class);
+ AnnotationEdmProvider localAep = new AnnotationEdmProvider(localAnnotatedClasses);
+ // validate
+ ComplexType testType = localAep.getComplexType(new FullQualifiedName(
+ GeneratedNamesComplexTestClass.class.getPackage().getName(),
+ GeneratedNamesComplexTestClass.class.getSimpleName()));
+ assertNotNull("Requested entity not found.", testType);
+ assertEquals("GeneratedNamesComplexTestClass", testType.getName());
+ assertNull("This should not have a base type", testType.getBaseType());
+ }
+
+ @Test
+ public void defaultContainerNameGeneration() throws ODataException {
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ AnnotationEdmProvider localAep =
+ new AnnotationEdmProvider((Collection) Arrays.asList(GeneratedNamesTestClass.class));
+
+ EntityContainerInfo containerInfo = localAep.getEntityContainerInfo(null);
+ assertNotNull(containerInfo);
+ assertEquals("DefaultContainer", containerInfo.getName());
+ }
+
+
+ @Test
+ public void defaultNamespaceDefined() throws ODataException {
+ Collection<Class<?>> localAnnotatedClasses = new ArrayList<Class<?>>();
+ localAnnotatedClasses.add(DefinedNamesTestClass.class);
+ AnnotationEdmProvider localAep = new AnnotationEdmProvider(localAnnotatedClasses);
+ // validate
+ EntityType testClass = localAep.getEntityType(new FullQualifiedName("MyTestNamespace",
+ DefinedNamesTestClass.class.getSimpleName()));
+ assertNotNull("Requested entity not found.", testClass);
+ assertEquals("DefinedNamesTestClass", testClass.getName());
+ assertNull("This should not have a base type", testClass.getBaseType());
+ }
+
+ @Test
+ public void defaultContainerNameDefined() throws ODataException {
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ AnnotationEdmProvider localAep = new AnnotationEdmProvider((Collection) Arrays.asList(DefinedNamesTestClass.class));
+
+ EntityContainerInfo containerInfo = localAep.getEntityContainerInfo(null);
+ assertNotNull(containerInfo);
+ assertEquals("MyTestContainer", containerInfo.getName());
+ }
+
+ @Test
+ public void loadAnnotatedClassesFromPackage() throws Exception {
+ AnnotationEdmProvider localAep = new AnnotationEdmProvider("org.apache.olingo.odata2.core.annotation.model");
+
+ // validate employee
+ EntityType employee = localAep.getEntityType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "Employee"));
+ assertEquals("Employee", employee.getName());
+ final List<PropertyRef> employeeKeys = employee.getKey().getKeys();
+ assertEquals(1, employeeKeys.size());
+ assertEquals("EmployeeId", employeeKeys.get(0).getName());
+ assertEquals(6, employee.getProperties().size());
+ assertEquals(3, employee.getNavigationProperties().size());
+
+ List<Schema> schemas = localAep.getSchemas();
+ assertEquals(1, schemas.size());
+ EntityContainerInfo info = localAep.getEntityContainerInfo(ModelSharedConstants.CONTAINER_1);
+ assertTrue(info.isDefaultEntityContainer());
+ }
+
+ @Test
+ public void annotationProviderBasic() throws Exception {
+ assertNotNull(aep);
+
+ List<Schema> schemas = aep.getSchemas();
+ assertEquals(1, schemas.size());
+ EntityContainerInfo info = aep.getEntityContainerInfo(ModelSharedConstants.CONTAINER_1);
+ assertTrue(info.isDefaultEntityContainer());
+
+ FunctionImport funImp = aep.getFunctionImport(ModelSharedConstants.CONTAINER_1, "NoImport");
+ assertNull(funImp);
+
+ final FullQualifiedName associationFqn = new FullQualifiedName(
+ ModelSharedConstants.NAMESPACE_1, "NoAssociation");
+ Association noAssociation = aep.getAssociation(associationFqn);
+ assertNull(noAssociation);
+
+ AssociationSet noAssociationSet = aep.getAssociationSet(
+ ModelSharedConstants.CONTAINER_1, associationFqn, "NoSrc", "NoSrcEntity");
+ assertNull(noAssociationSet);
+
+ AssociationSet asBuildingRooms = aep.getAssociationSet(
+ ModelSharedConstants.CONTAINER_1, defaultFqn("BuildingRooms"), "Buildings", "r_Building");
+ assertNotNull(asBuildingRooms);
+ assertEquals("Buildings", asBuildingRooms.getEnd1().getEntitySet());
+ assertEquals("r_Building", asBuildingRooms.getEnd1().getRole());
+ assertEquals("Rooms", asBuildingRooms.getEnd2().getEntitySet());
+ assertEquals("r_Room", asBuildingRooms.getEnd2().getRole());
+ }
+
+ @Test
+ public void annotationProviderGetDefaultContainer() throws Exception {
+ assertNotNull(aep);
+
+ List<Schema> schemas = aep.getSchemas();
+ assertEquals(1, schemas.size());
+ EntityContainerInfo info = aep.getEntityContainerInfo(null);
+ assertTrue(info.isDefaultEntityContainer());
+ assertEquals(ModelSharedConstants.CONTAINER_1, info.getName());
+ }
+
+ @Test
+ public void schemaBasic() throws Exception {
+ assertNotNull(aep);
+
+ List<Schema> schemas = aep.getSchemas();
+ assertEquals(1, schemas.size());
+
+ Schema schema = schemas.get(0);
+ List<EntityContainer> containers = schema.getEntityContainers();
+ assertEquals(1, containers.size());
+ EntityContainer container = containers.get(0);
+ assertEquals(ModelSharedConstants.CONTAINER_1, container.getName());
+ final List<EntitySet> entitySets = container.getEntitySets();
+ assertEquals(6, entitySets.size());
+
+ List<Association> associations = schema.getAssociations();
+ assertEquals(4, associations.size());
+ for (Association association : associations) {
+ assertNotNull(association.getName());
+ validateAssociation(association);
+ }
+ }
+
+ private FullQualifiedName defaultFqn(String name) {
+ return new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, name);
+ }
+
+ private void validateAssociation(Association association) {
+ String name = association.getName();
+ if(name.equals("r_Employee-r_Room")) {
+ validateAssociation(association,
+ "r_Room", EdmMultiplicity.ONE, defaultFqn("Room"),
+ "r_Employee", EdmMultiplicity.MANY, defaultFqn("Employee"));
+ } else if(name.equals("BuildingRooms")) {
+ validateAssociation(association,
+ "r_Building", EdmMultiplicity.ONE, defaultFqn("Building"),
+ "r_Room", EdmMultiplicity.MANY, defaultFqn("Room"));
+ } else if(name.equals("ManagerEmployees")) {
+ validateAssociation(association,
+ "r_Manager", EdmMultiplicity.ONE, defaultFqn("Manager"),
+ "r_Employee", EdmMultiplicity.MANY, defaultFqn("Employee"));
+ } else if(name.equals("TeamEmployees")) {
+ validateAssociation(association,
+ "r_Team", EdmMultiplicity.ONE, defaultFqn("Team"),
+ "r_Employee", EdmMultiplicity.MANY, defaultFqn("Employee"));
+ } else {
+ fail("Got unknown association to validate with name '" + name + "'.");
+ }
+ }
+
+ private void validateAssociation(Association association,
+ String fromRole, EdmMultiplicity fromMulti, FullQualifiedName fromType,
+ String toRole, EdmMultiplicity toMulti, FullQualifiedName toType) {
+
+ AssociationEnd[] ends = new AssociationEnd[]{association.getEnd1(),association.getEnd2()};
+ for (AssociationEnd associationEnd : ends) {
+ if(associationEnd.getRole().equals(fromRole)) {
+ validateAssociationEnd(associationEnd, fromRole, fromMulti, fromType);
+ } else if(associationEnd.getRole().equals(toRole)) {
+ validateAssociationEnd(associationEnd, toRole, toMulti, toType);
+ } else {
+ fail("Unexpected navigation end '" + associationEnd.getRole()
+ + "' for association with name '" + association.getName() + "'.");
+ }
+ }
+ }
+
+ private void validateAssociationEnd(AssociationEnd associationEnd,
+ String role, EdmMultiplicity multiplicity, FullQualifiedName type) {
+ assertEquals(role, associationEnd.getRole());
+ assertEquals(multiplicity, associationEnd.getMultiplicity());
+ assertEquals(type, associationEnd.getType());
+ }
+
+
+ @Test
+ public void entitySetTeams() throws Exception {
+ // validate teams
+ EntitySet teams = aep.getEntitySet(ModelSharedConstants.CONTAINER_1, "Teams");
+ assertEquals(ModelSharedConstants.NAMESPACE_1, teams.getEntityType().getNamespace());
+ assertEquals("Team", teams.getEntityType().getName());
+ }
+
+ @Test
+ public void entityTypeEmployee() throws Exception {
+ // validate employee
+ EntityType employee = aep.getEntityType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "Employee"));
+ assertEquals("Employee", employee.getName());
+ final List<PropertyRef> employeeKeys = employee.getKey().getKeys();
+ assertEquals(1, employeeKeys.size());
+ assertEquals("EmployeeId", employeeKeys.get(0).getName());
+ assertEquals(6, employee.getProperties().size());
+ assertEquals(3, employee.getNavigationProperties().size());
+
+ for (NavigationProperty navigationProperty : employee.getNavigationProperties()) {
+ if (navigationProperty.getName().equals("ne_Manager")) {
+ validateNavProperty(navigationProperty, "ManagerEmployees", "r_Employee", "r_Manager");
+ } else if (navigationProperty.getName().equals("ne_Team")) {
+ validateNavProperty(navigationProperty, "TeamEmployees", "r_Employee", "r_Team");
+ } else if (navigationProperty.getName().equals("ne_Room")) {
+ validateNavProperty(navigationProperty, "r_Employee-r_Room", "r_Employee", "r_Room");
+ } else {
+ fail("Got unexpected navigation property with name '" + navigationProperty.getName() + "'.");
+ }
+ }
+}
+
+ @Test
+ public void entityTypeTeam() throws Exception {
+ // validate team
+ EntityType team = aep.getEntityType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "Team"));
+ assertEquals("Team", team.getName());
+ assertEquals("Base", team.getBaseType().getName());
+ assertEquals(ModelSharedConstants.NAMESPACE_1, team.getBaseType().getNamespace());
+
+ assertEquals(1, team.getProperties().size());
+ assertEquals(1, team.getNavigationProperties().size());
+ NavigationProperty navigationProperty= team.getNavigationProperties().get(0);
+ validateNavProperty(navigationProperty, "TeamEmployees", "r_Team", "r_Employee");
+ }
+
+ @Test
+ public void entityTypePhotoWithTwoKeyProperties() throws Exception {
+ // validate team
+ EntityType photo = aep.getEntityType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "Photo"));
+ assertEquals("Photo", photo.getName());
+ final List<Property> properties = photo.getProperties();
+ assertEquals(5, properties.size());
+ assertTrue(containsProperty(properties, "Name"));
+ assertTrue(containsProperty(properties, "ImageFormat"));
+ assertTrue(containsProperty(properties, "MimeType"));
+ assertTrue(containsProperty(properties, "ImageUrl"));
+ assertTrue(containsProperty(properties, "Image"));
+ assertFalse(photo.isAbstract());
+ assertTrue(photo.isHasStream());
+
+ Key photoKey = photo.getKey();
+ List<PropertyRef> keyReferences = photoKey.getKeys();
+ assertEquals(2, keyReferences.size());
+ PropertyRef name = getPropertyRef(keyReferences, "Name");
+ assertEquals("Name", name.getName());
+ PropertyRef imageFormat = getPropertyRef(keyReferences, "ImageFormat");
+ assertEquals("ImageFormat", imageFormat.getName());
+
+// assertEquals(0, photo.getNavigationProperties().size());
+ assertNull(photo.getNavigationProperties());
+ }
+
+ @Test
+ public void entityTypeAbstractBaseType() throws Exception {
+ // validate employee
+ EntityType baseType = aep.getEntityType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "Base"));
+ assertEquals("Base", baseType.getName());
+ final List<PropertyRef> keys = baseType.getKey().getKeys();
+ assertEquals(1, keys.size());
+ assertEquals("Id", keys.get(0).getName());
+ assertEquals(2, baseType.getProperties().size());
+ assertTrue(baseType.isAbstract());
+
+ // validate base for team
+ EntityType team = aep.getEntityType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "Team"));
+ assertEquals("Team", team.getName());
+ assertEquals("Base", team.getBaseType().getName());
+ assertEquals(ModelSharedConstants.NAMESPACE_1, team.getBaseType().getNamespace());
+ }
+
+ @Test
+ public void complexTypeLocation() throws Exception {
+ // validate employee
+ EntityType employee = aep.getEntityType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "Employee"));
+ final List<Property> properties = employee.getProperties();
+ Property location = null;
+ for (Property property : properties) {
+ if (property.getName().equals("Location")) {
+ location = property;
+ }
+ }
+ assertNotNull(location);
+ assertEquals("Location", location.getName());
+
+ // validate location complex type
+ ComplexType locationType = aep.getComplexType(
+ new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "c_Location"));
+ assertEquals("c_Location", locationType.getName());
+ assertEquals(2, locationType.getProperties().size());
+ }
+
+ @Test
+ public void entityTypeRoomWithNavigation() throws Exception {
+ // validate employee
+ EntityType room = aep.getEntityType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "Room"));
+ assertEquals("Room", room.getName());
+ assertEquals("Base", room.getBaseType().getName());
+ assertEquals(2, room.getProperties().size());
+ final List<NavigationProperty> navigationProperties = room.getNavigationProperties();
+ assertEquals(2, navigationProperties.size());
+
+ for (NavigationProperty navigationProperty : navigationProperties) {
+ if(navigationProperty.getName().equals("nr_Employees")) {
+ validateNavProperty(navigationProperty, "r_Employee-r_Room", "r_Room", "r_Employee");
+ } else if(navigationProperty.getName().equals("nr_Building")) {
+ validateNavProperty(navigationProperty, "BuildingRooms", "r_Room", "r_Building");
+ } else {
+ fail("Got unexpected navigation property with name '" + navigationProperty.getName() + "'.");
+ }
+ }
+ }
+
+ private void validateNavProperty(NavigationProperty navigationProperty, String name,
+ String relationship, String fromRole, String toRole) {
+ if(name != null) {
+ assertEquals(name, navigationProperty.getName());
+ }
+ FullQualifiedName fqn = new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, relationship);
+ assertEquals("Wrong relationship for navigation property.", fqn, navigationProperty.getRelationship());
+ assertEquals("Wrong fromRole for navigation property.", fromRole, navigationProperty.getFromRole());
+ assertEquals("Wrong toRole for navigation property.", toRole, navigationProperty.getToRole());
+ }
+
+ private void validateNavProperty(NavigationProperty navigationProperty,
+ String relationship, String fromRole, String toRole) {
+ validateNavProperty(navigationProperty, null, relationship, fromRole, toRole);
+ }
+
+ private boolean containsProperty(List<Property> properties, String propertyName) {
+ return getProperty(properties, propertyName) != null;
+ }
+
+ private Property getProperty(List<Property> properties, String name) {
+ for (Property property : properties) {
+ if(name.equals(property.getName())) {
+ return property;
+ }
+ }
+ return null;
+ }
+
+ private PropertyRef getPropertyRef(List<PropertyRef> properties, String name) {
+ for (PropertyRef property : properties) {
+ if(name.equals(property.getName())) {
+ return property;
+ }
+ }
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Building.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Building.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Building.java
new file mode 100644
index 0000000..737b5e2
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Building.java
@@ -0,0 +1,95 @@
+/*******************************************************************************
+ * 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.core.annotation.model;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
+import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty.Multiplicity;
+import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmType;
+
+/**
+ *
+ */
+@EdmEntityType(name = "Building", namespace = ModelSharedConstants.NAMESPACE_1)
+@EdmEntitySet(name = "Buildings")
+public class Building {
+ @EdmKey
+ @EdmProperty(type = EdmType.INT32)
+ private String id;
+ @EdmProperty
+ private String name;
+ @EdmProperty(name = "Image", type = EdmType.BINARY)
+ private byte[] image;
+ @EdmNavigationProperty(name = "nb_Rooms", toType = Room.class,
+ association = "BuildingRooms", toMultiplicity = Multiplicity.MANY)
+ private List<Room> rooms = new ArrayList<Room>();
+
+ public Building() {}
+
+ public String getId() {
+ return id;
+ }
+
+ public void setName(final String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setImage(final byte[] byteArray) {
+ image = byteArray;
+ }
+
+ public byte[] getImage() {
+ if (image == null) {
+ return null;
+ } else {
+ return image.clone();
+ }
+ }
+
+ public List<Room> getRooms() {
+ return rooms;
+ }
+
+ @Override
+ public int hashCode() {
+ return id == null ? 0 : id.hashCode();
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ return this == obj
+ || obj != null && getClass() == obj.getClass() && id == ((Building) obj).id;
+ }
+
+ @Override
+ public String toString() {
+ return "{\"Id\":\"" + id + "\",\"Name\":\"" + name + "\",\"Image\":\"" + Arrays.toString(image) + "\"}";
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/City.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/City.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/City.java
new file mode 100644
index 0000000..7b866a3
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/City.java
@@ -0,0 +1,62 @@
+/*******************************************************************************
+ * 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.core.annotation.model;
+
+import org.apache.olingo.odata2.api.annotation.edm.EdmComplexType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
+
+
+/**
+ *
+ */
+@EdmComplexType(name="c_City", namespace = ModelSharedConstants.NAMESPACE_1)
+public class City {
+
+ @EdmProperty
+ private String postalCode;
+ @EdmProperty
+ private String cityName;
+
+ public City(final String postalCode, final String name) {
+ this.postalCode = postalCode;
+ cityName = name;
+ }
+
+ public void setPostalCode(final String postalCode) {
+ this.postalCode = postalCode;
+ }
+
+ public String getPostalCode() {
+ return postalCode;
+ }
+
+ public void setCityName(final String cityName) {
+ this.cityName = cityName;
+ }
+
+ public String getCityName() {
+ return cityName;
+ }
+
+ @Override
+ public String toString() {
+ return String.format("%s, %s", cityName, postalCode);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Employee.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Employee.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Employee.java
new file mode 100644
index 0000000..63b8a76
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Employee.java
@@ -0,0 +1,187 @@
+/*******************************************************************************
+ * 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.core.annotation.model;
+
+import java.text.DateFormat;
+import java.util.Calendar;
+
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
+import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceContent;
+import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceMimeType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmType;
+
+/**
+ *
+ */
+@EdmEntityType(name = "Employee", namespace = ModelSharedConstants.NAMESPACE_1)
+@EdmEntitySet(name = "Employees")
+public class Employee {
+ @EdmKey
+ @EdmProperty(name = "EmployeeId", type = EdmType.STRING)
+ private String employeeId;
+ @EdmProperty(name = "EmployeeName")
+ private String employeeName;
+ @EdmProperty
+ private int age;
+ @EdmNavigationProperty(name = "ne_Manager", association = "ManagerEmployees")
+ private Manager manager;
+ @EdmNavigationProperty(name = "ne_Team", association = "TeamEmployees")
+ private Team team;
+ @EdmNavigationProperty(name = "ne_Room")
+ private Room room;
+ @EdmMediaResourceMimeType
+ private String imageType;
+ @EdmMediaResourceContent
+ private byte[] image;
+ @EdmProperty(name = "ImageUrl")
+ private String imageUrl;
+ @EdmProperty(name = "EntryDate", type = EdmType.DATE_TIME)
+ private Calendar entryDate;
+ @EdmProperty(name = "Location")
+ private Location location;
+
+ public Employee(final String employeeId, final String name) {
+ this.employeeId = employeeId;
+ setEmployeeName(name);
+ }
+
+ public String getId() {
+ return employeeId;
+ }
+
+ public void setEmployeeName(final String employeeName) {
+ this.employeeName = employeeName;
+ }
+
+ public String getEmployeeName() {
+ return employeeName;
+ }
+
+ public void setAge(final int age) {
+ this.age = age;
+ }
+
+ public int getAge() {
+ return age;
+ }
+
+ public void setManager(final Manager manager) {
+ this.manager = manager;
+ }
+
+ public Manager getManager() {
+ return manager;
+ }
+
+ public void setTeam(final Team team) {
+ this.team = team;
+ }
+
+ public Team getTeam() {
+ return team;
+ }
+
+ public void setRoom(final Room room) {
+ this.room = room;
+ }
+
+ public Room getRoom() {
+ return room;
+ }
+
+ public void setImageUri(final String imageUri) {
+ imageUrl = imageUri;
+ }
+
+ public String getImageUri() {
+ return imageUrl;
+ }
+
+ public void setLocation(final Location location) {
+ this.location = location;
+ }
+
+ public Location getLocation() {
+ return location;
+ }
+
+ public void setEntryDate(final Calendar date) {
+ entryDate = date;
+ }
+
+ public Calendar getEntryDate() {
+ return entryDate;
+ }
+
+ public void setImageType(final String imageType) {
+ this.imageType = imageType;
+ }
+
+ public String getImageType() {
+ return imageType;
+ }
+
+ public void setImage(final byte[] image) {
+ this.image = image;
+ }
+
+ public byte[] getImage() {
+ if (image == null) {
+ return null;
+ }
+ return image.clone();
+ }
+
+ @Override
+ public int hashCode() {
+ if (employeeId == null) {
+ return 0;
+ }
+ return employeeId.hashCode();
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ return this == obj
+ || obj != null && getClass() == obj.getClass() && employeeId == ((Employee) obj).employeeId;
+ }
+
+ @Override
+ public String toString() {
+ return "{\"EmployeeId\":\"" + employeeId + "\","
+ + "\"EmployeeName\":\"" + employeeName + "\","
+ + "\"ManagerId\":" + (manager == null ? "null" : "\"" + manager.getId() + "\"") + ","
+ + "\"RoomId\":" + (room == null ? "null" : "\"" + room.getId() + "\"") + ","
+ + "\"TeamId\":" + (team == null ? "null" : "\"" + team.getId() + "\"") + ","
+ + "\"Location\":"
+ + (location == null ? "null" :
+ "{\"City\":" + (location.getCity() == null ? "null" :
+ "{\"PostalCode\":\"" + location.getCity().getPostalCode() + "\","
+ + "\"CityName\":\"" + location.getCity().getCityName() + "\"}") + ","
+ + "\"Country\":\"" + location.getCountry() + "\"}") + ","
+ + "\"Age\":" + age + ","
+ + "\"EntryDate\":"
+ + (entryDate == null ? "null" : "\"" + DateFormat.getInstance().format(entryDate.getTime()) + "\"") + ","
+ + "\"ImageUrl\":\"" + imageUrl + "\"}";
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Location.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Location.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Location.java
new file mode 100644
index 0000000..7f3f082
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Location.java
@@ -0,0 +1,61 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ ******************************************************************************/
+package org.apache.olingo.odata2.core.annotation.model;
+
+import org.apache.olingo.odata2.api.annotation.edm.EdmComplexType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
+
+
+/**
+ *
+ */
+@EdmComplexType(name = "c_Location", namespace = ModelSharedConstants.NAMESPACE_1)
+public class Location {
+ @EdmProperty
+ private String country;
+ @EdmProperty
+ private City city;
+
+ public Location(final String country, final String postalCode, final String cityName) {
+ this.country = country;
+ city = new City(postalCode, cityName);
+ }
+
+ public void setCountry(final String country) {
+ this.country = country;
+ }
+
+ public String getCountry() {
+ return country;
+ }
+
+ public void setCity(final City city) {
+ this.city = city;
+ }
+
+ public City getCity() {
+ return city;
+ }
+
+ @Override
+ public String toString() {
+ return String.format("%s, %s", country, city.toString());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Manager.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Manager.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Manager.java
new file mode 100644
index 0000000..e3edbd0
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Manager.java
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * 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.core.annotation.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty.Multiplicity;
+
+/**
+ *
+ */
+@EdmEntityType(name = "Manager", namespace = ModelSharedConstants.NAMESPACE_1)
+@EdmEntitySet(name = "Managers")
+public class Manager extends Employee {
+
+ @EdmNavigationProperty(name = "nm_Employees", association = "ManagerEmployees",
+ toMultiplicity = Multiplicity.MANY)
+ private List<Employee> employees = new ArrayList<Employee>();
+
+ public Manager(final String id, final String name) {
+ super(id, name);
+ }
+
+ public List<Employee> getEmployees() {
+ return employees;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/ModelSharedConstants.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/ModelSharedConstants.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/ModelSharedConstants.java
new file mode 100644
index 0000000..1d44498
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/ModelSharedConstants.java
@@ -0,0 +1,25 @@
+/*******************************************************************************
+ * 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.core.annotation.model;
+
+public interface ModelSharedConstants {
+
+ String NAMESPACE_1 = "RefScenario";
+ String CONTAINER_1 = "DefaultContainer";
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Photo.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Photo.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Photo.java
new file mode 100644
index 0000000..520216a
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Photo.java
@@ -0,0 +1,128 @@
+/*******************************************************************************
+ * 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.core.annotation.model;
+
+import java.util.Arrays;
+
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
+import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceContent;
+import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceMimeType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceSource;
+import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmType;
+
+/**
+ *
+ */
+@EdmEntityType(name = "Photo", namespace = ModelSharedConstants.NAMESPACE_1)
+@EdmEntitySet(name = "Photos")
+public class Photo {
+ @EdmProperty
+ @EdmKey
+ private String name;
+ @EdmProperty(name = "ImageFormat")
+ @EdmKey
+ private String type;
+ @EdmProperty
+ @EdmMediaResourceMimeType
+ private String mimeType;
+ @EdmProperty
+ @EdmMediaResourceSource
+ private String imageUrl = "http://localhost/someResource.png";
+ @EdmProperty(type = EdmType.BINARY)
+ @EdmMediaResourceContent
+ private byte[] image = ResourceHelper.generateImage();
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(final String name) {
+ this.name = name;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(final String type) {
+ this.type = type;
+ }
+
+ public String getImageUri() {
+ return imageUrl;
+ }
+
+ public void setImageUri(final String uri) {
+ imageUrl = uri;
+ }
+
+ public byte[] getImage() {
+ return image.clone();
+ }
+
+ public void setImage(final byte[] image) {
+ this.image = image;
+ }
+
+ public String getImageType() {
+ return mimeType;
+ }
+
+ public void setImageType(final String imageType) {
+ this.mimeType = imageType;
+ }
+
+ @Override
+ public int hashCode() {
+ int hash = 5;
+ hash = 83 * hash + (this.name != null ? this.name.hashCode() : 0);
+ hash = 83 * hash + (this.type != null ? this.type.hashCode() : 0);
+ return hash;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ final Photo other = (Photo) obj;
+ if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) {
+ return false;
+ }
+ if ((this.type == null) ? (other.type != null) : !this.type.equals(other.type)) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ return "{\"Name\":\"" + name + "\","
+ + "\"Type\":\"" + type + "\","
+ + "\"ImageUrl\":\"" + imageUrl + "\","
+ + "\"Image\":\"" + Arrays.toString(image) + "\","
+ + "\"MimeType\":\"" + mimeType + "\"";
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/RefBase.java
----------------------------------------------------------------------
diff --git a/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/RefBase.java b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/RefBase.java
new file mode 100644
index 0000000..6f3002f
--- /dev/null
+++ b/odata2-annotation-processor/annotation-processor-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/RefBase.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2013 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * 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.core.annotation.model;
+
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
+import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
+import org.apache.olingo.odata2.api.annotation.edm.EdmType;
+
+/**
+ *
+ */
+@EdmEntityType(name="Base", namespace=ModelSharedConstants.NAMESPACE_1)
+public abstract class RefBase {
+ @EdmProperty(name="Name")
+ protected String name;
+ @EdmProperty(name="Id", type = EdmType.STRING)
+ @EdmKey
+ protected int id;
+
+ public RefBase(int id, String name) {
+ this.name = name;
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getId() {
+ return Integer.toString(id);
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+}
[16/52] git commit: Poc for ListsDs and Processor
Posted by mi...@apache.org.
Poc for ListsDs and Processor
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/d83070de
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/d83070de
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/d83070de
Branch: refs/heads/master
Commit: d83070dee64d2afdb7a8afa6b800da2bf24dc54c
Parents: bd54d26
Author: Michael Bolz <mi...@apache.org>
Authored: Tue Nov 12 06:22:38 2013 +0100
Committer: Michael Bolz <mi...@apache.org>
Committed: Tue Nov 12 06:29:01 2013 +0100
----------------------------------------------------------------------
.../api/annotation/edm/EdmComplexEntity.java | 31 -
.../api/annotation/edm/EdmEntityType.java | 34 -
.../odata2/api/annotation/edm/EdmFacets.java | 33 -
.../odata2/api/annotation/edm/EdmKey.java | 29 -
.../annotation/edm/EdmMediaResourceContent.java | 29 -
.../edm/EdmMediaResourceMimeType.java | 29 -
.../annotation/edm/EdmMediaResourceSource.java | 29 -
.../annotation/edm/EdmNavigationProperty.java | 36 -
.../odata2/api/annotation/edm/EdmProperty.java | 36 -
.../api/annotation/edm/NavigationEnd.java | 34 -
.../olingo/odata2/api/data/ListsDataSource.java | 200 +++
.../olingo/odata2/api/data/ValueAccess.java | 69 +
.../edm-annotation-core/pom.xml | 7 +
.../annotation/ds/AnnotationInMemoryDs.java | 185 ++
.../annotation/ds/AnnotationValueAccess.java | 99 ++
.../core/annotation/ds/BeanPropertyAccess.java | 186 ++
.../core/annotation/ds/DataSourceHolder.java | 212 +++
.../odata2/core/annotation/ds/DataStore.java | 166 ++
.../annotation/edm/AnnotationEdmProvider.java | 1 +
.../core/annotation/edm/AnnotationHelper.java | 267 ++-
.../processor/AnnotationProcessor.java | 181 +-
.../annotation/processor/ListsProcessor.java | 1625 ++++++++++++++++++
.../processor/json/EdmAnnotationSerializer.java | 8 +-
.../annotation/processor/json/JsonConsumer.java | 6 +-
.../annotation/processor/json/JsonWriter.java | 1 +
.../edm/AnnotationEdmProviderTest.java | 12 +-
.../odata2/core/annotation/model/Building.java | 1 +
.../odata2/core/annotation/model/City.java | 1 +
.../odata2/core/annotation/model/Employee.java | 3 +-
.../odata2/core/annotation/model/Location.java | 1 +
.../odata2/core/annotation/model/Manager.java | 1 +
.../odata2/core/annotation/model/RefBase.java | 2 +-
.../odata2/core/annotation/model/Room.java | 1 +
.../odata2/core/annotation/model/Team.java | 1 +
.../processor/json/JsonConsumerTest.java | 2 +-
.../edm-annotation-webref/pom.xml | 7 +
.../odata2/ref/annotation/model/Building.java | 7 -
.../odata2/ref/annotation/model/Employee.java | 7 +-
.../odata2/ref/annotation/model/Manager.java | 4 -
.../odata2/ref/annotation/model/Photo.java | 5 -
.../odata2/ref/annotation/model/RefBase.java | 5 -
.../odata2/ref/annotation/model/Room.java | 4 -
.../odata2/ref/annotation/model/Team.java | 8 -
.../ref/annotation/model/ds/BuildingDs.java | 67 -
.../odata2/ref/annotation/model/ds/PhotoDs.java | 63 -
.../odata2/ref/annotation/model/ds/TeamDs.java | 66 -
.../processor/AnnotationPocServiceFactory.java | 161 ++
.../processor/ScenarioErrorCallback.java | 47 -
.../processor/ScenarioServiceFactory.java | 110 --
odata2-lib/odata-annotation/pom.xml | 60 +-
.../api/annotation/edm/EdmComplexEntity.java | 31 +
.../api/annotation/edm/EdmEntityType.java | 34 +
.../odata2/api/annotation/edm/EdmFacets.java | 33 +
.../odata2/api/annotation/edm/EdmKey.java | 29 +
.../annotation/edm/EdmMediaResourceContent.java | 29 +
.../edm/EdmMediaResourceMimeType.java | 29 +
.../annotation/edm/EdmMediaResourceSource.java | 29 +
.../annotation/edm/EdmNavigationProperty.java | 36 +
.../odata2/api/annotation/edm/EdmProperty.java | 36 +
.../api/annotation/edm/NavigationEnd.java | 34 +
.../olingo/odata2/fit/ref/AbstractRefTest.java | 4 +-
.../odata2/fit/ref/EntryXmlReadOnlyTest.java | 2 +-
.../AbstractContentNegotiationTest.java | 4 +-
odata2-lib/odata-ref/pom.xml | 5 +
.../ref/processor/BeanPropertyAccess.java | 185 --
.../odata2/ref/processor/ListsDataSource.java | 200 ---
.../odata2/ref/processor/ListsProcessor.java | 1623 -----------------
.../ref/processor/ScenarioDataSource.java | 1 +
.../ref/processor/ScenarioServiceFactory.java | 2 +
.../odata2/ref/processor/ValueAccess.java | 69 -
.../olingo/odata2/ref/read/EntitySetTest.java | 4 +-
.../olingo/odata2/ref/read/EntityTest.java | 4 +-
odata2-processor-jpa/jpa-web/pom.xml | 10 +
73 files changed, 3570 insertions(+), 3042 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d83070de/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmComplexEntity.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmComplexEntity.java b/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmComplexEntity.java
deleted file mode 100644
index adec2d7..0000000
--- a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmComplexEntity.java
+++ /dev/null
@@ -1,31 +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.api.annotation.edm;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-@Retention(RetentionPolicy.RUNTIME)
-@Target(ElementType.TYPE)
-public @interface EdmComplexEntity {
- String name() default "";
- String namespace();
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d83070de/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmEntityType.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmEntityType.java b/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmEntityType.java
deleted file mode 100644
index ed5d802..0000000
--- a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmEntityType.java
+++ /dev/null
@@ -1,34 +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.api.annotation.edm;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-@Retention(RetentionPolicy.RUNTIME)
-@Target(ElementType.TYPE)
-public @interface EdmEntityType {
- String name() default "";
- String namespace();
- /* If set this entity is exposed as entity set with given name. If not set theire will be no entity set generated. */
- String entitySetName() default "";
- String container() default "";
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d83070de/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmFacets.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmFacets.java b/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmFacets.java
deleted file mode 100644
index 4ea2bd5..0000000
--- a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmFacets.java
+++ /dev/null
@@ -1,33 +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.api.annotation.edm;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-@Retention(RetentionPolicy.RUNTIME)
-@Target(ElementType.ANNOTATION_TYPE)
-public @interface EdmFacets {
- int maxLength() default 0;
- int scale() default -1;
- int precision() default 0;
- boolean nullable() default false;
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d83070de/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmKey.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmKey.java b/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmKey.java
deleted file mode 100644
index 48db91f..0000000
--- a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmKey.java
+++ /dev/null
@@ -1,29 +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.api.annotation.edm;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-@Retention(RetentionPolicy.RUNTIME)
-@Target(ElementType.FIELD)
-public @interface EdmKey {
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d83070de/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmMediaResourceContent.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmMediaResourceContent.java b/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmMediaResourceContent.java
deleted file mode 100644
index 80e9cd8..0000000
--- a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmMediaResourceContent.java
+++ /dev/null
@@ -1,29 +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.api.annotation.edm;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-@Retention(RetentionPolicy.RUNTIME)
-@Target(ElementType.FIELD)
-public @interface EdmMediaResourceContent {
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d83070de/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmMediaResourceMimeType.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmMediaResourceMimeType.java b/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmMediaResourceMimeType.java
deleted file mode 100644
index d255ff4..0000000
--- a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmMediaResourceMimeType.java
+++ /dev/null
@@ -1,29 +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.api.annotation.edm;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-@Retention(RetentionPolicy.RUNTIME)
-@Target(ElementType.FIELD)
-public @interface EdmMediaResourceMimeType {
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d83070de/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmMediaResourceSource.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmMediaResourceSource.java b/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmMediaResourceSource.java
deleted file mode 100644
index 78e72b5..0000000
--- a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmMediaResourceSource.java
+++ /dev/null
@@ -1,29 +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.api.annotation.edm;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-@Retention(RetentionPolicy.RUNTIME)
-@Target(ElementType.FIELD)
-public @interface EdmMediaResourceSource {
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d83070de/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmNavigationProperty.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmNavigationProperty.java b/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmNavigationProperty.java
deleted file mode 100644
index cf898df..0000000
--- a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmNavigationProperty.java
+++ /dev/null
@@ -1,36 +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.api.annotation.edm;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
-
-@Retention(RetentionPolicy.RUNTIME)
-@Target(ElementType.FIELD)
-public @interface EdmNavigationProperty {
- String name();
- String relationship();
-
- //
- NavigationEnd from() default @NavigationEnd;
- NavigationEnd to() default @NavigationEnd;
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d83070de/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmProperty.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmProperty.java b/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmProperty.java
deleted file mode 100644
index 66c5282..0000000
--- a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmProperty.java
+++ /dev/null
@@ -1,36 +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.api.annotation.edm;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
-
-@Retention(RetentionPolicy.RUNTIME)
-@Target(ElementType.FIELD)
-public @interface EdmProperty {
- EdmSimpleTypeKind type() default EdmSimpleTypeKind.Null;
- String name() default "";
- /* only for complex property */
- String namespace() default "";
- EdmFacets facets() default @EdmFacets;
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d83070de/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/NavigationEnd.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/NavigationEnd.java b/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/NavigationEnd.java
deleted file mode 100644
index 2ce5ef1..0000000
--- a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/NavigationEnd.java
+++ /dev/null
@@ -1,34 +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.api.annotation.edm;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
-
-@Retention(RetentionPolicy.RUNTIME)
-@Target(ElementType.FIELD)
-public @interface NavigationEnd {
- String role() default "";
- String type() default "";
-
- EdmMultiplicity multiplicity() default EdmMultiplicity.ONE;
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d83070de/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/data/ListsDataSource.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/data/ListsDataSource.java b/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/data/ListsDataSource.java
new file mode 100644
index 0000000..e9229e3
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/data/ListsDataSource.java
@@ -0,0 +1,200 @@
+/*******************************************************************************
+ * 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.api.data;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.olingo.odata2.api.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.edm.EdmException;
+import org.apache.olingo.odata2.api.edm.EdmFunctionImport;
+import org.apache.olingo.odata2.api.exception.ODataApplicationException;
+import org.apache.olingo.odata2.api.exception.ODataNotFoundException;
+import org.apache.olingo.odata2.api.exception.ODataNotImplementedException;
+
+/**
+ * <p>This interface is intended to make it easier to implement an OData
+ * service in cases where all data for each entity set can be provided as a {@link List} of objects from which all
+ * properties described in the
+ * Entity Data Model can be retrieved and set.</p>
+ * <p>By obeying these restrictions, data-source implementations get the
+ * following advantages:
+ * <ul>
+ * <li>All system query options can be handled centrally.</li>
+ * <li>Following navigation paths must only be done step by step.</li>
+ * </ul>
+ * </p>
+ *
+ */
+public interface ListsDataSource {
+
+ /**
+ * Retrieves the whole data list for the specified entity set.
+ * @param entitySet the requested {@link EdmEntitySet}
+ * @return the requested data list
+ */
+ List<?> readData(EdmEntitySet entitySet) throws ODataNotImplementedException, ODataNotFoundException, EdmException,
+ ODataApplicationException;
+
+ /**
+ * Retrieves a single data object for the specified entity set and key.
+ * @param entitySet the requested {@link EdmEntitySet}
+ * @param keys the entity key as map of key names to key values
+ * @return the requested data object
+ */
+ Object readData(EdmEntitySet entitySet, Map<String, Object> keys) throws ODataNotImplementedException,
+ ODataNotFoundException, EdmException, ODataApplicationException;
+
+ /**
+ * <p>Retrieves data for the specified function import and key.</p>
+ * <p>This method is called also for function imports that have defined in
+ * their metadata an other HTTP method than <code>GET</code>.</p>
+ * @param function the requested {@link EdmFunctionImport}
+ * @param parameters the parameters of the function import
+ * as map of parameter names to parameter values
+ * @param keys the key of the returned entity set, as map of key names to key values,
+ * if the return type of the function import is a collection of entities
+ * (optional)
+ * @return the requested data object, either a list or a single object;
+ * if the function import's return type is of type <code>Binary</code>,
+ * the returned object(s) must be of type {@link BinaryData}
+ */
+ Object readData(EdmFunctionImport function, Map<String, Object> parameters, Map<String, Object> keys)
+ throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException;
+
+ /**
+ * <p>Retrieves related data for the specified source data, entity set, and key.</p>
+ * <p>If the underlying association of the EDM is specified to have target
+ * multiplicity '*' and no target key is given, this method returns a list of
+ * related data, otherwise it returns a single data object.</p>
+ * @param sourceEntitySet the {@link EdmEntitySet} of the source entity
+ * @param sourceData the data object of the source entity
+ * @param targetEntitySet the requested target {@link EdmEntitySet}
+ * @param targetKeys the key of the target entity as map of key names to key values
+ * (optional)
+ * @return the requested releated data object, either a list or a single object
+ */
+ Object readRelatedData(EdmEntitySet sourceEntitySet, Object sourceData, EdmEntitySet targetEntitySet,
+ Map<String, Object> targetKeys) throws ODataNotImplementedException, ODataNotFoundException, EdmException,
+ ODataApplicationException;
+
+ /**
+ * Retrieves the binary data and the MIME type for the media resource
+ * associated to the specified media-link entry.
+ * @param entitySet the {@link EdmEntitySet} of the media-link entry
+ * @param mediaLinkEntryData the data object of the media-link entry
+ * @return the binary data and the MIME type of the media resource
+ */
+ BinaryData readBinaryData(EdmEntitySet entitySet, Object mediaLinkEntryData) throws ODataNotImplementedException,
+ ODataNotFoundException, EdmException, ODataApplicationException;
+
+ /**
+ * <p>Creates and returns a new instance of the requested data-object type.</p>
+ * <p>This instance must not be part of the corresponding list and should
+ * have empty content, apart from the key and other mandatory properties.
+ * However, intermediate objects to access complex properties must not be
+ * <code>null</code>.</p>
+ * @param entitySet the {@link EdmEntitySet} the object must correspond to
+ * @return the new data object
+ */
+ Object newDataObject(EdmEntitySet entitySet) throws ODataNotImplementedException, EdmException,
+ ODataApplicationException;
+
+ /**
+ * Writes the binary data for the media resource associated to the
+ * specified media-link entry.
+ * @param entitySet the {@link EdmEntitySet} of the media-link entry
+ * @param mediaLinkEntryData the data object of the media-link entry
+ * @param binaryData the binary data of the media resource along with
+ * the MIME type of the binary data
+ */
+ void writeBinaryData(EdmEntitySet entitySet, Object mediaLinkEntryData, BinaryData binaryData)
+ throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException;
+
+ /**
+ * Deletes a single data object identified by the specified entity set and key.
+ * @param entitySet the {@link EdmEntitySet} of the entity to be deleted
+ * @param keys the entity key as map of key names to key values
+ */
+ void deleteData(EdmEntitySet entitySet, Map<String, Object> keys) throws ODataNotImplementedException,
+ ODataNotFoundException, EdmException, ODataApplicationException;
+
+ /**
+ * <p>Inserts an instance into the entity list of the specified entity set.</p>
+ * <p>If {@link #newDataObject} has not set the key and other mandatory
+ * properties already, this method must set them before inserting the
+ * instance into the list.</p>
+ * @param entitySet the {@link EdmEntitySet} the object must correspond to
+ * @param data the data object of the new entity
+ */
+ void createData(EdmEntitySet entitySet, Object data) throws ODataNotImplementedException, EdmException,
+ ODataApplicationException;
+
+ /**
+ * Deletes the relation from the specified source data to a target entity
+ * specified by entity set and key.
+ * @param sourceEntitySet the {@link EdmEntitySet} of the source entity
+ * @param sourceData the data object of the source entity
+ * @param targetEntitySet the {@link EdmEntitySet} of the target entity
+ * @param targetKeys the key of the target entity as map of key names to key values
+ * (optional)
+ */
+ void deleteRelation(EdmEntitySet sourceEntitySet, Object sourceData, EdmEntitySet targetEntitySet,
+ Map<String, Object> targetKeys) throws ODataNotImplementedException, ODataNotFoundException, EdmException,
+ ODataApplicationException;
+
+ /**
+ * Writes a relation from the specified source data to a target entity
+ * specified by entity set and key.
+ * @param sourceEntitySet the {@link EdmEntitySet} of the source entity
+ * @param sourceData the data object of the source entity
+ * @param targetEntitySet the {@link EdmEntitySet} of the relation target
+ * @param targetKeys the key of the target entity as map of key names to key values
+ */
+ void writeRelation(EdmEntitySet sourceEntitySet, Object sourceData, EdmEntitySet targetEntitySet,
+ Map<String, Object> targetKeys) throws ODataNotImplementedException, ODataNotFoundException, EdmException,
+ ODataApplicationException;
+
+ /**
+ * Container to store binary data (as byte array) and the associated MIME type.
+ */
+ public class BinaryData {
+ private final byte[] data;
+ private final String mimeType;
+
+ public BinaryData(final byte[] data, final String mimeType) {
+ this.data = data;
+ this.mimeType = mimeType;
+ }
+
+ public byte[] getData() {
+ return data;
+ }
+
+ public String getMimeType() {
+ return mimeType;
+ }
+
+ @Override
+ public String toString() {
+ return "data=" + Arrays.toString(data) + ", mimeType=" + mimeType;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d83070de/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/data/ValueAccess.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/data/ValueAccess.java b/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/data/ValueAccess.java
new file mode 100644
index 0000000..685e1b6
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/data/ValueAccess.java
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * 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.api.data;
+
+import org.apache.olingo.odata2.api.edm.EdmMapping;
+import org.apache.olingo.odata2.api.edm.EdmProperty;
+import org.apache.olingo.odata2.api.exception.ODataException;
+
+/**
+ * This interface is intended to access values in a Java object.
+ */
+public interface ValueAccess {
+
+ /**
+ * Retrieves the value of an EDM property for the given data object.
+ * @param data the Java data object
+ * @param property the requested {@link EdmProperty}
+ * @return the requested property value
+ */
+ public <T> Object getPropertyValue(final T data, final EdmProperty property) throws ODataException;
+
+ /**
+ * Sets the value of an EDM property for the given data object.
+ * @param data the Java data object
+ * @param property the {@link EdmProperty}
+ * @param value the new value of the property
+ */
+ public <T, V> void setPropertyValue(T data, final EdmProperty property, final V value) throws ODataException;
+
+ /**
+ * Retrieves the Java type of an EDM property for the given data object.
+ * @param data the Java data object
+ * @param property the requested {@link EdmProperty}
+ * @return the requested Java type
+ */
+ public <T> Class<?> getPropertyType(final T data, final EdmProperty property) throws ODataException;
+
+ /**
+ * Retrieves the value defined by a mapping object for the given data object.
+ * @param data the Java data object
+ * @param mapping the requested {@link EdmMapping}
+ * @return the requested value
+ */
+ public <T> Object getMappingValue(final T data, final EdmMapping mapping) throws ODataException;
+
+ /**
+ * Sets the value defined by a mapping object for the given data object.
+ * @param data the Java data object
+ * @param mapping the {@link EdmMapping}
+ * @param value the new value
+ */
+ public <T, V> void setMappingValue(T data, final EdmMapping mapping, final V value) throws ODataException;
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d83070de/odata2-edm-annotation/edm-annotation-core/pom.xml
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/pom.xml b/odata2-edm-annotation/edm-annotation-core/pom.xml
index 4f34c8d..4e408f7 100644
--- a/odata2-edm-annotation/edm-annotation-core/pom.xml
+++ b/odata2-edm-annotation/edm-annotation-core/pom.xml
@@ -34,8 +34,15 @@ the License. -->
</dependency>
<dependency>
<groupId>org.apache.olingo</groupId>
+ <artifactId>olingo-odata2-api-annotation-incubating</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.olingo</groupId>
<artifactId>olingo-odata2-core-incubating</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
+
+
</project>
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d83070de/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/ds/AnnotationInMemoryDs.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/ds/AnnotationInMemoryDs.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/ds/AnnotationInMemoryDs.java
new file mode 100644
index 0000000..bdf5d77
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/ds/AnnotationInMemoryDs.java
@@ -0,0 +1,185 @@
+/*******************************************************************************
+ * 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.core.annotation.ds;
+
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
+import org.apache.olingo.odata2.api.data.ListsDataSource;
+import org.apache.olingo.odata2.api.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.edm.EdmException;
+import org.apache.olingo.odata2.api.edm.EdmFunctionImport;
+import org.apache.olingo.odata2.api.exception.ODataApplicationException;
+import org.apache.olingo.odata2.api.exception.ODataNotFoundException;
+import org.apache.olingo.odata2.api.exception.ODataNotImplementedException;
+import org.apache.olingo.odata2.core.annotation.edm.AnnotationHelper;
+import org.apache.olingo.odata2.core.annotation.edm.ClassHelper;
+
+public class AnnotationInMemoryDs implements ListsDataSource {
+
+ private static final AnnotationHelper ANNOTATION_HELPER = new AnnotationHelper();
+ private final Map<String, DataStore<Object>> dataStores = new HashMap<String, DataStore<Object>>();
+
+ public AnnotationInMemoryDs(String packageToScan) {
+ List<Class<?>> foundClasses = ClassHelper.loadClasses(packageToScan, new ClassHelper.ClassValidator() {
+ @Override
+ public boolean isClassValid(Class<?> c) {
+ return null != c.getAnnotation(EdmEntityType.class);
+ }
+ });
+
+ init(foundClasses);
+ }
+
+ @SuppressWarnings("unchecked")
+ private void init(List<Class<?>> foundClasses) {
+ for (Class<?> clz : foundClasses) {
+
+ DataStore<Object> dhs = (DataStore<Object>) DataStore.createInMemory(clz);
+ EdmEntityType entityType = clz.getAnnotation(EdmEntityType.class);
+ dataStores.put(entityType.name(), dhs);
+ }
+ }
+
+ public <T> DataStore<T> getDataStore(Class<T> clazz) {
+ return DataStore.createInMemory(clazz);
+ }
+
+ @Override
+ public List<?> readData(EdmEntitySet entitySet) throws ODataNotImplementedException,
+ ODataNotFoundException, EdmException, ODataApplicationException {
+
+ final String name = entitySet.getEntityType().getName();
+
+ DataStore<Object> holder = dataStores.get(name);
+ if (holder != null) {
+ return new ArrayList(holder.read());
+ }
+
+ throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
+ }
+
+ @Override
+ public Object readData(EdmEntitySet entitySet, Map<String, Object> keys)
+ throws ODataNotFoundException, EdmException, ODataApplicationException {
+ final String name = entitySet.getEntityType().getName();
+
+ DataStore<Object> store = dataStores.get(name);
+ if (store != null) {
+ Object keyInstance = store.createInstance();
+ setKeyFields(keyInstance, keys.values().toArray());
+
+ Object result = store.read(keyInstance);
+ if (result != null) {
+ return result;
+ }
+ }
+
+ throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
+ }
+
+
+ @Override
+ public Object readData(EdmFunctionImport function, Map<String, Object> parameters, Map<String, Object> keys)
+ throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException {
+ throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
+ }
+
+ @Override
+ public Object readRelatedData(EdmEntitySet sourceEntitySet, Object sourceData, EdmEntitySet targetEntitySet,
+ Map<String, Object> targetKeys)
+ throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException {
+ final Object data;
+ if (targetKeys.isEmpty()) {
+ data = this.readData(targetEntitySet);
+ } else {
+ data = this.readData(targetEntitySet, targetKeys);
+ }
+
+ return data;
+ }
+
+ @Override
+ public BinaryData readBinaryData(EdmEntitySet entitySet, Object mediaLinkEntryData)
+ throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException {
+ throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
+ }
+
+ @Override
+ public Object newDataObject(EdmEntitySet entitySet)
+ throws ODataNotImplementedException, EdmException, ODataApplicationException {
+ throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
+ }
+
+ @Override
+ public void writeBinaryData(EdmEntitySet entitySet, Object mediaLinkEntryData, BinaryData binaryData)
+ throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException {
+ throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
+
+ }
+
+ @Override
+ public void deleteData(EdmEntitySet entitySet, Map<String, Object> keys)
+ throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException {
+ throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
+
+ }
+
+ @Override
+ public void createData(EdmEntitySet entitySet, Object data)
+ throws ODataNotImplementedException, EdmException, ODataApplicationException {
+ throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
+
+ }
+
+ @Override
+ public void deleteRelation(EdmEntitySet sourceEntitySet, Object sourceData, EdmEntitySet targetEntitySet,
+ Map<String, Object> targetKeys)
+ throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException {
+ throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
+
+ }
+
+ @Override
+ public void writeRelation(EdmEntitySet sourceEntitySet, Object sourceData, EdmEntitySet targetEntitySet,
+ Map<String, Object> targetKeys)
+ throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException {
+ throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
+ }
+
+
+ private <T> T setKeyFields(T instance, Object[] keyValues) {
+ List<Field> fields = ANNOTATION_HELPER.getAnnotatedFields(instance, EdmKey.class);
+ if (fields.size() != keyValues.length) {
+ throw new IllegalStateException("Wrong amount of key properties. Expected read keys = "
+ + fields + " given key predicates = " + Arrays.toString(keyValues));
+ }
+
+ String propertyName = ANNOTATION_HELPER.getCanonicalName(fields.get(0));
+ ANNOTATION_HELPER.setValueForProperty(instance, propertyName, keyValues[0]);
+
+ return instance;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d83070de/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/ds/AnnotationValueAccess.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/ds/AnnotationValueAccess.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/ds/AnnotationValueAccess.java
new file mode 100644
index 0000000..2c8ac96
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/ds/AnnotationValueAccess.java
@@ -0,0 +1,99 @@
+/*******************************************************************************
+ * 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.core.annotation.ds;
+
+import org.apache.olingo.odata2.api.data.ValueAccess;
+import org.apache.olingo.odata2.api.edm.EdmMapping;
+import org.apache.olingo.odata2.api.edm.EdmProperty;
+import org.apache.olingo.odata2.api.exception.ODataException;
+import org.apache.olingo.odata2.api.exception.ODataNotImplementedException;
+import org.apache.olingo.odata2.core.annotation.edm.AnnotationHelper;
+
+/**
+ *
+ */
+public class AnnotationValueAccess implements ValueAccess {
+ private final AnnotationHelper annotationHelper = new AnnotationHelper();
+
+ /**
+ * Retrieves the value of an EDM property for the given data object.
+ * @param data the Java data object
+ * @param property the requested {@link EdmProperty}
+ * @return the requested property value
+ */
+ @Override
+ public <T> Object getPropertyValue(final T data, final EdmProperty property) throws ODataException {
+ if(annotationHelper.isEdmAnnotated(data)) {
+ return annotationHelper.getValueForProperty(data, property.getName());
+ }
+ throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
+ }
+
+ /**
+ * Sets the value of an EDM property for the given data object.
+ * @param data the Java data object
+ * @param property the {@link EdmProperty}
+ * @param value the new value of the property
+ */
+ @Override
+ public <T, V> void setPropertyValue(T data, final EdmProperty property, final V value) throws ODataException {
+ if(annotationHelper.isEdmAnnotated(data)) {
+ annotationHelper.setValueForProperty(data, property.getName(), value);
+ } else {
+ throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
+ }
+ }
+
+ /**
+ * Retrieves the Java type of an EDM property for the given data object.
+ * @param data the Java data object
+ * @param property the requested {@link EdmProperty}
+ * @return the requested Java type
+ */
+ public <T> Class<?> getPropertyType(final T data, final EdmProperty property) throws ODataException {
+ if(annotationHelper.isEdmAnnotated(data)) {
+ Class<?> fieldType = annotationHelper.getFieldTypeForProperty(data, property.getName());
+ if(fieldType == null) {
+ throw new ODataException("No field type found for property " + property);
+ }
+ return fieldType;
+ }
+ throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
+ }
+
+ /**
+ * Retrieves the value defined by a mapping object for the given data object.
+ * @param data the Java data object
+ * @param mapping the requested {@link EdmMapping}
+ * @return the requested value
+ */
+ public <T> Object getMappingValue(final T data, final EdmMapping mapping) throws ODataException {
+ throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
+ }
+
+ /**
+ * Sets the value defined by a mapping object for the given data object.
+ * @param data the Java data object
+ * @param mapping the {@link EdmMapping}
+ * @param value the new value
+ */
+ public <T, V> void setMappingValue(T data, final EdmMapping mapping, final V value) throws ODataException {
+ throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d83070de/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/ds/BeanPropertyAccess.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/ds/BeanPropertyAccess.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/ds/BeanPropertyAccess.java
new file mode 100644
index 0000000..4b00c40
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/ds/BeanPropertyAccess.java
@@ -0,0 +1,186 @@
+/*******************************************************************************
+ * 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.core.annotation.ds;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Arrays;
+
+import org.apache.olingo.odata2.api.data.ValueAccess;
+import org.apache.olingo.odata2.api.edm.EdmException;
+import org.apache.olingo.odata2.api.edm.EdmMapping;
+import org.apache.olingo.odata2.api.edm.EdmProperty;
+import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
+import org.apache.olingo.odata2.api.exception.ODataException;
+import org.apache.olingo.odata2.api.exception.ODataHttpException;
+import org.apache.olingo.odata2.api.exception.ODataNotFoundException;
+
+/**
+ * Data access.
+ */
+public class BeanPropertyAccess implements ValueAccess {
+
+ @Override
+ public <T> Object getPropertyValue(final T data, final EdmProperty property) throws ODataException {
+ return getValue(data, getGetterMethodName(property));
+ }
+
+ @Override
+ public <T, V> void setPropertyValue(T data, final EdmProperty property, final V value) throws ODataException {
+ final String methodName = getSetterMethodName(getGetterMethodName(property));
+ if (methodName != null) {
+ setValue(data, methodName, value);
+ }
+ }
+
+ @Override
+ public <T> Class<?> getPropertyType(final T data, final EdmProperty property) throws ODataException {
+ return getType(data, getGetterMethodName(property));
+ }
+
+ @Override
+ public <T> Object getMappingValue(final T data, final EdmMapping mapping) throws ODataException {
+ if (mapping != null && mapping.getMimeType() != null) {
+ return getValue(data, mapping.getMimeType());
+ }
+ return null;
+ }
+
+ @Override
+ public <T, V> void setMappingValue(T data, final EdmMapping mapping, final V value) throws ODataException {
+ if (mapping != null && mapping.getMimeType() != null) {
+ setValue(data, getSetterMethodName(mapping.getMimeType()), value);
+ }
+ }
+
+ private String getGetterMethodName(final EdmProperty property) throws EdmException {
+ final String prefix = isBooleanProperty(property) ? "is" : "get";
+ final String defaultMethodName = prefix + property.getName();
+ return property.getMapping() == null || property.getMapping().getInternalName() == null ?
+ defaultMethodName : property.getMapping().getInternalName();
+ }
+
+ private boolean isBooleanProperty(final EdmProperty property) throws EdmException {
+ return property.isSimple()
+ && property.getType() == EdmSimpleTypeKind.Boolean.getEdmSimpleTypeInstance();
+ }
+
+ private String getSetterMethodName(final String getterMethodName) {
+ return getterMethodName.contains(".") ?
+ null : getterMethodName.replaceFirst("^is", "set").replaceFirst("^get", "set");
+ }
+
+ private <T> Object getValue(final T data, final String methodName) throws ODataNotFoundException {
+ Object dataObject = data;
+
+ for (final String method : methodName.split("\\.", -1)) {
+ if (dataObject != null) {
+ try {
+ dataObject = dataObject.getClass().getMethod(method).invoke(dataObject);
+ } catch (SecurityException e) {
+ throw new ODataNotFoundException(ODataHttpException.COMMON, e);
+ } catch (NoSuchMethodException e) {
+ throw new ODataNotFoundException(ODataHttpException.COMMON, e);
+ } catch (IllegalArgumentException e) {
+ throw new ODataNotFoundException(ODataHttpException.COMMON, e);
+ } catch (IllegalAccessException e) {
+ throw new ODataNotFoundException(ODataHttpException.COMMON, e);
+ } catch (InvocationTargetException e) {
+ throw new ODataNotFoundException(ODataHttpException.COMMON, e);
+ }
+ }
+ }
+
+ return dataObject;
+ }
+
+ private <T, V> void setValue(final T data, final String methodName, final V value)
+ throws ODataNotFoundException {
+ try {
+ boolean found = false;
+ for (final Method method : Arrays.asList(data.getClass().getMethods())) {
+ if (method.getName().equals(methodName)) {
+ found = true;
+ final Class<?> type = method.getParameterTypes()[0];
+ if (value == null) {
+ if (type.equals(byte.class) || type.equals(short.class) || type.equals(int.class)
+ || type.equals(long.class) || type.equals(char.class)) {
+ method.invoke(data, 0);
+ } else if (type.equals(float.class) || type.equals(double.class)) {
+ method.invoke(data, 0.0);
+ } else if (type.equals(boolean.class)) {
+ method.invoke(data, false);
+ } else {
+ method.invoke(data, value);
+ }
+ } else {
+ method.invoke(data, value);
+ }
+ break;
+ }
+ }
+ if (!found) {
+ throw new ODataNotFoundException(null);
+ }
+ } catch (SecurityException e) {
+ throw new ODataNotFoundException(null, e);
+ } catch (IllegalArgumentException e) {
+ throw new ODataNotFoundException(null, e);
+ } catch (IllegalAccessException e) {
+ throw new ODataNotFoundException(null, e);
+ } catch (InvocationTargetException e) {
+ throw new ODataNotFoundException(null, e);
+ }
+ }
+
+ private <T> Class<?> getType(final T data, final String methodName) throws ODataNotFoundException {
+ if (data == null) {
+ throw new ODataNotFoundException(ODataHttpException.COMMON);
+ }
+
+ Class<?> type = data.getClass();
+ for (final String method : methodName.split("\\.", -1)) {
+ try {
+ type = type.getMethod(method).getReturnType();
+ if (type.isPrimitive()) {
+ if (type == boolean.class) {
+ type = Boolean.class;
+ } else if (type == byte.class) {
+ type = Byte.class;
+ } else if (type == short.class) {
+ type = Short.class;
+ } else if (type == int.class) {
+ type = Integer.class;
+ } else if (type == long.class) {
+ type = Long.class;
+ } else if (type == float.class) {
+ type = Float.class;
+ } else if (type == double.class) {
+ type = Double.class;
+ }
+ }
+ } catch (final SecurityException e) {
+ throw new ODataNotFoundException(ODataHttpException.COMMON, e);
+ } catch (final NoSuchMethodException e) {
+ throw new ODataNotFoundException(ODataHttpException.COMMON, e);
+ }
+ }
+ return type;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d83070de/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/ds/DataSourceHolder.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/ds/DataSourceHolder.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/ds/DataSourceHolder.java
new file mode 100644
index 0000000..cb5502b
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/ds/DataSourceHolder.java
@@ -0,0 +1,212 @@
+/*******************************************************************************
+ * 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.core.annotation.ds;
+
+import java.lang.reflect.Method;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.annotation.edm.ds.EntityCreate;
+import org.apache.olingo.odata2.api.annotation.edm.ds.EntityDataSource;
+import org.apache.olingo.odata2.api.annotation.edm.ds.EntityDelete;
+import org.apache.olingo.odata2.api.annotation.edm.ds.EntityRead;
+import org.apache.olingo.odata2.api.annotation.edm.ds.EntitySetRead;
+import org.apache.olingo.odata2.api.annotation.edm.ds.EntityUpdate;
+import org.apache.olingo.odata2.api.uri.KeyPredicate;
+import org.apache.olingo.odata2.core.annotation.edm.AnnotationHelper;
+
+/**
+ *
+ */
+public final class DataSourceHolder {
+
+ private static final AnnotationHelper ANNOTATION_HELPER = new AnnotationHelper();
+ private static final Object[] EMPTY_ARRAY = new Object[0];
+
+ private final String name;
+ private final Object dataSourceInstance;
+ private final Class<?> entityTypeClass;
+ private Method readMethod;
+ private Method createMethod;
+ private Method updateMethod;
+ private Method deleteMethod;
+ private Method readSetMethod;
+
+ public DataSourceHolder(Class<?> clz) {
+ EntityDataSource eds = clz.getAnnotation(EntityDataSource.class);
+ entityTypeClass = eds.entityType();
+ EdmEntityType entityType = entityTypeClass.getAnnotation(EdmEntityType.class);
+ if (entityType == null) {
+ throw new IllegalArgumentException("Missing EdmEntityType Annotation at class " + clz);
+ }
+
+ if (entityType.name().isEmpty()) {
+ name = ANNOTATION_HELPER.getCanonicalName(entityTypeClass);
+ } else {
+ name = entityType.name();
+ }
+ dataSourceInstance = createInstance(clz);
+ initMethods(clz);
+ }
+
+ private void initMethods(Class<?> clz) throws IllegalArgumentException, SecurityException {
+ Method[] methods = clz.getDeclaredMethods();
+ for (Method method : methods) {
+ EntityRead ec = method.getAnnotation(EntityRead.class);
+ if (ec != null) {
+ readMethod = method;
+ }
+ EntityCreate ep = method.getAnnotation(EntityCreate.class);
+ if (ep != null) {
+ createMethod = method;
+ }
+ EntityUpdate update = method.getAnnotation(EntityUpdate.class);
+ if (update != null) {
+ updateMethod = method;
+ }
+ EntityDelete delete = method.getAnnotation(EntityDelete.class);
+ if (delete != null) {
+ deleteMethod = method;
+ }
+ EntitySetRead readSet = method.getAnnotation(EntitySetRead.class);
+ if (readSet != null) {
+ readSetMethod = method;
+ }
+ }
+
+ validateMethods(clz);
+ }
+
+ private void validateMethods(Class<?> clz) throws IllegalArgumentException {
+ //
+ if (readMethod == null) {
+ throw new IllegalArgumentException("Missing " + EntityRead.class
+ + " annotation at " + EntityDataSource.class + " annotated class " + clz);
+ }
+ if (updateMethod == null) {
+ throw new IllegalArgumentException("Missing " + EntityUpdate.class
+ + " annotation at " + EntityDataSource.class + " annotated class " + clz);
+ }
+ if (createMethod == null) {
+ throw new IllegalArgumentException("Missing " + EntityCreate.class
+ + " annotation at " + EntityDataSource.class + " annotated class " + clz);
+ }
+
+ if(readSetMethod != null) {
+ if(!Collection.class.isAssignableFrom(readSetMethod.getReturnType())) {
+ throw new IllegalArgumentException("Read set method must have a return type which is assignable to "
+ + Collection.class + " but return type for annotated method " + readSetMethod + " is "
+ + readSetMethod.getReturnType());
+ }
+ }
+ }
+
+ public Object readEntity(Object[] keyValues) {
+ if (readMethod.getParameterTypes().length != keyValues.length) {
+ throw new IllegalStateException("Wrong amount of key properties. Expected read keys = "
+ + Arrays.toString(readMethod.getParameterTypes()) + " given key predicates = "
+ + Arrays.toString(keyValues));
+ }
+
+ return invoke(readMethod, keyValues);
+ }
+
+ public Object readEntity(List<KeyPredicate> keys) {
+ Object[] parameterKeys = mapParameterKeys(readMethod, keys);
+ return invoke(readMethod, parameterKeys);
+ }
+
+ private Object[] mapParameterKeys(Method method, List<KeyPredicate> keys) throws IllegalStateException {
+ if(method == null) {
+ return EMPTY_ARRAY;
+ }
+ Class<?>[] pTypes = method.getParameterTypes();
+ if (pTypes.length != keys.size()) {
+ throw new IllegalStateException("Wrong amount of key properties. Expected read keys = "
+ + Arrays.toString(pTypes) + " given key predicates = " + keys);
+ }
+ Object[] parameterKeys = new Object[pTypes.length];
+ int i = 0;
+ for (KeyPredicate keyPredicate : keys) {
+ if (matches(pTypes[i], keyPredicate)) {
+ parameterKeys[i] = keyPredicate.getLiteral();
+ }
+ i++;
+ }
+ return parameterKeys;
+ }
+
+ public Object createEntity(Object key) {
+ return invoke(createMethod, new Object[]{key});
+ }
+
+ public Object updateEntity(Object key) {
+ return invoke(updateMethod, new Object[]{key});
+ }
+
+ public Object deleteEntity(List<KeyPredicate> keys) {
+ Object[] parameterKeys = mapParameterKeys(deleteMethod, keys);
+ return invoke(deleteMethod, parameterKeys);
+ }
+
+ public Collection<?> readEntitySet() {
+ return (Collection<?>) invoke(readSetMethod, new Object[0]);
+ }
+
+ private Object invoke(Method m, Object[] objs) {
+ try {
+ return m.invoke(dataSourceInstance, objs);
+ } catch (Exception ex) {
+ return null;
+ }
+ }
+
+ public Object createEntityInstance() {
+ return createInstance(this.entityTypeClass);
+ }
+
+ private static Object createInstance(Class<?> clz) {
+ try {
+ return clz.newInstance();
+ } catch (Exception ex) {
+ return null;
+ }
+ }
+
+ public String getEntityName() {
+ return this.name;
+ }
+
+ public Class<?> getEntityTypeClass() {
+ return entityTypeClass;
+ }
+
+ @Override
+ public String toString() {
+ return "DataSourceHolder{" + "name=" + name + ", dataSourceInstance=" + dataSourceInstance +
+ ", entityTypeClass=" + entityTypeClass + ", consumerMethod=" + readMethod +
+ ", createMethod=" + createMethod + ", updateMethod=" + updateMethod + '}';
+ }
+
+ private boolean matches(Class<?> aClass, KeyPredicate type) {
+ return true;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d83070de/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/ds/DataStore.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/ds/DataStore.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/ds/DataStore.java
new file mode 100644
index 0000000..77eb47d
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/ds/DataStore.java
@@ -0,0 +1,166 @@
+/*******************************************************************************
+ * 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.core.annotation.ds;
+
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
+import org.apache.olingo.odata2.api.annotation.edm.ds.EntityCreate;
+import org.apache.olingo.odata2.api.annotation.edm.ds.EntityDelete;
+import org.apache.olingo.odata2.api.annotation.edm.ds.EntityRead;
+import org.apache.olingo.odata2.api.annotation.edm.ds.EntitySetRead;
+import org.apache.olingo.odata2.api.annotation.edm.ds.EntityUpdate;
+import org.apache.olingo.odata2.core.annotation.edm.AnnotationHelper;
+import org.apache.olingo.odata2.core.exception.ODataRuntimeException;
+
+/**
+ *
+ */
+public class DataStore<T> {
+
+ private static final AnnotationHelper ANNOTATION_HELPER = new AnnotationHelper();
+ private final List<T> dataStore;
+ private final Class<T> dataTypeClass;
+
+ private int idCounter = 1;
+
+ private static class InMemoryDataStore {
+ private static final Map<Class<?>, DataStore<?>> c2ds = new HashMap<Class<?>, DataStore<?>>();
+ @SuppressWarnings("unchecked")
+ static DataStore<?> getInstance(Class<?> clz) {
+ DataStore<?> ds = c2ds.get(clz);
+ if(ds == null) {
+ ds = new DataStore<Object>((Class<Object>) clz);
+ c2ds.put(clz, ds);
+ }
+ return ds;
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ public static <T> DataStore<T> createInMemory(Class<T> clazz) {
+ return (DataStore<T>) InMemoryDataStore.getInstance(clazz);
+ }
+
+ private DataStore(List<T> wrapStore, Class<T> clz) {
+ dataStore = wrapStore;
+ dataTypeClass = clz;
+ }
+
+ private DataStore(Class<T> clz) {
+ this(new ArrayList<T>(), clz);
+ }
+
+ public Class<T> getDataTypeClass() {
+ return dataTypeClass;
+ }
+
+ public T createInstance() {
+ try {
+ return dataTypeClass.newInstance();
+ } catch (InstantiationException e) {
+ throw new ODataRuntimeException("Unable to create instance of class '" + dataTypeClass + "'.", e);
+ } catch (IllegalAccessException e) {
+ throw new ODataRuntimeException("Unable to create instance of class '" + dataTypeClass + "'.", e);
+ }
+ }
+
+ @EntityRead
+ public T read(T obj) {
+ List<Object> objKeys = getKeys(obj);
+ for (T stored : dataStore) {
+ if (objKeys.equals(getKeys(stored))) {
+ return stored;
+ }
+ }
+ return null;
+ }
+
+ @EntitySetRead
+ public Collection<T> read() {
+ return Collections.unmodifiableCollection(dataStore);
+ }
+
+ @EntityCreate
+ public T create(T object) {
+ createKeys(object);
+ dataStore.add(object);
+ return object;
+ }
+
+ @EntityUpdate
+ public T update(T object) {
+ T stored = read(object);
+ dataStore.remove(stored);
+ dataStore.add(object);
+ return object;
+ }
+
+ @EntityDelete
+ public T delete(T object) {
+ T stored = read(object);
+ if(stored != null) {
+ dataStore.remove(stored);
+ }
+ return stored;
+ }
+
+ private List<Object> getKeys(T object) {
+ Map<String, Object> keys = ANNOTATION_HELPER.getValueForAnnotatedFields(object, EdmKey.class);
+
+ // XXX: list should be in a defined order -> better to create an 'Key' object which is comparable
+ List<Object> keyList = new ArrayList(keys.values());
+ return keyList;
+ }
+
+ private T createKeys(T object) {
+ List<Field> fields = ANNOTATION_HELPER.getAnnotatedFields(object, EdmKey.class);
+ Map<String, Object> fieldName2KeyValue = new HashMap<String, Object>();
+
+ for (Field field : fields) {
+ Object key = createKey(field);
+ fieldName2KeyValue.put(ANNOTATION_HELPER.getCanonicalName(field), key);
+ }
+
+ ANNOTATION_HELPER.setValuesToAnnotatedFields(fieldName2KeyValue, object, EdmKey.class);
+
+ return object;
+ }
+
+ private Object createKey(Field field) {
+ Class<?> type = field.getType();
+
+ if(type == String.class) {
+ return String.valueOf(idCounter++);
+ } else if(type == Integer.class || type == int.class) {
+ return Integer.valueOf(idCounter++);
+ } else if(type == Long.class || type == long.class) {
+ return Long.valueOf(idCounter++);
+ }
+
+ throw new UnsupportedOperationException("Automated key generation for type '" + type
+ + "' is not supported (caused on field '" + field + "').");
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d83070de/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java
index d4ef369..03cec0b 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java
@@ -26,6 +26,7 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+
import org.apache.olingo.odata2.api.annotation.edm.EdmComplexEntity;
import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
[38/52] git commit: Merge remote-tracking branch 'origin/master' into
PocEdmAnnotationsExtension
Posted by mi...@apache.org.
Merge remote-tracking branch 'origin/master' into PocEdmAnnotationsExtension
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/d108298d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/d108298d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/d108298d
Branch: refs/heads/master
Commit: d108298dbabd35af36dc712f9a7ea28a219c7df6
Parents: e19384d d51297f
Author: Michael Bolz <mi...@apache.org>
Authored: Wed Dec 4 06:26:33 2013 +0100
Committer: Michael Bolz <mi...@apache.org>
Committed: Wed Dec 4 06:26:33 2013 +0100
----------------------------------------------------------------------
.../odata2/core/edm/provider/EdmxProvider.java | 2 -
.../consumer/AtomServiceDocumentConsumer.java | 33 +-
.../core/ep/consumer/XmlEntryConsumer.java | 6 +-
.../core/ep/consumer/XmlFeedConsumer.java | 5 +-
.../core/ep/consumer/XmlLinkConsumer.java | 12 +-
.../core/ep/consumer/XmlMetadataConsumer.java | 9 +-
.../ep/consumer/AbstractXmlConsumerTest.java | 45 +
.../AtomServiceDocumentConsumerTest.java | 10 +-
.../consumer/ServiceDocumentConsumerTest.java | 3 +-
.../core/ep/consumer/XmlEntityConsumerTest.java | 15 +-
.../core/ep/consumer/XmlFeedConsumerTest.java | 22 +-
.../core/ep/consumer/XmlLinkConsumerTest.java | 25 +-
.../ep/consumer/XmlMetadataConsumerTest.java | 27 +-
.../ep/consumer/XmlPropertyConsumerTest.java | 6 +-
.../src/test/resources/LargeEmployeeFeed.xml | 12538 +++++++++++++++++
.../core/jpa/access/data/JPAEntity.java | 85 +-
.../core/jpa/access/data/JPAEntityParser.java | 6 +-
.../core/jpa/access/data/JPAExpandCallBack.java | 3 +-
.../jpa/access/model/JPAEdmNameBuilder.java | 5 +-
.../core/jpa/mock/data/EdmMockUtilV2.java | 4 +-
.../core/jpa/mock/data/JPATypeMock.java | 3 +-
.../processor/ref/model/SalesOrderHeader.java | 8 +-
22 files changed, 12744 insertions(+), 128 deletions(-)
----------------------------------------------------------------------
[42/52] git commit: Removed not to merge PoC parts
Posted by mi...@apache.org.
Removed not to merge PoC parts
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/8764e11a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/8764e11a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/8764e11a
Branch: refs/heads/master
Commit: 8764e11a6d70099a93e2da110fe47ffe06c4baaa
Parents: a73d197
Author: Michael Bolz <mi...@apache.org>
Authored: Thu Dec 5 08:46:31 2013 +0100
Committer: Michael Bolz <mi...@apache.org>
Committed: Thu Dec 5 08:46:31 2013 +0100
----------------------------------------------------------------------
.../api/annotation/edm/ds/EntityCreate.java | 29 -
.../api/annotation/edm/ds/EntityDataSource.java | 31 -
.../api/annotation/edm/ds/EntityDelete.java | 29 -
.../api/annotation/edm/ds/EntityRead.java | 29 -
.../api/annotation/edm/ds/EntitySetRead.java | 29 -
.../api/annotation/edm/ds/EntityUpdate.java | 29 -
.../annotation/data/AnnotationInMemoryDs.java | 8 +-
.../annotation/data/AnnotationValueAccess.java | 2 +-
.../core/annotation/data/DataSourceHolder.java | 212 ------
.../odata2/core/annotation/data/DataStore.java | 2 +-
.../annotation/edm/AnnotationEdmProvider.java | 2 +
.../core/annotation/edm/AnnotationHelper.java | 726 -------------------
.../odata2/core/annotation/edm/ClassHelper.java | 105 ---
.../processor/AnnotationProcessor.java | 309 --------
.../processor/json/EdmAnnotationSerializer.java | 260 -------
.../annotation/processor/json/JsonConsumer.java | 138 ----
.../annotation/processor/json/JsonWriter.java | 204 ------
.../core/annotation/util/AnnotationHelper.java | 726 +++++++++++++++++++
.../core/annotation/util/ClassHelper.java | 105 +++
.../src/main/resources/log4j.xml | 39 -
.../data/AnnotationsInMemoryDsTest.java | 2 +-
.../processor/json/JsonConsumerTest.java | 85 ---
.../edm-annotation-webref/pom.xml | 12 +-
23 files changed, 845 insertions(+), 2268 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/8764e11a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/ds/EntityCreate.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/ds/EntityCreate.java b/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/ds/EntityCreate.java
deleted file mode 100644
index 529ee63..0000000
--- a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/ds/EntityCreate.java
+++ /dev/null
@@ -1,29 +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.api.annotation.edm.ds;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-@Retention(RetentionPolicy.RUNTIME)
-@Target(ElementType.METHOD)
-public @interface EntityCreate {
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/8764e11a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/ds/EntityDataSource.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/ds/EntityDataSource.java b/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/ds/EntityDataSource.java
deleted file mode 100644
index e21c81f..0000000
--- a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/ds/EntityDataSource.java
+++ /dev/null
@@ -1,31 +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.api.annotation.edm.ds;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-@Retention(RetentionPolicy.RUNTIME)
-@Target(ElementType.TYPE)
-public @interface EntityDataSource {
- String name() default "";
- Class<?> entityType();
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/8764e11a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/ds/EntityDelete.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/ds/EntityDelete.java b/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/ds/EntityDelete.java
deleted file mode 100644
index f852307..0000000
--- a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/ds/EntityDelete.java
+++ /dev/null
@@ -1,29 +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.api.annotation.edm.ds;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-@Retention(RetentionPolicy.RUNTIME)
-@Target(ElementType.METHOD)
-public @interface EntityDelete {
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/8764e11a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/ds/EntityRead.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/ds/EntityRead.java b/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/ds/EntityRead.java
deleted file mode 100644
index 76333ca..0000000
--- a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/ds/EntityRead.java
+++ /dev/null
@@ -1,29 +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.api.annotation.edm.ds;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-@Retention(RetentionPolicy.RUNTIME)
-@Target(ElementType.METHOD)
-public @interface EntityRead {
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/8764e11a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/ds/EntitySetRead.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/ds/EntitySetRead.java b/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/ds/EntitySetRead.java
deleted file mode 100644
index 79cb80c..0000000
--- a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/ds/EntitySetRead.java
+++ /dev/null
@@ -1,29 +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.api.annotation.edm.ds;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-@Retention(RetentionPolicy.RUNTIME)
-@Target(ElementType.METHOD)
-public @interface EntitySetRead {
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/8764e11a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/ds/EntityUpdate.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/ds/EntityUpdate.java b/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/ds/EntityUpdate.java
deleted file mode 100644
index 6aea1eb..0000000
--- a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/ds/EntityUpdate.java
+++ /dev/null
@@ -1,29 +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.api.annotation.edm.ds;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-@Retention(RetentionPolicy.RUNTIME)
-@Target(ElementType.METHOD)
-public @interface EntityUpdate {
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/8764e11a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationInMemoryDs.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationInMemoryDs.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationInMemoryDs.java
index 7c41945..030cc93 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationInMemoryDs.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationInMemoryDs.java
@@ -32,10 +32,10 @@ import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
import org.apache.olingo.odata2.api.exception.ODataApplicationException;
import org.apache.olingo.odata2.api.exception.ODataNotFoundException;
import org.apache.olingo.odata2.api.exception.ODataNotImplementedException;
-import org.apache.olingo.odata2.core.annotation.edm.AnnotationHelper;
-import org.apache.olingo.odata2.core.annotation.edm.AnnotationHelper.AnnotatedNavInfo;
-import org.apache.olingo.odata2.core.annotation.edm.AnnotationHelper.ODataAnnotationException;
-import org.apache.olingo.odata2.core.annotation.edm.ClassHelper;
+import org.apache.olingo.odata2.core.annotation.util.AnnotationHelper;
+import org.apache.olingo.odata2.core.annotation.util.ClassHelper;
+import org.apache.olingo.odata2.core.annotation.util.AnnotationHelper.AnnotatedNavInfo;
+import org.apache.olingo.odata2.core.annotation.util.AnnotationHelper.ODataAnnotationException;
import org.apache.olingo.odata2.core.exception.ODataRuntimeException;
public class AnnotationInMemoryDs implements ListsDataSource {
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/8764e11a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationValueAccess.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationValueAccess.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationValueAccess.java
index c29ac39..14183bf 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationValueAccess.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationValueAccess.java
@@ -23,7 +23,7 @@ import org.apache.olingo.odata2.api.edm.EdmMapping;
import org.apache.olingo.odata2.api.edm.EdmProperty;
import org.apache.olingo.odata2.api.exception.ODataException;
import org.apache.olingo.odata2.api.exception.ODataNotImplementedException;
-import org.apache.olingo.odata2.core.annotation.edm.AnnotationHelper;
+import org.apache.olingo.odata2.core.annotation.util.AnnotationHelper;
/**
*
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/8764e11a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/DataSourceHolder.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/DataSourceHolder.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/DataSourceHolder.java
deleted file mode 100644
index d4c6f98..0000000
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/DataSourceHolder.java
+++ /dev/null
@@ -1,212 +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.core.annotation.data;
-
-import java.lang.reflect.Method;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.annotation.edm.ds.EntityCreate;
-import org.apache.olingo.odata2.api.annotation.edm.ds.EntityDataSource;
-import org.apache.olingo.odata2.api.annotation.edm.ds.EntityDelete;
-import org.apache.olingo.odata2.api.annotation.edm.ds.EntityRead;
-import org.apache.olingo.odata2.api.annotation.edm.ds.EntitySetRead;
-import org.apache.olingo.odata2.api.annotation.edm.ds.EntityUpdate;
-import org.apache.olingo.odata2.api.uri.KeyPredicate;
-import org.apache.olingo.odata2.core.annotation.edm.AnnotationHelper;
-
-/**
- *
- */
-public final class DataSourceHolder {
-
- private static final AnnotationHelper ANNOTATION_HELPER = new AnnotationHelper();
- private static final Object[] EMPTY_ARRAY = new Object[0];
-
- private final String name;
- private final Object dataSourceInstance;
- private final Class<?> entityTypeClass;
- private Method readMethod;
- private Method createMethod;
- private Method updateMethod;
- private Method deleteMethod;
- private Method readSetMethod;
-
- public DataSourceHolder(Class<?> clz) {
- EntityDataSource eds = clz.getAnnotation(EntityDataSource.class);
- entityTypeClass = eds.entityType();
- EdmEntityType entityType = entityTypeClass.getAnnotation(EdmEntityType.class);
- if (entityType == null) {
- throw new IllegalArgumentException("Missing EdmEntityType Annotation at class " + clz);
- }
-
- if (entityType.name().isEmpty()) {
- name = ANNOTATION_HELPER.getCanonicalName(entityTypeClass);
- } else {
- name = entityType.name();
- }
- dataSourceInstance = createInstance(clz);
- initMethods(clz);
- }
-
- private void initMethods(Class<?> clz) throws IllegalArgumentException, SecurityException {
- Method[] methods = clz.getDeclaredMethods();
- for (Method method : methods) {
- EntityRead ec = method.getAnnotation(EntityRead.class);
- if (ec != null) {
- readMethod = method;
- }
- EntityCreate ep = method.getAnnotation(EntityCreate.class);
- if (ep != null) {
- createMethod = method;
- }
- EntityUpdate update = method.getAnnotation(EntityUpdate.class);
- if (update != null) {
- updateMethod = method;
- }
- EntityDelete delete = method.getAnnotation(EntityDelete.class);
- if (delete != null) {
- deleteMethod = method;
- }
- EntitySetRead readSet = method.getAnnotation(EntitySetRead.class);
- if (readSet != null) {
- readSetMethod = method;
- }
- }
-
- validateMethods(clz);
- }
-
- private void validateMethods(Class<?> clz) throws IllegalArgumentException {
- //
- if (readMethod == null) {
- throw new IllegalArgumentException("Missing " + EntityRead.class
- + " annotation at " + EntityDataSource.class + " annotated class " + clz);
- }
- if (updateMethod == null) {
- throw new IllegalArgumentException("Missing " + EntityUpdate.class
- + " annotation at " + EntityDataSource.class + " annotated class " + clz);
- }
- if (createMethod == null) {
- throw new IllegalArgumentException("Missing " + EntityCreate.class
- + " annotation at " + EntityDataSource.class + " annotated class " + clz);
- }
-
- if(readSetMethod != null) {
- if(!Collection.class.isAssignableFrom(readSetMethod.getReturnType())) {
- throw new IllegalArgumentException("Read set method must have a return type which is assignable to "
- + Collection.class + " but return type for annotated method " + readSetMethod + " is "
- + readSetMethod.getReturnType());
- }
- }
- }
-
- public Object readEntity(Object[] keyValues) {
- if (readMethod.getParameterTypes().length != keyValues.length) {
- throw new IllegalStateException("Wrong amount of key properties. Expected read keys = "
- + Arrays.toString(readMethod.getParameterTypes()) + " given key predicates = "
- + Arrays.toString(keyValues));
- }
-
- return invoke(readMethod, keyValues);
- }
-
- public Object readEntity(List<KeyPredicate> keys) {
- Object[] parameterKeys = mapParameterKeys(readMethod, keys);
- return invoke(readMethod, parameterKeys);
- }
-
- private Object[] mapParameterKeys(Method method, List<KeyPredicate> keys) throws IllegalStateException {
- if(method == null) {
- return EMPTY_ARRAY;
- }
- Class<?>[] pTypes = method.getParameterTypes();
- if (pTypes.length != keys.size()) {
- throw new IllegalStateException("Wrong amount of key properties. Expected read keys = "
- + Arrays.toString(pTypes) + " given key predicates = " + keys);
- }
- Object[] parameterKeys = new Object[pTypes.length];
- int i = 0;
- for (KeyPredicate keyPredicate : keys) {
- if (matches(pTypes[i], keyPredicate)) {
- parameterKeys[i] = keyPredicate.getLiteral();
- }
- i++;
- }
- return parameterKeys;
- }
-
- public Object createEntity(Object key) {
- return invoke(createMethod, new Object[]{key});
- }
-
- public Object updateEntity(Object key) {
- return invoke(updateMethod, new Object[]{key});
- }
-
- public Object deleteEntity(List<KeyPredicate> keys) {
- Object[] parameterKeys = mapParameterKeys(deleteMethod, keys);
- return invoke(deleteMethod, parameterKeys);
- }
-
- public Collection<?> readEntitySet() {
- return (Collection<?>) invoke(readSetMethod, new Object[0]);
- }
-
- private Object invoke(Method m, Object[] objs) {
- try {
- return m.invoke(dataSourceInstance, objs);
- } catch (Exception ex) {
- return null;
- }
- }
-
- public Object createEntityInstance() {
- return createInstance(this.entityTypeClass);
- }
-
- private static Object createInstance(Class<?> clz) {
- try {
- return clz.newInstance();
- } catch (Exception ex) {
- return null;
- }
- }
-
- public String getEntityName() {
- return this.name;
- }
-
- public Class<?> getEntityTypeClass() {
- return entityTypeClass;
- }
-
- @Override
- public String toString() {
- return "DataSourceHolder{" + "name=" + name + ", dataSourceInstance=" + dataSourceInstance +
- ", entityTypeClass=" + entityTypeClass + ", consumerMethod=" + readMethod +
- ", createMethod=" + createMethod + ", updateMethod=" + updateMethod + '}';
- }
-
- private boolean matches(Class<?> aClass, KeyPredicate type) {
- return true;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/8764e11a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/DataStore.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/DataStore.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/DataStore.java
index 834e33a..696ab9a 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/DataStore.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/DataStore.java
@@ -29,7 +29,7 @@ import java.util.Map;
import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
import org.apache.olingo.odata2.api.exception.ODataApplicationException;
-import org.apache.olingo.odata2.core.annotation.edm.AnnotationHelper;
+import org.apache.olingo.odata2.core.annotation.util.AnnotationHelper;
import org.apache.olingo.odata2.core.exception.ODataRuntimeException;
/**
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/8764e11a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java
index 1b53d58..97f5b53 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java
@@ -64,6 +64,8 @@ import org.apache.olingo.odata2.api.edm.provider.Schema;
import org.apache.olingo.odata2.api.edm.provider.SimpleProperty;
import org.apache.olingo.odata2.api.edm.provider.Using;
import org.apache.olingo.odata2.api.exception.ODataException;
+import org.apache.olingo.odata2.core.annotation.util.AnnotationHelper;
+import org.apache.olingo.odata2.core.annotation.util.ClassHelper;
import org.apache.olingo.odata2.core.exception.ODataRuntimeException;
/**
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/8764e11a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java
deleted file mode 100644
index 2b6675f..0000000
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java
+++ /dev/null
@@ -1,726 +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.core.annotation.edm;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Field;
-import java.lang.reflect.ParameterizedType;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.olingo.odata2.api.annotation.edm.EdmComplexType;
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
-import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
-import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty.Multiplicity;
-import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
-import org.apache.olingo.odata2.api.edm.EdmLiteralKind;
-import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
-import org.apache.olingo.odata2.api.edm.EdmSimpleTypeException;
-import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
-import org.apache.olingo.odata2.api.edm.FullQualifiedName;
-import org.apache.olingo.odata2.api.exception.ODataException;
-import org.apache.olingo.odata2.core.exception.ODataRuntimeException;
-
-/**
- *
- */
-public class AnnotationHelper {
-
- public static final String DEFAULT_CONTAINER_NAME = "DefaultContainer";
-
- /**
- * Compare keys of both instances.
- *
- * @param firstInstance
- * @param secondInstance
- * @return
- */
- public boolean keyMatch(Object firstInstance, Object secondInstance) {
- if (firstInstance == null || secondInstance == null) {
- return false;
- } else if (firstInstance.getClass() != secondInstance.getClass()) {
- return false;
- }
-
- Map<String, Object> firstKeyFields = getValueForAnnotatedFields(firstInstance, EdmKey.class);
- Map<String, Object> secondKeyFields = getValueForAnnotatedFields(secondInstance, EdmKey.class);
-
- return keyValuesMatch(firstKeyFields, secondKeyFields);
- }
-
- /**
- * Compare keys of instance with key values in map.
- *
- * @param instance
- * @param keyName2Value
- * @return
- */
- public boolean keyMatch(Object instance, Map<String, Object> keyName2Value) {
- Map<String, Object> instanceKeyFields = getValueForAnnotatedFields(instance, EdmKey.class);
- return keyValuesMatch(instanceKeyFields, keyName2Value);
- }
-
- private boolean keyValuesMatch(Map<String, Object> firstKeyValues, Map<String, Object> secondKeyValues) {
- if (firstKeyValues.size() != secondKeyValues.size()) {
- return false;
- } else {
- Set<Map.Entry<String, Object>> entries = firstKeyValues.entrySet();
- for (Map.Entry<String, Object> entry : entries) {
- Object firstKey = entry.getValue();
- Object secondKey = secondKeyValues.get(entry.getKey());
- if (!isEqual(firstKey, secondKey)) {
- return false;
- }
- }
- return true;
- }
- }
-
- private boolean isEqual(Object firstKey, Object secondKey) {
- if (firstKey == null) {
- if (secondKey == null) {
- return true;
- } else {
- return secondKey.equals(firstKey);
- }
- } else {
- return firstKey.equals(secondKey);
- }
- }
-
- public String extractEntitTypeName(EdmNavigationProperty enp, Class<?> fallbackClass) {
- Class<?> entityTypeClass = enp.toType();
- return extractEntityTypeName(entityTypeClass == Object.class ? fallbackClass : entityTypeClass);
- }
-
- public String extractEntitTypeName(EdmNavigationProperty enp, Field field) {
- Class<?> entityTypeClass = enp.toType();
- if (entityTypeClass == Object.class) {
- Class<?> toClass = field.getType();
- return extractEntityTypeName((toClass.isArray() || Collection.class.isAssignableFrom(toClass) ?
- (Class<?>) ((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0] : toClass));
- } else {
- return extractEntityTypeName(entityTypeClass);
- }
- }
-
- /**
- * Returns <code>NULL</code> if given class is not annotated. If annotated the set entity type name is returned and if
- * no name is set the default name is generated from the simple class name.
- *
- * @param annotatedClass
- * @return
- */
- public String extractEntityTypeName(Class<?> annotatedClass) {
- return extractTypeName(annotatedClass, EdmEntityType.class);
- }
-
- public FullQualifiedName extractEntityTypeFqn(EdmEntityType type, Class<?> annotatedClass) {
- if(type.namespace().isEmpty()) {
- return new FullQualifiedName(generateNamespace(annotatedClass), extractEntityTypeName(annotatedClass));
- }
- return new FullQualifiedName(type.namespace(), extractEntityTypeName(annotatedClass));
- }
-
- public FullQualifiedName extractEntityTypeFqn(Class<?> annotatedClass) {
- EdmEntityType type = annotatedClass.getAnnotation(EdmEntityType.class);
- if(type == null) {
- return null;
- }
- return extractEntityTypeFqn(type, annotatedClass);
- }
-
- public FullQualifiedName extractComplexTypeFqn(Class<?> annotatedClass) {
- EdmComplexType type = annotatedClass.getAnnotation(EdmComplexType.class);
- if(type == null) {
- return null;
- }
- return extractComplexTypeFqn(type, annotatedClass);
- }
-
- public FullQualifiedName extractComplexTypeFqn(EdmComplexType type, Class<?> annotatedClass) {
- if(type.namespace().isEmpty()) {
- return new FullQualifiedName(generateNamespace(annotatedClass), extractComplexTypeName(annotatedClass));
- }
- return new FullQualifiedName(type.namespace(), extractComplexTypeName(annotatedClass));
- }
-
- public String extractComplexTypeName(Class<?> annotatedClass) {
- return extractTypeName(annotatedClass, EdmComplexType.class);
- }
-
- public String generateNamespace(Class<?> annotatedClass) {
- String packageName = annotatedClass.getPackage().getName();
- return packageName;
- }
-
- /**
- *
- *
- * @param <T> must be EdmEntityType or EdmComplexType annotation
- * @param annotatedClass
- * @param typeAnnotation
- * @return null if annotatedClass is not annotated or name set via annotation or generated via
- * {@link #getCanonicalName(java.lang.Class)}
- */
- private <T extends Annotation> String extractTypeName(Class<?> annotatedClass, Class<T> typeAnnotation) {
- if (annotatedClass == Object.class) {
- return null;
- }
- T type = annotatedClass.getAnnotation(typeAnnotation);
- if (type == null) {
- return null;
- }
-
- String name;
- if (typeAnnotation == EdmEntityType.class) {
- name = ((EdmEntityType) type).name();
- } else if (typeAnnotation == EdmComplexType.class) {
- name = ((EdmComplexType) type).name();
- } else {
- return null;
- }
-
- if (name.isEmpty()) {
- return getCanonicalName(annotatedClass);
- }
- return name;
- }
-
- /**
- * Get the set property name from an EdmProperty or EdmNavigationProperty annotation.
- *
- * @param field
- * @return
- */
- public String getPropertyNameFromAnnotation(Field field) {
- EdmProperty property = field.getAnnotation(EdmProperty.class);
- if (property == null) {
- EdmNavigationProperty navProperty = field.getAnnotation(EdmNavigationProperty.class);
- if (navProperty == null) {
- throw new EdmAnnotationException("Given field '" + field
- + "' has no EdmProperty or EdmNavigationProperty annotation.");
- }
- return navProperty.name();
- }
- return property.name();
- }
-
- public String getPropertyName(Field field) {
- String propertyName = getPropertyNameFromAnnotation(field);
- if (propertyName.isEmpty()) {
- propertyName = getCanonicalName(field);
- }
- return propertyName;
- }
-
- public String extractFromRoleName(EdmNavigationProperty enp, Field field) {
- return getCanonicalRole(field.getDeclaringClass());
- }
-
- public String extractToRoleName(EdmNavigationProperty enp, Field field) {
- String role = enp.toRole();
- if (role.isEmpty()) {
- role = getCanonicalRole(
- field.getType().isArray() || Collection.class.isAssignableFrom(field.getType()) ?
- (Class<?>) ((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0] : field.getType());
- }
- return role;
- }
-
- public String getCanonicalRole(Class<?> fallbackClass) {
- String toRole = extractEntityTypeName(fallbackClass);
- return "r_" + toRole;
- }
-
- public String extractRelationshipName(EdmNavigationProperty enp, Field field) {
- String relationshipName = enp.association();
- if (relationshipName.isEmpty()) {
- final String fromRole = extractFromRoleName(enp, field);
- final String toRole = extractToRoleName(enp, field);
- if (fromRole.compareTo(toRole) > 0) {
- relationshipName = toRole + "-" + fromRole;
- } else {
- relationshipName = fromRole + "-" + toRole;
- }
- }
- return relationshipName;
- }
-
- public EdmMultiplicity getMultiplicity(EdmNavigationProperty enp, Field field) {
- EdmMultiplicity multiplicity = mapMultiplicity(enp.toMultiplicity());
- final boolean isCollectionType = field.getType().isArray() || Collection.class.isAssignableFrom(field.getType());
-
- if (multiplicity == EdmMultiplicity.ONE && isCollectionType) {
- return EdmMultiplicity.MANY;
- }
- return multiplicity;
- }
-
-
- /**
- * Set key fields based on values in map.
- * If an key field is not available or <code>NULL</code> in the map
- * it will be not set as <code>NULL</code> at the instance object.
- *
- * @param instance
- * @param keys
- * @return
- */
- public <T> T setKeyFields(T instance, Map<String, Object> keys) {
- List<Field> fields = getAnnotatedFields(instance, EdmKey.class);
-
- for (Field field : fields) {
- String propertyName = getPropertyName(field);
- Object keyValue = keys.get(propertyName);
- setValueForProperty(instance, propertyName, keyValue);
- }
-
- return instance;
- }
-
- public static final class ODataAnnotationException extends ODataException {
- private static final long serialVersionUID = 1L;
-
- public ODataAnnotationException(String message) {
- super(message);
- }
- }
-
-
- public class AnnotatedNavInfo {
- private final Field fromField;
- private final Field toField;
- private final EdmNavigationProperty fromNavigation;
- private final EdmNavigationProperty toNavigation;
-
- public AnnotatedNavInfo(Field fromField, Field toField, EdmNavigationProperty fromNavigation,
- EdmNavigationProperty toNavigation) {
- this.fromField = fromField;
- this.toField = toField;
- this.fromNavigation = fromNavigation;
- this.toNavigation = toNavigation;
- }
-
- public Field getFromField() {
- return fromField;
- }
-
- public Field getToField() {
- return toField;
- }
-
- public EdmMultiplicity getFromMultiplicity() {
- return getMultiplicity(toNavigation, toField);
- }
-
- public EdmMultiplicity getToMultiplicity() {
- return getMultiplicity(fromNavigation, fromField);
- }
-
- public boolean isBiDirectional() {
- return toNavigation != null;
- }
- }
-
- public AnnotatedNavInfo getCommonNavigationInfo(Class<?> sourceClass, Class<?> targetClass) {
- List<Field> sourceFields = getAnnotatedFields(sourceClass, EdmNavigationProperty.class);
- List<Field> targetFields = getAnnotatedFields(targetClass, EdmNavigationProperty.class);
-
- // first try via association name to get full navigation information
- for (Field sourceField : sourceFields) {
- final EdmNavigationProperty sourceNav = sourceField.getAnnotation(EdmNavigationProperty.class);
- final String sourceAssociation = extractRelationshipName(sourceNav, sourceField);
- for (Field targetField : targetFields) {
- final EdmNavigationProperty targetNav = targetField.getAnnotation(EdmNavigationProperty.class);
- final String targetAssociation = extractRelationshipName(targetNav, targetField);
- if (sourceAssociation.equals(targetAssociation)) {
- return new AnnotatedNavInfo(sourceField, targetField, sourceNav, targetNav);
- }
- }
- }
-
- // if nothing was found assume none bi-directinal navigation
- String targetEntityTypeName = extractEntityTypeName(targetClass);
- for (Field sourceField : sourceFields) {
- final EdmNavigationProperty sourceNav = sourceField.getAnnotation(EdmNavigationProperty.class);
- final String navTargetEntityName = extractEntitTypeName(sourceNav, sourceField);
-
- if (navTargetEntityName.equals(targetEntityTypeName)) {
- return new AnnotatedNavInfo(sourceField, null, sourceNav, null);
- }
- }
-
- return null;
- }
-
- public Class<?> getFieldTypeForProperty(Object instance, String propertyName) throws ODataAnnotationException {
- if (instance == null) {
- return null;
- }
-
- Field field = getFieldForPropertyName(instance, propertyName, instance.getClass(), true);
- if (field == null) {
- throw new ODataAnnotationException("No field for property '" + propertyName
- + "' found at class '" + instance.getClass() + "'.");
- }
- return field.getType();
- }
-
- public Object getValueForProperty(Object instance, String propertyName) throws ODataAnnotationException {
- if (instance == null) {
- return null;
- }
-
- Field field = getFieldForPropertyName(instance, propertyName, instance.getClass(), true);
- if (field == null) {
- throw new ODataAnnotationException("No field for property '" + propertyName
- + "' found at class '" + instance.getClass() + "'.");
- }
- return getFieldValue(instance, field);
- }
-
- public void setValueForProperty(Object instance, String propertyName, Object propertyValue) {
- if (instance != null) {
- Field field = getFieldForPropertyName(instance, propertyName, instance.getClass(), true);
- if (field != null) {
- setFieldValue(instance, field, propertyValue);
- }
- }
- }
-
- private Field getFieldForPropertyName(Object instance, String propertyName,
- Class<?> resultClass, boolean inherited) {
- if (instance == null) {
- return null;
- }
-
- Field[] fields = resultClass.getDeclaredFields();
- for (Field field : fields) {
- EdmProperty property = field.getAnnotation(EdmProperty.class);
- if (property != null) {
- if (property.name().isEmpty() && getCanonicalName(field).equals(propertyName)) {
- return field;
- } else if (property.name().equals(propertyName)) {
- return field;
- }
- }
- }
-
- Class<?> superClass = resultClass.getSuperclass();
- if (inherited && superClass != Object.class) {
- return getFieldForPropertyName(instance, propertyName, superClass, true);
- }
-
- return null;
- }
-
- public Object getValueForField(Object instance, String fieldName, Class<? extends Annotation> annotation) {
- if (instance == null) {
- return null;
- }
- return getValueForField(instance, fieldName, instance.getClass(), annotation, true);
- }
-
- public Object getValueForField(Object instance, Class<? extends Annotation> annotation) {
- if (instance == null) {
- return null;
- }
- return getValueForField(instance, instance.getClass(), annotation, true);
- }
-
- private Object getValueForField(Object instance, Class<?> resultClass,
- Class<? extends Annotation> annotation, boolean inherited) {
- return getValueForField(instance, null, resultClass, annotation, inherited);
- }
-
- public Map<String, Object> getValueForAnnotatedFields(Object instance,
- Class<? extends Annotation> annotation) {
- return getValueForAnnotatedFields(instance, instance.getClass(), annotation, true);
- }
-
- private Map<String, Object> getValueForAnnotatedFields(Object instance, Class<?> resultClass,
- Class<? extends Annotation> annotation, boolean inherited) {
- if (instance == null) {
- return null;
- }
-
- Field[] fields = resultClass.getDeclaredFields();
- Map<String, Object> fieldName2Value = new HashMap<String, Object>();
-
- for (Field field : fields) {
- if (field.getAnnotation(annotation) != null) {
- Object value = getFieldValue(instance, field);
- final EdmProperty property = field.getAnnotation(EdmProperty.class);
- final String name = property == null || property.name().isEmpty() ? field.getName() : property.name();
- fieldName2Value.put(name, value);
- }
- }
-
- Class<?> superClass = resultClass.getSuperclass();
- if (inherited && superClass != Object.class) {
- Map<String, Object> tmp = getValueForAnnotatedFields(instance, superClass, annotation, true);
- fieldName2Value.putAll(tmp);
- }
-
- return fieldName2Value;
- }
-
- public void setValueForAnnotatedField(Object instance, Class<? extends Annotation> annotation, Object value)
- throws ODataAnnotationException {
- List<Field> fields = getAnnotatedFields(instance, annotation);
-
- if(fields.isEmpty()) {
- throw new ODataAnnotationException("No field found for annotation '" + annotation
- + "' on instance '" + instance + "'.");
- } else if(fields.size() > 1) {
- throw new ODataAnnotationException("More then one field found for annotation '" + annotation
- + "' on instance '" + instance + "'.");
- }
-
- setFieldValue(instance, fields.get(0), value);
- }
-
- public void setValuesToAnnotatedFields(Object instance,
- Class<? extends Annotation> annotation, Map<String, Object> fieldName2Value) {
- List<Field> fields = getAnnotatedFields(instance, annotation);
-
- // XXX: refactore
- for (Field field : fields) {
- final String canonicalName = getCanonicalName(field);
- if (fieldName2Value.containsKey(canonicalName)) {
- Object value = fieldName2Value.get(canonicalName);
- setFieldValue(instance, field, value);
- }
- }
- }
-
- public List<Field> getAnnotatedFields(Object instance, Class<? extends Annotation> annotation) {
- if (instance == null) {
- return null;
- }
- return getAnnotatedFields(instance.getClass(), annotation, true);
- }
-
- public List<Field> getAnnotatedFields(Class<?> fieldClass, Class<? extends Annotation> annotation) {
- return getAnnotatedFields(fieldClass, annotation, true);
- }
-
- /**
- *
- * @param instance
- * @param resultClass
- * @param annotation
- * @param inherited
- * @return
- */
- private List<Field> getAnnotatedFields(Class<?> resultClass,
- Class<? extends Annotation> annotation, boolean inherited) {
- if (resultClass == null) {
- return null;
- }
-
- Field[] fields = resultClass.getDeclaredFields();
- List<Field> annotatedFields = new ArrayList<Field>();
-
- for (Field field : fields) {
- if (field.getAnnotation(annotation) != null) {
- annotatedFields.add(field);
- }
- }
-
- Class<?> superClass = resultClass.getSuperclass();
- if (inherited && superClass != Object.class) {
- List<Field> tmp = getAnnotatedFields(superClass, annotation, true);
- annotatedFields.addAll(tmp);
- }
-
- return annotatedFields;
- }
-
- private Object getValueForField(Object instance, String fieldName, Class<?> resultClass,
- Class<? extends Annotation> annotation, boolean inherited) {
- if (instance == null) {
- return null;
- }
-
- Field[] fields = resultClass.getDeclaredFields();
- for (Field field : fields) {
- if (field.getAnnotation(annotation) != null
- && (fieldName == null || field.getName().equals(fieldName))) {
- return getFieldValue(instance, field);
- }
- }
-
- Class<?> superClass = resultClass.getSuperclass();
- if (inherited && superClass != Object.class) {
- return getValueForField(instance, fieldName, superClass, annotation, true);
- }
-
- return null;
- }
-
- private Object getFieldValue(Object instance, Field field) {
- try {
- boolean access = field.isAccessible();
- field.setAccessible(true);
- Object value = field.get(instance);
- field.setAccessible(access);
- return value;
- } catch (IllegalArgumentException ex) { // should never happen
- throw new ODataRuntimeException(ex);
- } catch (IllegalAccessException ex) { // should never happen
- throw new ODataRuntimeException(ex);
- }
- }
-
- private void setFieldValue(Object instance, Field field, Object value) {
- try {
- Object usedValue = value;
- if (value != null
- && field.getType() != value.getClass()
- && value.getClass() == String.class) {
- usedValue = convert(field, (String) value);
- }
- boolean access = field.isAccessible();
- field.setAccessible(true);
- field.set(instance, usedValue);
- field.setAccessible(access);
- } catch (IllegalArgumentException ex) { // should never happen
- throw new ODataRuntimeException(ex);
- } catch (IllegalAccessException ex) { // should never happen
- throw new ODataRuntimeException(ex);
- }
- }
-
- public Object convert(Field field, String propertyValue) {
- Class<?> fieldClass = field.getType();
- try {
- EdmProperty property = field.getAnnotation(EdmProperty.class);
- EdmSimpleTypeKind type = mapTypeKind(property.type());
- return type.getEdmSimpleTypeInstance().valueOfString(propertyValue,
- EdmLiteralKind.DEFAULT, null, fieldClass);
- } catch (EdmSimpleTypeException ex) {
- throw new ODataRuntimeException("Conversion failed for string property with error: "
- + ex.getMessage(), ex);
- }
- }
-
- public boolean isEdmAnnotated(Object object) {
- if (object == null) {
- return false;
- }
- return isEdmAnnotated(object.getClass());
- }
-
- public boolean isEdmTypeAnnotated(Class<?> clazz) {
- boolean isComplexEntity = clazz.getAnnotation(EdmComplexType.class) != null;
- boolean isEntity = clazz.getAnnotation(EdmEntityType.class) != null;
- return isComplexEntity || isEntity;
- }
-
- public boolean isEdmAnnotated(Class<?> clazz) {
- if (clazz == null) {
- return false;
- } else {
- final boolean isEntity = null != clazz.getAnnotation(EdmEntityType.class);
- final boolean isEntitySet = null != clazz.getAnnotation(EdmEntitySet.class);
- final boolean isComplexEntity = null != clazz.getAnnotation(EdmComplexType.class);
- return isEntity || isComplexEntity || isEntitySet;
- }
- }
-
- public String getCanonicalName(Field field) {
- return firstCharToUpperCase(field.getName());
- }
-
- public String getCanonicalName(Class<?> clazz) {
- return firstCharToUpperCase(clazz.getSimpleName());
- }
-
- private String firstCharToUpperCase(String content) {
- if (content == null || content.isEmpty()) {
- return content;
- }
- return content.substring(0, 1).toUpperCase(Locale.ENGLISH) + content.substring(1);
- }
-
- public EdmSimpleTypeKind mapTypeKind(org.apache.olingo.odata2.api.annotation.edm.EdmType type) {
- switch (type) {
- case BINARY: return EdmSimpleTypeKind.Binary;
- case BOOLEAN: return EdmSimpleTypeKind.Boolean;
- case BYTE: return EdmSimpleTypeKind.Byte;
- case COMPLEX: return EdmSimpleTypeKind.Null;
- case DATE_TIME: return EdmSimpleTypeKind.DateTime;
- case DATE_TIME_OFFSET: return EdmSimpleTypeKind.DateTimeOffset;
- case DECIMAL: return EdmSimpleTypeKind.Decimal;
- case DOUBLE: return EdmSimpleTypeKind.Double;
- case GUID: return EdmSimpleTypeKind.Guid;
- case INT16: return EdmSimpleTypeKind.Int16;
- case INT32: return EdmSimpleTypeKind.Int32;
- case INT64: return EdmSimpleTypeKind.Int64;
- case NULL: return EdmSimpleTypeKind.Null;
- case SBYTE: return EdmSimpleTypeKind.SByte;
- case SINGLE: return EdmSimpleTypeKind.Single;
- case STRING: return EdmSimpleTypeKind.String;
- case TIME: return EdmSimpleTypeKind.Time;
- default: throw new ODataRuntimeException("Unknown type '" + type
- + "' for mapping to EdmSimpleTypeKind.");
- }
- }
-
- public EdmMultiplicity mapMultiplicity(Multiplicity multiplicity) {
- switch (multiplicity) {
- case ZERO_OR_ONE: return EdmMultiplicity.ZERO_TO_ONE;
- case ONE: return EdmMultiplicity.ONE;
- case MANY: return EdmMultiplicity.MANY;
- default: throw new ODataRuntimeException("Unknown type '" + multiplicity + "' for mapping to EdmMultiplicity.");
- }
- }
-
- /**
- *
- */
- private static class EdmAnnotationException extends RuntimeException {
-
- private static final long serialVersionUID = 42L;
-
- public EdmAnnotationException(String message) {
- super(message);
- }
- }
-
- public String getCanonicalNamespace(Class<?> aClass) {
- return generateNamespace(aClass);
- }
-
- public String extractContainerName(Class<?> aClass) {
- EdmEntitySet entitySet = aClass.getAnnotation(EdmEntitySet.class);
- if(entitySet != null) {
- String containerName = entitySet.container();
- if(!containerName.isEmpty()) {
- return containerName;
- }
- }
- return DEFAULT_CONTAINER_NAME;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/8764e11a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/ClassHelper.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/ClassHelper.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/ClassHelper.java
deleted file mode 100644
index 2a4c706..0000000
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/ClassHelper.java
+++ /dev/null
@@ -1,105 +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.core.annotation.edm;
-
-import java.io.File;
-import java.io.FileFilter;
-import java.io.FilenameFilter;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- *
- */
-public class ClassHelper {
-
- private static final File[] EMPTY_FILE_ARRAY = new File[0];
-
- private static final FilenameFilter CLASSFILE_FILTER = new FilenameFilter() {
- @Override
- public boolean accept(File dir, String name) {
- return name.endsWith(CLASSFILE_ENDING);
- }
- public static final String CLASSFILE_ENDING = ".class";
- };
-
- private static final FileFilter FOLDER_FILTER = new FileFilter() {
- @Override
- public boolean accept(File pathname) {
- return pathname.isDirectory();
- }
- };
-
- public static final List<Class<?>> loadClasses(String packageToScan, ClassValidator cv) {
- return loadClasses(packageToScan, CLASSFILE_FILTER, cv);
- }
-
-
- public static final List<Class<?>> loadClasses(String packageToScan, FilenameFilter ff, ClassValidator cv) {
- final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
- String folderToScan = packageToScan.replace(".", "/");
- URL url = classLoader.getResource(folderToScan);
- if(url == null) {
- throw new IllegalArgumentException("No folder to scan found for package '" + packageToScan + "'.");
- }
- File folder = new File(url.getFile());
- File[] classFiles = folder.listFiles(ff);
- if(classFiles == null) {
- classFiles = EMPTY_FILE_ARRAY;
- }
-
- List<Class<?>> annotatedClasses = new ArrayList<Class<?>>(classFiles.length);
- for (File file : classFiles) {
- String name = file.getName();
- String fqn = packageToScan + "." + name.substring(0, name.length() - 6);
- try {
- Class<?> c = classLoader.loadClass(fqn);
- if (cv.isClassValid(c)) {
- annotatedClasses.add(c);
- }
- } catch (ClassNotFoundException ex) {
- throw new IllegalArgumentException("Exception during class loading of class '" + fqn +
- "' with message '" + ex.getMessage() + "'.");
- }
- }
-
- // recursive search
- File[] subfolders = listSubFolder(folder);
- for (File file : subfolders) {
- List<Class<?>> subFolderClazzes = loadClasses(packageToScan + "." + file.getName(), ff, cv);
- annotatedClasses.addAll(subFolderClazzes);
- }
- //
-
- return annotatedClasses;
- }
-
- private static File[] listSubFolder(File folder) {
- File[] subfolders = folder.listFiles(FOLDER_FILTER);
- if(subfolders == null) {
- return EMPTY_FILE_ARRAY;
- }
- return subfolders;
- }
-
- public interface ClassValidator {
- boolean isClassValid(Class<?> c);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/8764e11a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/AnnotationProcessor.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/AnnotationProcessor.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/AnnotationProcessor.java
deleted file mode 100644
index b1b8730..0000000
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/AnnotationProcessor.java
+++ /dev/null
@@ -1,309 +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.core.annotation.processor;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.lang.reflect.Field;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceContent;
-import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceMimeType;
-import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
-import org.apache.olingo.odata2.api.annotation.edm.ds.EntityDataSource;
-import org.apache.olingo.odata2.api.commons.HttpStatusCodes;
-import org.apache.olingo.odata2.api.exception.ODataException;
-import org.apache.olingo.odata2.api.processor.ODataContext;
-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.DeleteUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetEntitySetUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetEntityUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetMediaResourceUriInfo;
-import org.apache.olingo.odata2.api.uri.info.PostUriInfo;
-import org.apache.olingo.odata2.api.uri.info.PutMergePatchUriInfo;
-import org.apache.olingo.odata2.core.annotation.data.DataSourceHolder;
-import org.apache.olingo.odata2.core.annotation.edm.AnnotationHelper;
-import org.apache.olingo.odata2.core.annotation.edm.ClassHelper;
-import org.apache.olingo.odata2.core.annotation.processor.json.EdmAnnotationSerializer;
-import org.apache.olingo.odata2.core.annotation.processor.json.JsonConsumer;
-import org.apache.olingo.odata2.core.exception.ODataRuntimeException;
-
-/**
- *
- */
-public class AnnotationProcessor extends ODataSingleProcessor {
-
- private static final AnnotationHelper ANNOTATION_HELPER = new AnnotationHelper();
-
- private final Map<String, DataSourceHolder> dataSources = new HashMap<String, DataSourceHolder>();
- private ODataContext odataContext;
-
- public AnnotationProcessor(ODataContext context, String packageToScan) {
- odataContext = context;
-
- List<Class<?>> foundClasses = ClassHelper.loadClasses(packageToScan, new ClassHelper.ClassValidator() {
- @Override
- public boolean isClassValid(Class<?> c) {
- return null != c.getAnnotation(EntityDataSource.class);
- }
- });
-
- init(foundClasses);
- }
-
- private void init(List<Class<?>> foundClasses) {
- for (Class<?> clz : foundClasses) {
- DataSourceHolder dhs = new DataSourceHolder(clz);
- dataSources.put(dhs.getEntityName(), dhs);
- }
- }
-
- @Override
- public ODataResponse readEntity(GetEntityUriInfo uriInfo, String contentType) throws ODataException {
- final String name = uriInfo.getTargetType().getName();
-
- List<KeyPredicate> keys = uriInfo.getKeyPredicates();
- DataSourceHolder holder = dataSources.get(name);
- if (holder != null) {
- Object result = holder.readEntity(keys);
- if (result != null) {
- return createODataResponse(result, HttpStatusCodes.OK);
- }
- }
-
- return ODataResponse.status(HttpStatusCodes.NOT_FOUND).build();
- }
-
- @Override
- public ODataResponse readEntitySet(GetEntitySetUriInfo uriInfo, String contentType) throws ODataException {
- final String name = uriInfo.getTargetType().getName();
-
- DataSourceHolder holder = dataSources.get(name);
- if (holder != null) {
- Object result = holder.readEntitySet();
- if (result != null) {
- return createODataResponse(result, HttpStatusCodes.OK);
- }
- }
-
- return ODataResponse.status(HttpStatusCodes.NOT_FOUND).build();
- }
-
- @Override
- public ODataResponse createEntity(PostUriInfo uriInfo, InputStream content,
- String requestContentType, String contentType) throws ODataException {
- final String name = uriInfo.getTargetType().getName();
-
- DataSourceHolder dataSource = dataSources.get(name);
- if (dataSource != null) {
- Object instance = createInstanceFromContent(dataSource, content);
-
- Object result = dataSource.createEntity(instance);
- return createODataResponse(result, HttpStatusCodes.CREATED);
- }
-
- return ODataResponse.status(HttpStatusCodes.BAD_REQUEST).build();
- }
-
- @Override
- public ODataResponse deleteEntity(DeleteUriInfo uriInfo, String contentType) throws ODataException {
- final String name = uriInfo.getTargetType().getName();
-
- DataSourceHolder holder = dataSources.get(name);
- if (holder != null) {
- List<KeyPredicate> keys = uriInfo.getKeyPredicates();
- Object result = holder.deleteEntity(keys);
- if (result != null) {
- return ODataResponse.status(HttpStatusCodes.NO_CONTENT).build();
- }
- }
-
- return ODataResponse.status(HttpStatusCodes.NOT_FOUND).build();
- }
-
- @Override
- public ODataResponse readEntityMedia(GetMediaResourceUriInfo uriInfo, String contentType) throws ODataException {
- final String name = uriInfo.getTargetType().getName();
-
- List<KeyPredicate> keys = uriInfo.getKeyPredicates();
- Object result = readEntity(name, keys);
- if (result != null) {
- Object content = new AnnotationHelper().getValueForField(result, EdmMediaResourceContent.class);
- Object mimeType = new AnnotationHelper().getValueForField(result, EdmMediaResourceMimeType.class);
- return ODataResponse.status(HttpStatusCodes.OK).entity(content).contentHeader(String.valueOf(mimeType)).build();
- }
-
- return ODataResponse.status(HttpStatusCodes.NOT_FOUND).build();
- }
-
- private Object readEntity(String entityName, List<KeyPredicate> keys) {
- DataSourceHolder holder = dataSources.get(entityName);
- if (holder != null) {
- return holder.readEntity(keys);
- }
- return null;
- }
-
-
- private ODataResponse createODataResponse(Object result, HttpStatusCodes statusCode) throws ODataException {
-// StringBuilder resultAsString = new StringBuilder("{\"d\":");
-// if (result != null) {
-// resultAsString.append(result.toString());
-// } else {
-// resultAsString.append("NULL");
-// }
-// resultAsString.append("}");
- EdmAnnotationSerializer jsonSerializer =
- new EdmAnnotationSerializer(odataContext.getPathInfo().getServiceRoot().toASCIIString());
- InputStream resultAsString = jsonSerializer.serialize(result);
- return ODataResponse.status(statusCode)
- .contentHeader("application/json")
- .entity(resultAsString).build();
- }
-
- private Object createInstanceFromContent(DataSourceHolder dataSource, InputStream content)
- throws ODataException {
- try {
- Object instance = dataSource.createEntityInstance();
- Map<String, FieldHolder> propName2Field = extractPropertyFields(dataSource.getEntityTypeClass());
- Map<String, String> contentAsMap = JsonConsumer.readContent(content);
- Set<Map.Entry<String, String>> contentEntries = contentAsMap.entrySet();
- for (Map.Entry<String, String> entry : contentEntries) {
- FieldHolder fh = propName2Field.get(entry.getKey());
- if (fh != null) {
- fh.set(instance, entry.getValue());
- }
- }
- return instance;
- } catch (IOException e) {
- throw new ODataRuntimeException("Unexpected IOException with message: " + e.getMessage());
- }
- }
-
- @Override
- public ODataResponse updateEntity(PutMergePatchUriInfo uriInfo, InputStream content,
- String requestContentType, boolean merge, String contentType) throws ODataException {
- final String name = uriInfo.getTargetType().getName();
-
- DataSourceHolder dataSource = dataSources.get(name);
- if (dataSource != null) {
- Object instance = createInstanceFromContent(dataSource, content);
-
- Object result = dataSource.updateEntity(instance);
- return createODataResponse(result, HttpStatusCodes.OK);
- }
-
- return ODataResponse.status(HttpStatusCodes.BAD_REQUEST).build();
- }
-
- private Map<String, FieldHolder> extractPropertyFields(Class<?> typeClass) {
- if (typeClass == null) {
- return Collections.emptyMap();
- }
- EdmEntityType type = typeClass.getAnnotation(EdmEntityType.class);
- if (type == null) {
- return Collections.emptyMap();
- }
-
- //
- Map<String, FieldHolder> name2Fields = new HashMap<String, FieldHolder>();
- Field[] fields = typeClass.getDeclaredFields();
- for (Field field : fields) {
- FieldHolder fh = FieldHolder.create(field);
- name2Fields.put(fh.propertyName, fh);
- }
-
- //
- Class<?> superClass = typeClass.getSuperclass();
- if (superClass != null && superClass.getAnnotation(EdmEntityType.class) != null) {
- name2Fields.putAll(extractPropertyFields(superClass));
- }
- //
-
- return name2Fields;
- }
-
- /**
- *
- */
- static final class FieldHolder {
-
- final String propertyName;
- final Field propertyField;
-
- public FieldHolder(String propertyName, Field propertyField) {
- this.propertyName = propertyName;
- this.propertyField = propertyField;
- }
-
- public static FieldHolder create(Field field) {
- EdmProperty ep = field.getAnnotation(EdmProperty.class);
- String name;
- if (ep != null && !ep.name().isEmpty()) {
- name = ep.name();
- } else {
- name = ANNOTATION_HELPER.getCanonicalName(field);
- }
- return new FieldHolder(name, field);
- }
-
- public void set(Object instance, Object value) {
- set(instance, String.valueOf(value));
- }
-
- public void set(Object instance, String value) {
- try {
- boolean accessible = propertyField.isAccessible();
- if (!accessible) {
- propertyField.setAccessible(true);
- }
-
- //
- Class<?> type = propertyField.getType();
- if (type == Boolean.class || type == boolean.class) {
- propertyField.set(instance, Boolean.valueOf(value));
- } else if (type == Integer.class || type == int.class) {
- propertyField.set(instance, Integer.valueOf(value));
- } else if (type == Long.class || type == long.class) {
- propertyField.set(instance, Integer.valueOf(value));
- } else {
- propertyField.set(instance, value);
- }
- //
-
- if (!accessible) {
- propertyField.setAccessible(false);
- }
- } catch (Exception ex) {
- }
- }
-
- @Override
- public String toString() {
- return "FieldHolder{" + "propertyName=" + propertyName + ", propertyField=" + propertyField + '}';
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/8764e11a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/json/EdmAnnotationSerializer.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/json/EdmAnnotationSerializer.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/json/EdmAnnotationSerializer.java
deleted file mode 100644
index 7ae9971..0000000
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/json/EdmAnnotationSerializer.java
+++ /dev/null
@@ -1,260 +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.core.annotation.processor.json;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.StringWriter;
-import java.io.Writer;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Field;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
-
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
-import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
-import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
-import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
-import org.apache.olingo.odata2.api.annotation.edm.EdmType;
-import org.apache.olingo.odata2.api.edm.EdmLiteralKind;
-import org.apache.olingo.odata2.api.edm.EdmSimpleTypeException;
-import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
-import org.apache.olingo.odata2.core.annotation.edm.AnnotationHelper;
-import org.apache.olingo.odata2.core.exception.ODataRuntimeException;
-
-public class EdmAnnotationSerializer {
-
- private final String baseUri;
- private static final AnnotationHelper ANNOTATION_HELPER = new AnnotationHelper();
-
- public EdmAnnotationSerializer(String baseUri) {
- this.baseUri = baseUri;
- }
-
- public InputStream serialize(Object obj) {
- byte[] buf = getContent(obj).getBytes();
- InputStream stream = new ByteArrayInputStream(buf);
- return stream;
- }
-
- private String getContent(Object entity) {
- if (entity == null) {
- return "NULL";
- } else if (isConsumable(entity)) {
- try {
- return handleEdmAnnotations(entity);
- } catch (Exception e) {
- throw new ODataRuntimeException("Exception with following message occured: " + e.getMessage(), e);
- }
- } else {
- return entity.toString();
- }
- }
-
- private String handleEdmAnnotations(Object entity)
- throws IllegalArgumentException, IllegalAccessException, IOException {
- //
- Writer writer = new StringWriter();
- JsonWriter json = new JsonWriter(writer);
- json.start();
- writeObject(entity, json);
- json.finish();
- writer.close();
- //
- return writer.toString();
- }
-
- private void writeObject(Object entity, JsonWriter json) throws IllegalAccessException {
- if (entity.getClass().isArray()) {
- List<Object> entities = Arrays.asList(entity);
- writeCollection(entities, json);
- } else if (Collection.class.isAssignableFrom(entity.getClass())) {
- Collection<Object> entities = (Collection<Object>) entity;
- writeCollection(entities, json);
- } else {
- writeSingleObject(entity, json);
- }
- }
-
- private void writeCollection(Collection<Object> entities, JsonWriter json) throws IllegalAccessException {
- json.startObject();
- json.writeName("results");
- json.startArray();
- boolean writeSeperator = false;
- for (Object object : entities) {
- if (writeSeperator) {
- json.writeSeparator();
- } else {
- writeSeperator = true;
- }
- writeSingleObject(object, json);
- }
- json.endArray();
- json.endObject();
- }
-
- private void writeSingleObject(Object entity, JsonWriter json) throws IllegalAccessException {
- List<Field> fields = getAllFields(entity.getClass());
- json.startObject();
- for (Field field : fields) {
- boolean written = writeEdmProperty(entity, json, field);
- if (!written) {
- writeEdmNavigationProperty(entity, json, field);
- }
- }
- json.endObject();
- }
-
- private boolean writeEdmNavigationProperty(Object entity, JsonWriter json, Field field)
- throws IllegalArgumentException, IllegalAccessException {
- EdmNavigationProperty navProperty = field.getAnnotation(EdmNavigationProperty.class);
- EdmEntitySet entitySet = entity.getClass().getAnnotation(EdmEntitySet.class);
- if (navProperty != null) {
- field.setAccessible(true);
- Object keyValue = extractEdmKey(entity);
- json.writeStringProperty("uri", baseUri + entitySet.name() + "('" + keyValue.toString() + "')"
- + "/" + navProperty.association());
- return true;
- }
- return false;
- }
-
- private boolean writeEdmProperty(Object entity, JsonWriter json, Field field) throws IllegalAccessException {
- EdmProperty property = field.getAnnotation(EdmProperty.class);
- if (property != null) {
- field.setAccessible(true);
- Object fieldValue = field.get(entity);
- String name = getName(property, field);
- EdmSimpleTypeKind defaultType = getDefaultSimpleTypeKind(field, property);
- try {
- String value = defaultType.getEdmSimpleTypeInstance().valueToString(fieldValue, EdmLiteralKind.JSON, null);
- write(defaultType, name, value, json);
- } catch (EdmSimpleTypeException e) {
- throw new IllegalArgumentException("Illegal argument for valueToString for EdmSimpleType = '"
- + property.type() + "' with message = '" + e.getMessage() + "'.");
- }
- return true;
- }
- return false;
- }
-
- public void write(EdmSimpleTypeKind kind, String name, String value, JsonWriter jsonStreamWriter) {
- switch (kind) {
- case String:
- jsonStreamWriter.writeStringProperty(name, value);
- break;
- case Boolean:
- case Byte:
- case SByte:
- case Int16:
- case Int32:
- jsonStreamWriter.writeRawProperty(name, value);
- break;
- case DateTime:
- case DateTimeOffset:
- // Although JSON escaping is (and should be) done in the JSON
- // serializer, we backslash-escape the forward slash here explicitly
- // because it is not required to escape it in JSON but in OData.
- jsonStreamWriter.writeRawStringProperty(name, value == null ? null : value.replace("/", "\\/"));
- break;
- default:
- jsonStreamWriter.writeRawStringProperty(name, value);
- break;
- }
- }
-
- private EdmSimpleTypeKind getDefaultSimpleTypeKind(Field field, EdmProperty property) {
- final EdmType type = property.type();
- if (type == EdmType.NULL) {
- Class<?> fieldType = field.getType();
- if (fieldType == String.class) {
- return EdmSimpleTypeKind.String;
- } else if (fieldType == Long.class) {
- return EdmSimpleTypeKind.Int64;
- } else if (fieldType == Integer.class) {
- return EdmSimpleTypeKind.Int32;
- }
- }
- return ANNOTATION_HELPER.mapTypeKind(type);
- }
-
- private Class<?> getType(EdmProperty property) {
- EdmSimpleTypeKind type = ANNOTATION_HELPER.mapTypeKind(property.type());
- Class<?> defaultType = type.getEdmSimpleTypeInstance().getDefaultType();
- return defaultType;
- }
-
- private Object extractEdmKey(Object value) throws IllegalArgumentException, IllegalAccessException {
- Field idField = getFieldWithAnnotation(value.getClass(), EdmKey.class);
- if (idField == null) {
- return "NULL";
- }
- idField.setAccessible(true);
- return idField.get(value);
- }
-
- private Field getFieldWithAnnotation(Class<?> clazz, Class<? extends Annotation> annotationClazz) {
-
- Field[] fields = clazz.getDeclaredFields();
- for (Field field : fields) {
- if (field.getAnnotation(annotationClazz) != null) {
- return field;
- }
- }
-
- Class<?> superclass = clazz.getSuperclass();
- if (superclass != Object.class) {
- return getFieldWithAnnotation(superclass, annotationClazz);
- }
-
- return null;
- }
-
- private List<Field> getAllFields(Class<?> clazz) {
- Field[] fields = clazz.getDeclaredFields();
- List<Field> allFields = new ArrayList<Field>(Arrays.asList(fields));
-
- final Class<?> superclass = clazz.getSuperclass();
- if (superclass != Object.class) {
- allFields.addAll(getAllFields(superclass));
- }
-
- return allFields;
- }
-
- private boolean isConsumable(Object entity) {
- if (entity == null) {
- return false;
- } else if (ANNOTATION_HELPER.isEdmAnnotated(entity)) {
- return true;
- } else if (entity.getClass().isArray() || entity.getClass().isAssignableFrom(Collection.class)) {
- return true;
- } else if (Collection.class.isAssignableFrom(entity.getClass())) {
- return true;
- }
- return false;
- }
-
- private String getName(EdmProperty property, Field field) {
- String name = property.name();
- if (name.isEmpty()) {
- name = ANNOTATION_HELPER.getCanonicalName(field);
- }
- return name;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/8764e11a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/json/JsonConsumer.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/json/JsonConsumer.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/json/JsonConsumer.java
deleted file mode 100644
index 265484d..0000000
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/json/JsonConsumer.java
+++ /dev/null
@@ -1,138 +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.core.annotation.processor.json;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.olingo.odata2.core.ep.util.FormatJson;
-
-import com.google.gson.stream.JsonReader;
-import com.google.gson.stream.JsonToken;
-
-/**
- *
- */
-public class JsonConsumer {
-
- private final JsonReader reader;
- private final Map<String, String> properties;
-
- public JsonConsumer(InputStream content) {
- reader = new JsonReader(new InputStreamReader(content));
- properties = new HashMap<String, String>();
- }
-
- public static Map<String, String> readContent(InputStream content) throws IOException {
- JsonConsumer jc = new JsonConsumer(content);
- return jc.read();
- }
-
- public Map<String, String> read() throws IOException {
-
- reader.beginObject();
- String nextName = reader.nextName();
- if (FormatJson.D.equals(nextName)) {
- reader.beginObject();
- readEntryContent();
- reader.endObject();
- } else {
- handleName(nextName);
- readEntryContent();
- }
- reader.endObject();
-
- return properties;
- }
-
- private void readEntryContent() throws IOException {
- while (reader.hasNext()) {
- final String name = reader.nextName();
- handleName(name);
- }
- }
-
- private void handleName(final String name) throws IOException {
- if (FormatJson.METADATA.equals(name)) {
- readMetadata();
- } else {
- readPropertyValue(name);
- }
- }
-
- private void readPropertyValue(final String name) throws IOException {
- final JsonToken tokenType = reader.peek();
- final String value;
-
- switch (tokenType) {
- case STRING:
- value = reader.nextString();
- break;
- case BOOLEAN:
- value = String.valueOf(reader.nextBoolean());
- break;
- case NULL:
- reader.nextNull();
- default:
- value = null;
- }
-
- properties.put(name, value);
- }
-
- private void readMetadata() throws IOException {
- reader.beginObject();
-
- while (reader.hasNext()) {
- String name = reader.nextName();
-
- if (FormatJson.PROPERTIES.equals(name)) {
- reader.skipValue();
- continue;
- }
-
- String value = reader.nextString();
- if (FormatJson.ID.equals(name)) {
- properties.put("md_" + name, value);
- } else if (FormatJson.URI.equals(name)) {
- properties.put("md_" + name, value);
- } else if (FormatJson.TYPE.equals(name)) {
- properties.put("md_" + name, value);
- } else if (FormatJson.ETAG.equals(name)) {
- properties.put("md_" + name, value);
- } else if (FormatJson.EDIT_MEDIA.equals(name)) {
- properties.put("md_" + name, value);
- } else if (FormatJson.MEDIA_SRC.equals(name)) {
- properties.put("md_" + name, value);
- } else if (FormatJson.MEDIA_ETAG.equals(name)) {
- properties.put("md_" + name, value);
- } else if (FormatJson.CONTENT_TYPE.equals(name)) {
- properties.put("md_" + name, value);
- } else {
- throw new IllegalStateException("Unknown metadata");
- }
- }
-
- reader.endObject();
- }
-
-}
[43/52] git commit: Extract abstract,
rename and refactore processor parts
Posted by mi...@apache.org.
Extract abstract, rename and refactore processor parts
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/28b35fff
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/28b35fff
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/28b35fff
Branch: refs/heads/master
Commit: 28b35fff8c68aec2fbdac3f2f4f127cba62641b6
Parents: 8764e11
Author: Michael Bolz <mi...@apache.org>
Authored: Thu Dec 5 09:44:11 2013 +0100
Committer: Michael Bolz <mi...@apache.org>
Committed: Thu Dec 5 09:44:11 2013 +0100
----------------------------------------------------------------------
.../olingo/odata2/api/data/DataSource.java | 200 +++++++++++++++++++
.../odata2/api/data/DataSourceProcessor.java | 47 +++++
.../olingo/odata2/api/data/ListsDataSource.java | 200 -------------------
.../annotation/data/AnnotationInMemoryDs.java | 4 +-
.../annotation/processor/ListsProcessor.java | 18 +-
.../odata2/fit/ref/EntryXmlReadOnlyTest.java | 15 +-
.../ref/processor/ScenarioDataSource.java | 4 +-
7 files changed, 271 insertions(+), 217 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/28b35fff/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/data/DataSource.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/data/DataSource.java b/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/data/DataSource.java
new file mode 100644
index 0000000..694f199
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/data/DataSource.java
@@ -0,0 +1,200 @@
+/*******************************************************************************
+ * 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.api.data;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.olingo.odata2.api.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.edm.EdmException;
+import org.apache.olingo.odata2.api.edm.EdmFunctionImport;
+import org.apache.olingo.odata2.api.exception.ODataApplicationException;
+import org.apache.olingo.odata2.api.exception.ODataNotFoundException;
+import org.apache.olingo.odata2.api.exception.ODataNotImplementedException;
+
+/**
+ * <p>This interface is intended to make it easier to implement an OData
+ * service in cases where all data for each entity set can be provided as a {@link List} of objects from which all
+ * properties described in the
+ * Entity Data Model can be retrieved and set.</p>
+ * <p>By obeying these restrictions, data-source implementations get the
+ * following advantages:
+ * <ul>
+ * <li>All system query options can be handled centrally.</li>
+ * <li>Following navigation paths must only be done step by step.</li>
+ * </ul>
+ * </p>
+ *
+ */
+public interface DataSource {
+
+ /**
+ * Retrieves the whole data list for the specified entity set.
+ * @param entitySet the requested {@link EdmEntitySet}
+ * @return the requested data list
+ */
+ List<?> readData(EdmEntitySet entitySet) throws ODataNotImplementedException, ODataNotFoundException, EdmException,
+ ODataApplicationException;
+
+ /**
+ * Retrieves a single data object for the specified entity set and key.
+ * @param entitySet the requested {@link EdmEntitySet}
+ * @param keys the entity key as map of key names to key values
+ * @return the requested data object
+ */
+ Object readData(EdmEntitySet entitySet, Map<String, Object> keys) throws ODataNotImplementedException,
+ ODataNotFoundException, EdmException, ODataApplicationException;
+
+ /**
+ * <p>Retrieves data for the specified function import and key.</p>
+ * <p>This method is called also for function imports that have defined in
+ * their metadata an other HTTP method than <code>GET</code>.</p>
+ * @param function the requested {@link EdmFunctionImport}
+ * @param parameters the parameters of the function import
+ * as map of parameter names to parameter values
+ * @param keys the key of the returned entity set, as map of key names to key values,
+ * if the return type of the function import is a collection of entities
+ * (optional)
+ * @return the requested data object, either a list or a single object;
+ * if the function import's return type is of type <code>Binary</code>,
+ * the returned object(s) must be of type {@link BinaryData}
+ */
+ Object readData(EdmFunctionImport function, Map<String, Object> parameters, Map<String, Object> keys)
+ throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException;
+
+ /**
+ * <p>Retrieves related data for the specified source data, entity set, and key.</p>
+ * <p>If the underlying association of the EDM is specified to have target
+ * multiplicity '*' and no target key is given, this method returns a list of
+ * related data, otherwise it returns a single data object.</p>
+ * @param sourceEntitySet the {@link EdmEntitySet} of the source entity
+ * @param sourceData the data object of the source entity
+ * @param targetEntitySet the requested target {@link EdmEntitySet}
+ * @param targetKeys the key of the target entity as map of key names to key values
+ * (optional)
+ * @return the requested releated data object, either a list or a single object
+ */
+ Object readRelatedData(EdmEntitySet sourceEntitySet, Object sourceData, EdmEntitySet targetEntitySet,
+ Map<String, Object> targetKeys) throws ODataNotImplementedException, ODataNotFoundException, EdmException,
+ ODataApplicationException;
+
+ /**
+ * Retrieves the binary data and the MIME type for the media resource
+ * associated to the specified media-link entry.
+ * @param entitySet the {@link EdmEntitySet} of the media-link entry
+ * @param mediaLinkEntryData the data object of the media-link entry
+ * @return the binary data and the MIME type of the media resource
+ */
+ BinaryData readBinaryData(EdmEntitySet entitySet, Object mediaLinkEntryData) throws ODataNotImplementedException,
+ ODataNotFoundException, EdmException, ODataApplicationException;
+
+ /**
+ * <p>Creates and returns a new instance of the requested data-object type.</p>
+ * <p>This instance must not be part of the corresponding list and should
+ * have empty content, apart from the key and other mandatory properties.
+ * However, intermediate objects to access complex properties must not be
+ * <code>null</code>.</p>
+ * @param entitySet the {@link EdmEntitySet} the object must correspond to
+ * @return the new data object
+ */
+ Object newDataObject(EdmEntitySet entitySet) throws ODataNotImplementedException, EdmException,
+ ODataApplicationException;
+
+ /**
+ * Writes the binary data for the media resource associated to the
+ * specified media-link entry.
+ * @param entitySet the {@link EdmEntitySet} of the media-link entry
+ * @param mediaLinkEntryData the data object of the media-link entry
+ * @param binaryData the binary data of the media resource along with
+ * the MIME type of the binary data
+ */
+ void writeBinaryData(EdmEntitySet entitySet, Object mediaLinkEntryData, BinaryData binaryData)
+ throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException;
+
+ /**
+ * Deletes a single data object identified by the specified entity set and key.
+ * @param entitySet the {@link EdmEntitySet} of the entity to be deleted
+ * @param keys the entity key as map of key names to key values
+ */
+ void deleteData(EdmEntitySet entitySet, Map<String, Object> keys) throws ODataNotImplementedException,
+ ODataNotFoundException, EdmException, ODataApplicationException;
+
+ /**
+ * <p>Inserts an instance into the entity list of the specified entity set.</p>
+ * <p>If {@link #newDataObject} has not set the key and other mandatory
+ * properties already, this method must set them before inserting the
+ * instance into the list.</p>
+ * @param entitySet the {@link EdmEntitySet} the object must correspond to
+ * @param data the data object of the new entity
+ */
+ void createData(EdmEntitySet entitySet, Object data) throws ODataNotImplementedException, EdmException,
+ ODataApplicationException;
+
+ /**
+ * Deletes the relation from the specified source data to a target entity
+ * specified by entity set and key.
+ * @param sourceEntitySet the {@link EdmEntitySet} of the source entity
+ * @param sourceData the data object of the source entity
+ * @param targetEntitySet the {@link EdmEntitySet} of the target entity
+ * @param targetKeys the key of the target entity as map of key names to key values
+ * (optional)
+ */
+ void deleteRelation(EdmEntitySet sourceEntitySet, Object sourceData, EdmEntitySet targetEntitySet,
+ Map<String, Object> targetKeys) throws ODataNotImplementedException, ODataNotFoundException, EdmException,
+ ODataApplicationException;
+
+ /**
+ * Writes a relation from the specified source data to a target entity
+ * specified by entity set and key.
+ * @param sourceEntitySet the {@link EdmEntitySet} of the source entity
+ * @param sourceData the data object of the source entity
+ * @param targetEntitySet the {@link EdmEntitySet} of the relation target
+ * @param targetKeys the key of the target entity as map of key names to key values
+ */
+ void writeRelation(EdmEntitySet sourceEntitySet, Object sourceData, EdmEntitySet targetEntitySet,
+ Map<String, Object> targetKeys) throws ODataNotImplementedException, ODataNotFoundException, EdmException,
+ ODataApplicationException;
+
+ /**
+ * Container to store binary data (as byte array) and the associated MIME type.
+ */
+ public class BinaryData {
+ private final byte[] data;
+ private final String mimeType;
+
+ public BinaryData(final byte[] data, final String mimeType) {
+ this.data = data;
+ this.mimeType = mimeType;
+ }
+
+ public byte[] getData() {
+ return data;
+ }
+
+ public String getMimeType() {
+ return mimeType;
+ }
+
+ @Override
+ public String toString() {
+ return "data=" + Arrays.toString(data) + ", mimeType=" + mimeType;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/28b35fff/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/data/DataSourceProcessor.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/data/DataSourceProcessor.java b/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/data/DataSourceProcessor.java
new file mode 100644
index 0000000..2be5663
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/data/DataSourceProcessor.java
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * 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.api.data;
+
+import org.apache.olingo.odata2.api.processor.ODataSingleProcessor;
+
+/**
+ * Abstract class for implementation of the centralized parts of OData processing,
+ * allowing to use the simplified {@link DataSource} and {@link ValueAccess} for the
+ * actual data handling.
+ * <br/>
+ * Extend this class and implement a DataSourceProcessor if the default implementation
+ * (<code>ListProcessor</code> found in <code>annotation-processor-core module</code>) has to be overwritten.
+ */
+public abstract class DataSourceProcessor extends ODataSingleProcessor {
+
+ protected final DataSource dataSource;
+ protected final ValueAccess valueAccess;
+
+ /**
+ * Initialize a {@link DataSourceProcessor} in combination with given {@link DataSource} (providing data objects)
+ * and {@link ValueAccess} (accessing values of data objects).
+ *
+ * @param dataSource used for accessing the data objects
+ * @param valueAccess for accessing the values provided by the data objects
+ */
+ public DataSourceProcessor(final DataSource dataSource, final ValueAccess valueAccess) {
+ this.dataSource = dataSource;
+ this.valueAccess = valueAccess;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/28b35fff/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/data/ListsDataSource.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/data/ListsDataSource.java b/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/data/ListsDataSource.java
deleted file mode 100644
index e9229e3..0000000
--- a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/data/ListsDataSource.java
+++ /dev/null
@@ -1,200 +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.api.data;
-
-import java.util.Arrays;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.olingo.odata2.api.edm.EdmEntitySet;
-import org.apache.olingo.odata2.api.edm.EdmException;
-import org.apache.olingo.odata2.api.edm.EdmFunctionImport;
-import org.apache.olingo.odata2.api.exception.ODataApplicationException;
-import org.apache.olingo.odata2.api.exception.ODataNotFoundException;
-import org.apache.olingo.odata2.api.exception.ODataNotImplementedException;
-
-/**
- * <p>This interface is intended to make it easier to implement an OData
- * service in cases where all data for each entity set can be provided as a {@link List} of objects from which all
- * properties described in the
- * Entity Data Model can be retrieved and set.</p>
- * <p>By obeying these restrictions, data-source implementations get the
- * following advantages:
- * <ul>
- * <li>All system query options can be handled centrally.</li>
- * <li>Following navigation paths must only be done step by step.</li>
- * </ul>
- * </p>
- *
- */
-public interface ListsDataSource {
-
- /**
- * Retrieves the whole data list for the specified entity set.
- * @param entitySet the requested {@link EdmEntitySet}
- * @return the requested data list
- */
- List<?> readData(EdmEntitySet entitySet) throws ODataNotImplementedException, ODataNotFoundException, EdmException,
- ODataApplicationException;
-
- /**
- * Retrieves a single data object for the specified entity set and key.
- * @param entitySet the requested {@link EdmEntitySet}
- * @param keys the entity key as map of key names to key values
- * @return the requested data object
- */
- Object readData(EdmEntitySet entitySet, Map<String, Object> keys) throws ODataNotImplementedException,
- ODataNotFoundException, EdmException, ODataApplicationException;
-
- /**
- * <p>Retrieves data for the specified function import and key.</p>
- * <p>This method is called also for function imports that have defined in
- * their metadata an other HTTP method than <code>GET</code>.</p>
- * @param function the requested {@link EdmFunctionImport}
- * @param parameters the parameters of the function import
- * as map of parameter names to parameter values
- * @param keys the key of the returned entity set, as map of key names to key values,
- * if the return type of the function import is a collection of entities
- * (optional)
- * @return the requested data object, either a list or a single object;
- * if the function import's return type is of type <code>Binary</code>,
- * the returned object(s) must be of type {@link BinaryData}
- */
- Object readData(EdmFunctionImport function, Map<String, Object> parameters, Map<String, Object> keys)
- throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException;
-
- /**
- * <p>Retrieves related data for the specified source data, entity set, and key.</p>
- * <p>If the underlying association of the EDM is specified to have target
- * multiplicity '*' and no target key is given, this method returns a list of
- * related data, otherwise it returns a single data object.</p>
- * @param sourceEntitySet the {@link EdmEntitySet} of the source entity
- * @param sourceData the data object of the source entity
- * @param targetEntitySet the requested target {@link EdmEntitySet}
- * @param targetKeys the key of the target entity as map of key names to key values
- * (optional)
- * @return the requested releated data object, either a list or a single object
- */
- Object readRelatedData(EdmEntitySet sourceEntitySet, Object sourceData, EdmEntitySet targetEntitySet,
- Map<String, Object> targetKeys) throws ODataNotImplementedException, ODataNotFoundException, EdmException,
- ODataApplicationException;
-
- /**
- * Retrieves the binary data and the MIME type for the media resource
- * associated to the specified media-link entry.
- * @param entitySet the {@link EdmEntitySet} of the media-link entry
- * @param mediaLinkEntryData the data object of the media-link entry
- * @return the binary data and the MIME type of the media resource
- */
- BinaryData readBinaryData(EdmEntitySet entitySet, Object mediaLinkEntryData) throws ODataNotImplementedException,
- ODataNotFoundException, EdmException, ODataApplicationException;
-
- /**
- * <p>Creates and returns a new instance of the requested data-object type.</p>
- * <p>This instance must not be part of the corresponding list and should
- * have empty content, apart from the key and other mandatory properties.
- * However, intermediate objects to access complex properties must not be
- * <code>null</code>.</p>
- * @param entitySet the {@link EdmEntitySet} the object must correspond to
- * @return the new data object
- */
- Object newDataObject(EdmEntitySet entitySet) throws ODataNotImplementedException, EdmException,
- ODataApplicationException;
-
- /**
- * Writes the binary data for the media resource associated to the
- * specified media-link entry.
- * @param entitySet the {@link EdmEntitySet} of the media-link entry
- * @param mediaLinkEntryData the data object of the media-link entry
- * @param binaryData the binary data of the media resource along with
- * the MIME type of the binary data
- */
- void writeBinaryData(EdmEntitySet entitySet, Object mediaLinkEntryData, BinaryData binaryData)
- throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException;
-
- /**
- * Deletes a single data object identified by the specified entity set and key.
- * @param entitySet the {@link EdmEntitySet} of the entity to be deleted
- * @param keys the entity key as map of key names to key values
- */
- void deleteData(EdmEntitySet entitySet, Map<String, Object> keys) throws ODataNotImplementedException,
- ODataNotFoundException, EdmException, ODataApplicationException;
-
- /**
- * <p>Inserts an instance into the entity list of the specified entity set.</p>
- * <p>If {@link #newDataObject} has not set the key and other mandatory
- * properties already, this method must set them before inserting the
- * instance into the list.</p>
- * @param entitySet the {@link EdmEntitySet} the object must correspond to
- * @param data the data object of the new entity
- */
- void createData(EdmEntitySet entitySet, Object data) throws ODataNotImplementedException, EdmException,
- ODataApplicationException;
-
- /**
- * Deletes the relation from the specified source data to a target entity
- * specified by entity set and key.
- * @param sourceEntitySet the {@link EdmEntitySet} of the source entity
- * @param sourceData the data object of the source entity
- * @param targetEntitySet the {@link EdmEntitySet} of the target entity
- * @param targetKeys the key of the target entity as map of key names to key values
- * (optional)
- */
- void deleteRelation(EdmEntitySet sourceEntitySet, Object sourceData, EdmEntitySet targetEntitySet,
- Map<String, Object> targetKeys) throws ODataNotImplementedException, ODataNotFoundException, EdmException,
- ODataApplicationException;
-
- /**
- * Writes a relation from the specified source data to a target entity
- * specified by entity set and key.
- * @param sourceEntitySet the {@link EdmEntitySet} of the source entity
- * @param sourceData the data object of the source entity
- * @param targetEntitySet the {@link EdmEntitySet} of the relation target
- * @param targetKeys the key of the target entity as map of key names to key values
- */
- void writeRelation(EdmEntitySet sourceEntitySet, Object sourceData, EdmEntitySet targetEntitySet,
- Map<String, Object> targetKeys) throws ODataNotImplementedException, ODataNotFoundException, EdmException,
- ODataApplicationException;
-
- /**
- * Container to store binary data (as byte array) and the associated MIME type.
- */
- public class BinaryData {
- private final byte[] data;
- private final String mimeType;
-
- public BinaryData(final byte[] data, final String mimeType) {
- this.data = data;
- this.mimeType = mimeType;
- }
-
- public byte[] getData() {
- return data;
- }
-
- public String getMimeType() {
- return mimeType;
- }
-
- @Override
- public String toString() {
- return "data=" + Arrays.toString(data) + ", mimeType=" + mimeType;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/28b35fff/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationInMemoryDs.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationInMemoryDs.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationInMemoryDs.java
index 030cc93..db03a4c 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationInMemoryDs.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationInMemoryDs.java
@@ -24,7 +24,7 @@ import java.util.Map;
import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceContent;
import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceMimeType;
import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
-import org.apache.olingo.odata2.api.data.ListsDataSource;
+import org.apache.olingo.odata2.api.data.DataSource;
import org.apache.olingo.odata2.api.edm.EdmEntitySet;
import org.apache.olingo.odata2.api.edm.EdmException;
import org.apache.olingo.odata2.api.edm.EdmFunctionImport;
@@ -38,7 +38,7 @@ import org.apache.olingo.odata2.core.annotation.util.AnnotationHelper.AnnotatedN
import org.apache.olingo.odata2.core.annotation.util.AnnotationHelper.ODataAnnotationException;
import org.apache.olingo.odata2.core.exception.ODataRuntimeException;
-public class AnnotationInMemoryDs implements ListsDataSource {
+public class AnnotationInMemoryDs implements DataSource {
private static final AnnotationHelper ANNOTATION_HELPER = new AnnotationHelper();
private final Map<String, DataStore<Object>> dataStores = new HashMap<String, DataStore<Object>>();
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/28b35fff/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/ListsProcessor.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/ListsProcessor.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/ListsProcessor.java
index 16e1eab..19218d7 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/ListsProcessor.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/ListsProcessor.java
@@ -36,8 +36,9 @@ import org.apache.olingo.odata2.api.batch.BatchResponsePart;
import org.apache.olingo.odata2.api.commons.HttpContentType;
import org.apache.olingo.odata2.api.commons.HttpStatusCodes;
import org.apache.olingo.odata2.api.commons.InlineCount;
-import org.apache.olingo.odata2.api.data.ListsDataSource;
-import org.apache.olingo.odata2.api.data.ListsDataSource.BinaryData;
+import org.apache.olingo.odata2.api.data.DataSource;
+import org.apache.olingo.odata2.api.data.DataSource.BinaryData;
+import org.apache.olingo.odata2.api.data.DataSourceProcessor;
import org.apache.olingo.odata2.api.data.ValueAccess;
import org.apache.olingo.odata2.api.edm.Edm;
import org.apache.olingo.odata2.api.edm.EdmConcurrencyMode;
@@ -81,7 +82,6 @@ import org.apache.olingo.odata2.api.exception.ODataNotImplementedException;
import org.apache.olingo.odata2.api.processor.ODataContext;
import org.apache.olingo.odata2.api.processor.ODataRequest;
import org.apache.olingo.odata2.api.processor.ODataResponse;
-import org.apache.olingo.odata2.api.processor.ODataSingleProcessor;
import org.apache.olingo.odata2.api.uri.ExpandSelectTreeNode;
import org.apache.olingo.odata2.api.uri.KeyPredicate;
import org.apache.olingo.odata2.api.uri.NavigationSegment;
@@ -117,21 +117,17 @@ import org.apache.olingo.odata2.api.uri.info.PutMergePatchUriInfo;
/**
* Implementation of the centralized parts of OData processing,
- * allowing to use the simplified {@link ListsDataSource} for the
+ * allowing to use the simplified {@link DataSource} for the
* actual data handling.
*
*/
-public class ListsProcessor extends ODataSingleProcessor {
+public class ListsProcessor extends DataSourceProcessor {
// TODO: Paging size should be configurable.
private static final int SERVER_PAGING_SIZE = 100;
- private final ListsDataSource dataSource;
- private final ValueAccess valueAccess;
-
- public ListsProcessor(final ListsDataSource dataSource, final ValueAccess valueAccess) {
- this.dataSource = dataSource;
- this.valueAccess = valueAccess;
+ public ListsProcessor(final DataSource dataSource, final ValueAccess valueAccess) {
+ super(dataSource, valueAccess);
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/28b35fff/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/EntryXmlReadOnlyTest.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/EntryXmlReadOnlyTest.java b/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/EntryXmlReadOnlyTest.java
index eec1f42..6e319c6 100644
--- a/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/EntryXmlReadOnlyTest.java
+++ b/odata2-lib/odata-fit/src/test/java/org/apache/olingo/odata2/fit/ref/EntryXmlReadOnlyTest.java
@@ -96,10 +96,10 @@ public class EntryXmlReadOnlyTest extends AbstractRefXmlTest {
public void entryWithSpecialKey() throws Exception {
// Ugly hack to create an entity with a key containing special characters just for this test.
ListsProcessor processor = (ListsProcessor) getService().getEntityProcessor();
- Field field = processor.getClass().getDeclaredField("dataSource");
+ Field field = getField(processor.getClass(), "dataSource");
field.setAccessible(true);
ScenarioDataSource dataSource = (ScenarioDataSource) field.get(processor);
- field = dataSource.getClass().getDeclaredField("dataContainer");
+ field = getField(dataSource.getClass(), "dataContainer");
field.setAccessible(true);
DataContainer dataContainer = (DataContainer) field.get(dataSource);
// Add a new Photo where the "Type" property is set to, space-separated,
@@ -118,6 +118,17 @@ public class EntryXmlReadOnlyTest extends AbstractRefXmlTest {
assertXpathEvaluatesTo(expected + "/$value", "/atom:entry/atom:link[@rel=\"edit-media\"]/@href", body);
}
+ private Field getField(Class<?> clazz, String string) throws Exception {
+ try {
+ return clazz.getDeclaredField(string);
+ } catch (NoSuchFieldException e) {
+ if(clazz == Object.class) {
+ throw e;
+ }
+ return getField(clazz.getSuperclass(), string);
+ }
+ }
+
@Test
public void expand() throws Exception {
HttpResponse response = callUri("Employees('5')?$expand=ne_Manager");
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/28b35fff/odata2-lib/odata-ref/src/main/java/org/apache/olingo/odata2/ref/processor/ScenarioDataSource.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-ref/src/main/java/org/apache/olingo/odata2/ref/processor/ScenarioDataSource.java b/odata2-lib/odata-ref/src/main/java/org/apache/olingo/odata2/ref/processor/ScenarioDataSource.java
index 0047226..cc70639 100644
--- a/odata2-lib/odata-ref/src/main/java/org/apache/olingo/odata2/ref/processor/ScenarioDataSource.java
+++ b/odata2-lib/odata-ref/src/main/java/org/apache/olingo/odata2/ref/processor/ScenarioDataSource.java
@@ -28,7 +28,7 @@ import java.util.Map;
import java.util.Map.Entry;
import org.apache.olingo.odata2.api.commons.HttpContentType;
-import org.apache.olingo.odata2.api.data.ListsDataSource;
+import org.apache.olingo.odata2.api.data.DataSource;
import org.apache.olingo.odata2.api.edm.EdmEntitySet;
import org.apache.olingo.odata2.api.edm.EdmException;
import org.apache.olingo.odata2.api.edm.EdmFunctionImport;
@@ -48,7 +48,7 @@ import org.apache.olingo.odata2.ref.model.Team;
* Data for the reference scenario
*
*/
-public class ScenarioDataSource implements ListsDataSource {
+public class ScenarioDataSource implements DataSource {
private static final String ENTITYSET_1_1 = "Employees";
private static final String ENTITYSET_1_2 = "Teams";
[14/52] Poc for ListsDs and Processor
Posted by mi...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d83070de/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/ListsProcessor.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/ListsProcessor.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/ListsProcessor.java
new file mode 100644
index 0000000..26c85df
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/ListsProcessor.java
@@ -0,0 +1,1625 @@
+/*******************************************************************************
+ * 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.core.annotation.processor;
+
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+
+import org.apache.olingo.odata2.api.ODataCallback;
+import org.apache.olingo.odata2.api.batch.BatchHandler;
+import org.apache.olingo.odata2.api.batch.BatchRequestPart;
+import org.apache.olingo.odata2.api.batch.BatchResponsePart;
+import org.apache.olingo.odata2.api.commons.HttpContentType;
+import org.apache.olingo.odata2.api.commons.HttpStatusCodes;
+import org.apache.olingo.odata2.api.commons.InlineCount;
+import org.apache.olingo.odata2.api.data.ListsDataSource;
+import org.apache.olingo.odata2.api.data.ListsDataSource.BinaryData;
+import org.apache.olingo.odata2.api.data.ValueAccess;
+import org.apache.olingo.odata2.api.edm.Edm;
+import org.apache.olingo.odata2.api.edm.EdmConcurrencyMode;
+import org.apache.olingo.odata2.api.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.edm.EdmException;
+import org.apache.olingo.odata2.api.edm.EdmFunctionImport;
+import org.apache.olingo.odata2.api.edm.EdmLiteral;
+import org.apache.olingo.odata2.api.edm.EdmLiteralKind;
+import org.apache.olingo.odata2.api.edm.EdmMapping;
+import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
+import org.apache.olingo.odata2.api.edm.EdmNavigationProperty;
+import org.apache.olingo.odata2.api.edm.EdmProperty;
+import org.apache.olingo.odata2.api.edm.EdmSimpleType;
+import org.apache.olingo.odata2.api.edm.EdmSimpleTypeException;
+import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
+import org.apache.olingo.odata2.api.edm.EdmStructuralType;
+import org.apache.olingo.odata2.api.edm.EdmType;
+import org.apache.olingo.odata2.api.edm.EdmTypeKind;
+import org.apache.olingo.odata2.api.edm.EdmTyped;
+import org.apache.olingo.odata2.api.ep.EntityProvider;
+import org.apache.olingo.odata2.api.ep.EntityProviderBatchProperties;
+import org.apache.olingo.odata2.api.ep.EntityProviderException;
+import org.apache.olingo.odata2.api.ep.EntityProviderReadProperties;
+import org.apache.olingo.odata2.api.ep.EntityProviderWriteProperties;
+import org.apache.olingo.odata2.api.ep.callback.OnWriteEntryContent;
+import org.apache.olingo.odata2.api.ep.callback.OnWriteFeedContent;
+import org.apache.olingo.odata2.api.ep.callback.WriteCallbackContext;
+import org.apache.olingo.odata2.api.ep.callback.WriteEntryCallbackContext;
+import org.apache.olingo.odata2.api.ep.callback.WriteEntryCallbackResult;
+import org.apache.olingo.odata2.api.ep.callback.WriteFeedCallbackContext;
+import org.apache.olingo.odata2.api.ep.callback.WriteFeedCallbackResult;
+import org.apache.olingo.odata2.api.ep.entry.ODataEntry;
+import org.apache.olingo.odata2.api.ep.feed.ODataFeed;
+import org.apache.olingo.odata2.api.exception.ODataApplicationException;
+import org.apache.olingo.odata2.api.exception.ODataBadRequestException;
+import org.apache.olingo.odata2.api.exception.ODataException;
+import org.apache.olingo.odata2.api.exception.ODataHttpException;
+import org.apache.olingo.odata2.api.exception.ODataNotFoundException;
+import org.apache.olingo.odata2.api.exception.ODataNotImplementedException;
+import org.apache.olingo.odata2.api.processor.ODataContext;
+import org.apache.olingo.odata2.api.processor.ODataRequest;
+import org.apache.olingo.odata2.api.processor.ODataResponse;
+import org.apache.olingo.odata2.api.processor.ODataSingleProcessor;
+import org.apache.olingo.odata2.api.uri.ExpandSelectTreeNode;
+import org.apache.olingo.odata2.api.uri.KeyPredicate;
+import org.apache.olingo.odata2.api.uri.NavigationSegment;
+import org.apache.olingo.odata2.api.uri.PathInfo;
+import org.apache.olingo.odata2.api.uri.UriParser;
+import org.apache.olingo.odata2.api.uri.expression.BinaryExpression;
+import org.apache.olingo.odata2.api.uri.expression.CommonExpression;
+import org.apache.olingo.odata2.api.uri.expression.ExpressionKind;
+import org.apache.olingo.odata2.api.uri.expression.FilterExpression;
+import org.apache.olingo.odata2.api.uri.expression.LiteralExpression;
+import org.apache.olingo.odata2.api.uri.expression.MemberExpression;
+import org.apache.olingo.odata2.api.uri.expression.MethodExpression;
+import org.apache.olingo.odata2.api.uri.expression.OrderByExpression;
+import org.apache.olingo.odata2.api.uri.expression.OrderExpression;
+import org.apache.olingo.odata2.api.uri.expression.PropertyExpression;
+import org.apache.olingo.odata2.api.uri.expression.SortOrder;
+import org.apache.olingo.odata2.api.uri.expression.UnaryExpression;
+import org.apache.olingo.odata2.api.uri.info.DeleteUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetComplexPropertyUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetEntityCountUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetEntityLinkCountUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetEntityLinkUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetEntitySetCountUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetEntitySetLinksCountUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetEntitySetLinksUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetEntitySetUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetEntityUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetFunctionImportUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetMediaResourceUriInfo;
+import org.apache.olingo.odata2.api.uri.info.GetSimplePropertyUriInfo;
+import org.apache.olingo.odata2.api.uri.info.PostUriInfo;
+import org.apache.olingo.odata2.api.uri.info.PutMergePatchUriInfo;
+
+/**
+ * Implementation of the centralized parts of OData processing,
+ * allowing to use the simplified {@link ListsDataSource} for the
+ * actual data handling.
+ *
+ */
+public class ListsProcessor extends ODataSingleProcessor {
+
+ // TODO: Paging size should be configurable.
+ private static final int SERVER_PAGING_SIZE = 100;
+
+ private final ListsDataSource dataSource;
+ private final ValueAccess valueAccess;
+
+ public ListsProcessor(final ListsDataSource dataSource, final ValueAccess valueAccess) {
+ this.dataSource = dataSource;
+ this.valueAccess = valueAccess;
+ }
+
+ @Override
+ public ODataResponse readEntitySet(final GetEntitySetUriInfo uriInfo, final String contentType)
+ throws ODataException {
+ ArrayList<Object> data = new ArrayList<Object>();
+ try {
+ data.addAll((List<?>) retrieveData(
+ uriInfo.getStartEntitySet(),
+ uriInfo.getKeyPredicates(),
+ uriInfo.getFunctionImport(),
+ mapFunctionParameters(uriInfo.getFunctionImportParameters()),
+ uriInfo.getNavigationSegments()));
+ } catch (final ODataNotFoundException e) {
+ data.clear();
+ }
+
+ final EdmEntitySet entitySet = uriInfo.getTargetEntitySet();
+ final InlineCount inlineCountType = uriInfo.getInlineCount();
+ final Integer count = applySystemQueryOptions(
+ entitySet,
+ data,
+ uriInfo.getFilter(),
+ inlineCountType,
+ uriInfo.getOrderBy(),
+ uriInfo.getSkipToken(),
+ uriInfo.getSkip(),
+ uriInfo.getTop());
+
+ ODataContext context = getContext();
+ String nextLink = null;
+
+ // Limit the number of returned entities and provide a "next" link
+ // if there are further entities.
+ // Almost all system query options in the current request must be carried
+ // over to the URI for the "next" link, with the exception of $skiptoken
+ // and $skip.
+ if (data.size() > SERVER_PAGING_SIZE) {
+ if (uriInfo.getOrderBy() == null
+ && uriInfo.getSkipToken() == null
+ && uriInfo.getSkip() == null
+ && uriInfo.getTop() == null) {
+ sortInDefaultOrder(entitySet, data);
+ }
+
+ // TODO: Percent-encode "next" link.
+ nextLink = context.getPathInfo().getServiceRoot().relativize(context.getPathInfo().getRequestUri()).toString()
+ .replaceAll("\\$skiptoken=.+?&?", "")
+ .replaceAll("\\$skip=.+?&?", "")
+ .replaceFirst("(?:\\?|&)$", ""); // Remove potentially trailing "?" or "&" left over from remove actions
+ // above.
+ nextLink += (nextLink.contains("?") ? "&" : "?")
+ + "$skiptoken=" + getSkipToken(entitySet, data.get(SERVER_PAGING_SIZE));
+
+ while (data.size() > SERVER_PAGING_SIZE) {
+ data.remove(SERVER_PAGING_SIZE);
+ }
+ }
+
+ final EdmEntityType entityType = entitySet.getEntityType();
+ List<Map<String, Object>> values = new ArrayList<Map<String, Object>>();
+ for (final Object entryData : data) {
+ values.add(getStructuralTypeValueMap(entryData, entityType));
+ }
+
+ final EntityProviderWriteProperties feedProperties = EntityProviderWriteProperties
+ .serviceRoot(context.getPathInfo().getServiceRoot())
+ .inlineCountType(inlineCountType)
+ .inlineCount(count)
+ .expandSelectTree(UriParser.createExpandSelectTree(uriInfo.getSelect(), uriInfo.getExpand()))
+ .callbacks(getCallbacks(data, entityType))
+ .nextLink(nextLink)
+ .build();
+
+ final int timingHandle = context.startRuntimeMeasurement("EntityProvider", "writeFeed");
+ final ODataResponse response = EntityProvider.writeFeed(contentType, entitySet, values, feedProperties);
+
+ context.stopRuntimeMeasurement(timingHandle);
+
+ return ODataResponse.fromResponse(response).build();
+ }
+
+ @Override
+ public ODataResponse countEntitySet(final GetEntitySetCountUriInfo uriInfo, final String contentType)
+ throws ODataException {
+ ArrayList<Object> data = new ArrayList<Object>();
+ try {
+ data.addAll((List<?>) retrieveData(
+ uriInfo.getStartEntitySet(),
+ uriInfo.getKeyPredicates(),
+ uriInfo.getFunctionImport(),
+ mapFunctionParameters(uriInfo.getFunctionImportParameters()),
+ uriInfo.getNavigationSegments()));
+ } catch (final ODataNotFoundException e) {
+ data.clear();
+ }
+
+ applySystemQueryOptions(
+ uriInfo.getTargetEntitySet(),
+ data,
+ uriInfo.getFilter(),
+ null,
+ null,
+ null,
+ uriInfo.getSkip(),
+ uriInfo.getTop());
+
+ return ODataResponse.fromResponse(EntityProvider.writeText(String.valueOf(data.size()))).build();
+ }
+
+ @Override
+ public ODataResponse readEntityLinks(final GetEntitySetLinksUriInfo uriInfo, final String contentType)
+ throws ODataException {
+ ArrayList<Object> data = new ArrayList<Object>();
+ try {
+ data.addAll((List<?>) retrieveData(
+ uriInfo.getStartEntitySet(),
+ uriInfo.getKeyPredicates(),
+ uriInfo.getFunctionImport(),
+ mapFunctionParameters(uriInfo.getFunctionImportParameters()),
+ uriInfo.getNavigationSegments()));
+ } catch (final ODataNotFoundException e) {
+ data.clear();
+ }
+
+ final Integer count = applySystemQueryOptions(
+ uriInfo.getTargetEntitySet(),
+ data,
+ uriInfo.getFilter(),
+ uriInfo.getInlineCount(),
+ null, // uriInfo.getOrderBy(),
+ uriInfo.getSkipToken(),
+ uriInfo.getSkip(),
+ uriInfo.getTop());
+
+ final EdmEntitySet entitySet = uriInfo.getTargetEntitySet();
+
+ List<Map<String, Object>> values = new ArrayList<Map<String, Object>>();
+ for (final Object entryData : data) {
+ Map<String, Object> entryValues = new HashMap<String, Object>();
+ for (final EdmProperty property : entitySet.getEntityType().getKeyProperties()) {
+ entryValues.put(property.getName(), valueAccess.getPropertyValue(entryData, property));
+ }
+ values.add(entryValues);
+ }
+
+ ODataContext context = getContext();
+ final EntityProviderWriteProperties entryProperties = EntityProviderWriteProperties
+ .serviceRoot(context.getPathInfo().getServiceRoot())
+ .inlineCountType(uriInfo.getInlineCount())
+ .inlineCount(count)
+ .build();
+
+ final int timingHandle = context.startRuntimeMeasurement("EntityProvider", "writeLinks");
+
+ final ODataResponse response = EntityProvider.writeLinks(contentType, entitySet, values, entryProperties);
+
+ context.stopRuntimeMeasurement(timingHandle);
+
+ return ODataResponse.fromResponse(response).build();
+ }
+
+ @Override
+ public ODataResponse countEntityLinks(final GetEntitySetLinksCountUriInfo uriInfo, final String contentType)
+ throws ODataException {
+ return countEntitySet((GetEntitySetCountUriInfo) uriInfo, contentType);
+ }
+
+ @Override
+ public ODataResponse readEntity(final GetEntityUriInfo uriInfo, final String contentType) throws ODataException {
+ final Object data = retrieveData(
+ uriInfo.getStartEntitySet(),
+ uriInfo.getKeyPredicates(),
+ uriInfo.getFunctionImport(),
+ mapFunctionParameters(uriInfo.getFunctionImportParameters()),
+ uriInfo.getNavigationSegments());
+
+ if (!appliesFilter(data, uriInfo.getFilter())) {
+ throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
+ }
+
+ final ExpandSelectTreeNode expandSelectTreeNode =
+ UriParser.createExpandSelectTree(uriInfo.getSelect(), uriInfo.getExpand());
+ ODataResponse odr =
+ ODataResponse.fromResponse(writeEntry(uriInfo.getTargetEntitySet(), expandSelectTreeNode, data, contentType))
+ .build();
+
+ return odr;
+ }
+
+ @Override
+ public ODataResponse existsEntity(final GetEntityCountUriInfo uriInfo, final String contentType)
+ throws ODataException {
+ final Object data = retrieveData(
+ uriInfo.getStartEntitySet(),
+ uriInfo.getKeyPredicates(),
+ uriInfo.getFunctionImport(),
+ mapFunctionParameters(uriInfo.getFunctionImportParameters()),
+ uriInfo.getNavigationSegments());
+
+ return ODataResponse.fromResponse(EntityProvider.writeText(appliesFilter(data, uriInfo.getFilter()) ? "1" : "0"))
+ .build();
+ }
+
+ @Override
+ public ODataResponse deleteEntity(final DeleteUriInfo uriInfo, final String contentType) throws ODataException {
+ dataSource.deleteData(
+ uriInfo.getStartEntitySet(),
+ mapKey(uriInfo.getKeyPredicates()));
+ return ODataResponse.newBuilder().build();
+ }
+
+ @Override
+ public ODataResponse createEntity(final PostUriInfo uriInfo, final InputStream content,
+ final String requestContentType, final String contentType) throws ODataException {
+ final EdmEntitySet entitySet = uriInfo.getTargetEntitySet();
+ final EdmEntityType entityType = entitySet.getEntityType();
+
+ Object data = dataSource.newDataObject(entitySet);
+ ExpandSelectTreeNode expandSelectTree = null;
+
+ if (entityType.hasStream()) {
+ dataSource.createData(entitySet, data);
+ dataSource.writeBinaryData(entitySet, data,
+ new BinaryData(EntityProvider.readBinary(content), requestContentType));
+
+ } else {
+ final EntityProviderReadProperties properties = EntityProviderReadProperties.init()
+ .mergeSemantic(false)
+ .addTypeMappings(getStructuralTypeTypeMap(data, entityType))
+ .build();
+ final ODataEntry entryValues = parseEntry(entitySet, content, requestContentType, properties);
+
+ setStructuralTypeValuesFromMap(data, entityType, entryValues.getProperties(), false);
+
+ dataSource.createData(entitySet, data);
+
+ createInlinedEntities(entitySet, data, entryValues);
+
+ expandSelectTree = entryValues.getExpandSelectTree();
+ }
+
+ // Link back to the entity the target entity set is related to, if any.
+ final List<NavigationSegment> navigationSegments = uriInfo.getNavigationSegments();
+ if (!navigationSegments.isEmpty()) {
+ final List<NavigationSegment> previousSegments = navigationSegments.subList(0, navigationSegments.size() - 1);
+ final Object sourceData = retrieveData(
+ uriInfo.getStartEntitySet(),
+ uriInfo.getKeyPredicates(),
+ uriInfo.getFunctionImport(),
+ mapFunctionParameters(uriInfo.getFunctionImportParameters()),
+ previousSegments);
+ final EdmEntitySet previousEntitySet = previousSegments.isEmpty() ?
+ uriInfo.getStartEntitySet() : previousSegments.get(previousSegments.size() - 1).getEntitySet();
+ dataSource.writeRelation(previousEntitySet, sourceData, entitySet, getStructuralTypeValueMap(data, entityType));
+ }
+
+ return ODataResponse.fromResponse(writeEntry(uriInfo.getTargetEntitySet(), expandSelectTree, data, contentType))
+ .eTag(constructETag(entitySet, data)).build();
+ }
+
+ @Override
+ public ODataResponse updateEntity(final PutMergePatchUriInfo uriInfo, final InputStream content,
+ final String requestContentType, final boolean merge, final String contentType) throws ODataException {
+ Object data = retrieveData(
+ uriInfo.getStartEntitySet(),
+ uriInfo.getKeyPredicates(),
+ uriInfo.getFunctionImport(),
+ mapFunctionParameters(uriInfo.getFunctionImportParameters()),
+ uriInfo.getNavigationSegments());
+
+ if (!appliesFilter(data, uriInfo.getFilter())) {
+ throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
+ }
+
+ final EdmEntitySet entitySet = uriInfo.getTargetEntitySet();
+ final EdmEntityType entityType = entitySet.getEntityType();
+ final EntityProviderReadProperties properties = EntityProviderReadProperties.init()
+ .mergeSemantic(merge)
+ .addTypeMappings(getStructuralTypeTypeMap(data, entityType))
+ .build();
+ final ODataEntry entryValues = parseEntry(entitySet, content, requestContentType, properties);
+
+ setStructuralTypeValuesFromMap(data, entityType, entryValues.getProperties(), merge);
+
+ return ODataResponse.newBuilder().eTag(constructETag(entitySet, data)).build();
+ }
+
+ @Override
+ public ODataResponse readEntityLink(final GetEntityLinkUriInfo uriInfo, final String contentType)
+ throws ODataException {
+ final Object data = retrieveData(
+ uriInfo.getStartEntitySet(),
+ uriInfo.getKeyPredicates(),
+ uriInfo.getFunctionImport(),
+ mapFunctionParameters(uriInfo.getFunctionImportParameters()),
+ uriInfo.getNavigationSegments());
+
+ // if (!appliesFilter(data, uriInfo.getFilter()))
+ if (data == null) {
+ throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
+ }
+
+ final EdmEntitySet entitySet = uriInfo.getTargetEntitySet();
+
+ Map<String, Object> values = new HashMap<String, Object>();
+ for (final EdmProperty property : entitySet.getEntityType().getKeyProperties()) {
+ values.put(property.getName(), valueAccess.getPropertyValue(data, property));
+ }
+
+ ODataContext context = getContext();
+ final EntityProviderWriteProperties entryProperties = EntityProviderWriteProperties
+ .serviceRoot(context.getPathInfo().getServiceRoot())
+ .build();
+
+ final int timingHandle = context.startRuntimeMeasurement("EntityProvider", "writeLink");
+
+ final ODataResponse response = EntityProvider.writeLink(contentType, entitySet, values, entryProperties);
+
+ context.stopRuntimeMeasurement(timingHandle);
+
+ return ODataResponse.fromResponse(response).build();
+ }
+
+ @Override
+ public ODataResponse existsEntityLink(final GetEntityLinkCountUriInfo uriInfo, final String contentType)
+ throws ODataException {
+ return existsEntity((GetEntityCountUriInfo) uriInfo, contentType);
+ }
+
+ @Override
+ public ODataResponse deleteEntityLink(final DeleteUriInfo uriInfo, final String contentType) throws ODataException {
+ final List<NavigationSegment> navigationSegments = uriInfo.getNavigationSegments();
+ final List<NavigationSegment> previousSegments = navigationSegments.subList(0, navigationSegments.size() - 1);
+
+ final Object sourceData = retrieveData(
+ uriInfo.getStartEntitySet(),
+ uriInfo.getKeyPredicates(),
+ uriInfo.getFunctionImport(),
+ mapFunctionParameters(uriInfo.getFunctionImportParameters()),
+ previousSegments);
+
+ final EdmEntitySet entitySet = previousSegments.isEmpty() ?
+ uriInfo.getStartEntitySet() : previousSegments.get(previousSegments.size() - 1).getEntitySet();
+ final EdmEntitySet targetEntitySet = uriInfo.getTargetEntitySet();
+ final Map<String, Object> keys = mapKey(uriInfo.getTargetKeyPredicates());
+
+ final Object targetData = dataSource.readRelatedData(entitySet, sourceData, targetEntitySet, keys);
+
+ // if (!appliesFilter(targetData, uriInfo.getFilter()))
+ if (targetData == null) {
+ throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
+ }
+
+ dataSource.deleteRelation(entitySet, sourceData, targetEntitySet, keys);
+
+ return ODataResponse.newBuilder().build();
+ }
+
+ @Override
+ public ODataResponse createEntityLink(final PostUriInfo uriInfo, final InputStream content,
+ final String requestContentType, final String contentType) throws ODataException {
+ final List<NavigationSegment> navigationSegments = uriInfo.getNavigationSegments();
+ final List<NavigationSegment> previousSegments = navigationSegments.subList(0, navigationSegments.size() - 1);
+
+ final Object sourceData = retrieveData(
+ uriInfo.getStartEntitySet(),
+ uriInfo.getKeyPredicates(),
+ uriInfo.getFunctionImport(),
+ mapFunctionParameters(uriInfo.getFunctionImportParameters()),
+ previousSegments);
+
+ final EdmEntitySet entitySet = previousSegments.isEmpty() ?
+ uriInfo.getStartEntitySet() : previousSegments.get(previousSegments.size() - 1).getEntitySet();
+ final EdmEntitySet targetEntitySet = uriInfo.getTargetEntitySet();
+
+ final Map<String, Object> targetKeys = parseLink(targetEntitySet, content, requestContentType);
+
+ dataSource.writeRelation(entitySet, sourceData, targetEntitySet, targetKeys);
+
+ return ODataResponse.newBuilder().build();
+ }
+
+ @Override
+ public ODataResponse updateEntityLink(final PutMergePatchUriInfo uriInfo, final InputStream content,
+ final String requestContentType, final String contentType) throws ODataException {
+ final List<NavigationSegment> navigationSegments = uriInfo.getNavigationSegments();
+ final List<NavigationSegment> previousSegments = navigationSegments.subList(0, navigationSegments.size() - 1);
+
+ final Object sourceData = retrieveData(
+ uriInfo.getStartEntitySet(),
+ uriInfo.getKeyPredicates(),
+ uriInfo.getFunctionImport(),
+ mapFunctionParameters(uriInfo.getFunctionImportParameters()),
+ previousSegments);
+
+ final EdmEntitySet entitySet = previousSegments.isEmpty() ?
+ uriInfo.getStartEntitySet() : previousSegments.get(previousSegments.size() - 1).getEntitySet();
+ final EdmEntitySet targetEntitySet = uriInfo.getTargetEntitySet();
+ final Map<String, Object> keys = mapKey(uriInfo.getTargetKeyPredicates());
+
+ final Object targetData = dataSource.readRelatedData(entitySet, sourceData, targetEntitySet, keys);
+
+ if (!appliesFilter(targetData, uriInfo.getFilter())) {
+ throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
+ }
+
+ dataSource.deleteRelation(entitySet, sourceData, targetEntitySet, keys);
+
+ final Map<String, Object> newKeys = parseLink(targetEntitySet, content, requestContentType);
+
+ dataSource.writeRelation(entitySet, sourceData, targetEntitySet, newKeys);
+
+ return ODataResponse.newBuilder().build();
+ }
+
+ @Override
+ public ODataResponse readEntityComplexProperty(final GetComplexPropertyUriInfo uriInfo, final String contentType)
+ throws ODataException {
+ Object data = retrieveData(
+ uriInfo.getStartEntitySet(),
+ uriInfo.getKeyPredicates(),
+ uriInfo.getFunctionImport(),
+ mapFunctionParameters(uriInfo.getFunctionImportParameters()),
+ uriInfo.getNavigationSegments());
+
+ // if (!appliesFilter(data, uriInfo.getFilter()))
+ if (data == null) {
+ throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
+ }
+
+ final List<EdmProperty> propertyPath = uriInfo.getPropertyPath();
+ final EdmProperty property = propertyPath.get(propertyPath.size() - 1);
+ final Object value = property.isSimple() ?
+ property.getMapping() == null || property.getMapping().getMimeType() == null ?
+ getPropertyValue(data, propertyPath) : getSimpleTypeValueMap(data, propertyPath) :
+ getStructuralTypeValueMap(getPropertyValue(data, propertyPath), (EdmStructuralType) property.getType());
+
+ ODataContext context = getContext();
+ final int timingHandle = context.startRuntimeMeasurement("EntityProvider", "writeProperty");
+
+ final ODataResponse response = EntityProvider.writeProperty(contentType, property, value);
+
+ context.stopRuntimeMeasurement(timingHandle);
+
+ return ODataResponse.fromResponse(response).eTag(constructETag(uriInfo.getTargetEntitySet(), data)).build();
+ }
+
+ @Override
+ public ODataResponse readEntitySimpleProperty(final GetSimplePropertyUriInfo uriInfo, final String contentType)
+ throws ODataException {
+ return readEntityComplexProperty((GetComplexPropertyUriInfo) uriInfo, contentType);
+ }
+
+ @Override
+ public ODataResponse readEntitySimplePropertyValue(final GetSimplePropertyUriInfo uriInfo, final String contentType)
+ throws ODataException {
+ Object data = retrieveData(
+ uriInfo.getStartEntitySet(),
+ uriInfo.getKeyPredicates(),
+ uriInfo.getFunctionImport(),
+ mapFunctionParameters(uriInfo.getFunctionImportParameters()),
+ uriInfo.getNavigationSegments());
+
+ // if (!appliesFilter(data, uriInfo.getFilter()))
+ if (data == null) {
+ throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
+ }
+
+ final List<EdmProperty> propertyPath = uriInfo.getPropertyPath();
+ final EdmProperty property = propertyPath.get(propertyPath.size() - 1);
+ final Object value = property.getMapping() == null || property.getMapping().getMimeType() == null ?
+ getPropertyValue(data, propertyPath) : getSimpleTypeValueMap(data, propertyPath);
+
+ return ODataResponse.fromResponse(EntityProvider.writePropertyValue(property, value)).eTag(
+ constructETag(uriInfo.getTargetEntitySet(), data)).build();
+ }
+
+ @Override
+ public ODataResponse deleteEntitySimplePropertyValue(final DeleteUriInfo uriInfo, final String contentType)
+ throws ODataException {
+ Object data = retrieveData(
+ uriInfo.getStartEntitySet(),
+ uriInfo.getKeyPredicates(),
+ uriInfo.getFunctionImport(),
+ mapFunctionParameters(uriInfo.getFunctionImportParameters()),
+ uriInfo.getNavigationSegments());
+
+ if (data == null) {
+ throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
+ }
+
+ final List<EdmProperty> propertyPath = uriInfo.getPropertyPath();
+ final EdmProperty property = propertyPath.get(propertyPath.size() - 1);
+
+ data = getPropertyValue(data, propertyPath.subList(0, propertyPath.size() - 1));
+ valueAccess.setPropertyValue(data, property, null);
+ valueAccess.setMappingValue(data, property.getMapping(), null);
+
+ return ODataResponse.newBuilder().build();
+ }
+
+ @Override
+ public ODataResponse updateEntityComplexProperty(final PutMergePatchUriInfo uriInfo, final InputStream content,
+ final String requestContentType, final boolean merge, final String contentType) throws ODataException {
+ Object data = retrieveData(
+ uriInfo.getStartEntitySet(),
+ uriInfo.getKeyPredicates(),
+ uriInfo.getFunctionImport(),
+ mapFunctionParameters(uriInfo.getFunctionImportParameters()),
+ uriInfo.getNavigationSegments());
+
+ if (!appliesFilter(data, uriInfo.getFilter())) {
+ throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
+ }
+
+ final List<EdmProperty> propertyPath = uriInfo.getPropertyPath();
+ final EdmProperty property = propertyPath.get(propertyPath.size() - 1);
+
+ data = getPropertyValue(data, propertyPath.subList(0, propertyPath.size() - 1));
+
+ ODataContext context = getContext();
+ int timingHandle = context.startRuntimeMeasurement("EntityConsumer", "readProperty");
+
+ Map<String, Object> values;
+ try {
+ values =
+ EntityProvider.readProperty(requestContentType, property, content, EntityProviderReadProperties.init()
+ .mergeSemantic(merge).build());
+ } catch (final EntityProviderException e) {
+ throw new ODataBadRequestException(ODataBadRequestException.BODY, e);
+ }
+
+ context.stopRuntimeMeasurement(timingHandle);
+
+ final Object value = values.get(property.getName());
+ if (property.isSimple()) {
+ valueAccess.setPropertyValue(data, property, value);
+ } else {
+ @SuppressWarnings("unchecked")
+ final Map<String, Object> propertyValue = (Map<String, Object>) value;
+ setStructuralTypeValuesFromMap(valueAccess.getPropertyValue(data, property),
+ (EdmStructuralType) property.getType(), propertyValue, merge);
+ }
+
+ return ODataResponse.newBuilder().eTag(constructETag(uriInfo.getTargetEntitySet(), data)).build();
+ }
+
+ @Override
+ public ODataResponse updateEntitySimpleProperty(final PutMergePatchUriInfo uriInfo, final InputStream content,
+ final String requestContentType, final String contentType) throws ODataException {
+ return updateEntityComplexProperty(uriInfo, content, requestContentType, false, contentType);
+ }
+
+ @Override
+ public ODataResponse updateEntitySimplePropertyValue(final PutMergePatchUriInfo uriInfo, final InputStream content,
+ final String requestContentType, final String contentType) throws ODataException {
+ Object data = retrieveData(
+ uriInfo.getStartEntitySet(),
+ uriInfo.getKeyPredicates(),
+ uriInfo.getFunctionImport(),
+ mapFunctionParameters(uriInfo.getFunctionImportParameters()),
+ uriInfo.getNavigationSegments());
+
+ if (!appliesFilter(data, uriInfo.getFilter())) {
+ throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
+ }
+
+ final List<EdmProperty> propertyPath = uriInfo.getPropertyPath();
+ final EdmProperty property = propertyPath.get(propertyPath.size() - 1);
+
+ data = getPropertyValue(data, propertyPath.subList(0, propertyPath.size() - 1));
+
+ ODataContext context = getContext();
+ int timingHandle = context.startRuntimeMeasurement("EntityConsumer", "readPropertyValue");
+
+ Object value;
+ try {
+ value = EntityProvider.readPropertyValue(property, content);
+ } catch (final EntityProviderException e) {
+ throw new ODataBadRequestException(ODataBadRequestException.BODY, e);
+ }
+
+ context.stopRuntimeMeasurement(timingHandle);
+
+ valueAccess.setPropertyValue(data, property, value);
+ valueAccess.setMappingValue(data, property.getMapping(), requestContentType);
+
+ return ODataResponse.newBuilder().eTag(constructETag(uriInfo.getTargetEntitySet(), data)).build();
+ }
+
+ @Override
+ public ODataResponse readEntityMedia(final GetMediaResourceUriInfo uriInfo, final String contentType)
+ throws ODataException {
+ final Object data = retrieveData(
+ uriInfo.getStartEntitySet(),
+ uriInfo.getKeyPredicates(),
+ uriInfo.getFunctionImport(),
+ mapFunctionParameters(uriInfo.getFunctionImportParameters()),
+ uriInfo.getNavigationSegments());
+
+ if (!appliesFilter(data, uriInfo.getFilter())) {
+ throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
+ }
+
+ final EdmEntitySet entitySet = uriInfo.getTargetEntitySet();
+ final BinaryData binaryData = dataSource.readBinaryData(entitySet, data);
+ if (binaryData == null) {
+ throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
+ }
+
+ final String mimeType = binaryData.getMimeType() == null ?
+ HttpContentType.APPLICATION_OCTET_STREAM : binaryData.getMimeType();
+
+ return ODataResponse.fromResponse(EntityProvider.writeBinary(mimeType, binaryData.getData())).eTag(
+ constructETag(entitySet, data)).build();
+ }
+
+ @Override
+ public ODataResponse deleteEntityMedia(final DeleteUriInfo uriInfo, final String contentType) throws ODataException {
+ final Object data = retrieveData(
+ uriInfo.getStartEntitySet(),
+ uriInfo.getKeyPredicates(),
+ uriInfo.getFunctionImport(),
+ mapFunctionParameters(uriInfo.getFunctionImportParameters()),
+ uriInfo.getNavigationSegments());
+
+ if (data == null) {
+ throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
+ }
+
+ dataSource.writeBinaryData(uriInfo.getTargetEntitySet(), data, new BinaryData(null, null));
+
+ return ODataResponse.newBuilder().build();
+ }
+
+ @Override
+ public ODataResponse updateEntityMedia(final PutMergePatchUriInfo uriInfo, final InputStream content,
+ final String requestContentType, final String contentType) throws ODataException {
+ final Object data = retrieveData(
+ uriInfo.getStartEntitySet(),
+ uriInfo.getKeyPredicates(),
+ uriInfo.getFunctionImport(),
+ mapFunctionParameters(uriInfo.getFunctionImportParameters()),
+ uriInfo.getNavigationSegments());
+
+ if (!appliesFilter(data, uriInfo.getFilter())) {
+ throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
+ }
+
+ ODataContext context = getContext();
+ final int timingHandle = context.startRuntimeMeasurement("EntityProvider", "readBinary");
+
+ final byte[] value = EntityProvider.readBinary(content);
+
+ context.stopRuntimeMeasurement(timingHandle);
+
+ final EdmEntitySet entitySet = uriInfo.getTargetEntitySet();
+ dataSource.writeBinaryData(entitySet, data, new BinaryData(value, requestContentType));
+
+ return ODataResponse.newBuilder().eTag(constructETag(entitySet, data)).build();
+ }
+
+ @Override
+ public ODataResponse executeFunctionImport(final GetFunctionImportUriInfo uriInfo, final String contentType)
+ throws ODataException {
+ final EdmFunctionImport functionImport = uriInfo.getFunctionImport();
+ final EdmType type = functionImport.getReturnType().getType();
+
+ final Object data = dataSource.readData(
+ functionImport,
+ mapFunctionParameters(uriInfo.getFunctionImportParameters()),
+ null);
+
+ if (data == null) {
+ throw new ODataNotFoundException(ODataHttpException.COMMON);
+ }
+
+ Object value;
+ if (type.getKind() == EdmTypeKind.SIMPLE) {
+ value = type == EdmSimpleTypeKind.Binary.getEdmSimpleTypeInstance() ?
+ ((BinaryData) data).getData() : data;
+ } else if (functionImport.getReturnType().getMultiplicity() == EdmMultiplicity.MANY) {
+ List<Map<String, Object>> values = new ArrayList<Map<String, Object>>();
+ for (final Object typeData : (List<?>) data) {
+ values.add(getStructuralTypeValueMap(typeData, (EdmStructuralType) type));
+ }
+ value = values;
+ } else {
+ value = getStructuralTypeValueMap(data, (EdmStructuralType) type);
+ }
+
+ ODataContext context = getContext();
+
+ final EntityProviderWriteProperties entryProperties = EntityProviderWriteProperties
+ .serviceRoot(context.getPathInfo().getServiceRoot()).build();
+
+ final int timingHandle = context.startRuntimeMeasurement("EntityProvider", "writeFunctionImport");
+
+ final ODataResponse response =
+ EntityProvider.writeFunctionImport(contentType, functionImport, value, entryProperties);
+
+ context.stopRuntimeMeasurement(timingHandle);
+
+ return ODataResponse.fromResponse(response).build();
+ }
+
+ @Override
+ public ODataResponse executeFunctionImportValue(final GetFunctionImportUriInfo uriInfo, final String contentType)
+ throws ODataException {
+ final EdmFunctionImport functionImport = uriInfo.getFunctionImport();
+ final EdmSimpleType type = (EdmSimpleType) functionImport.getReturnType().getType();
+
+ final Object data = dataSource.readData(
+ functionImport,
+ mapFunctionParameters(uriInfo.getFunctionImportParameters()),
+ null);
+
+ if (data == null) {
+ throw new ODataNotFoundException(ODataHttpException.COMMON);
+ }
+
+ ODataResponse response;
+ if (type == EdmSimpleTypeKind.Binary.getEdmSimpleTypeInstance()) {
+ response = EntityProvider.writeBinary(((BinaryData) data).getMimeType(), ((BinaryData) data).getData());
+ } else {
+ final String value = type.valueToString(data, EdmLiteralKind.DEFAULT, null);
+ response = EntityProvider.writeText(value == null ? "" : value);
+ }
+ return ODataResponse.fromResponse(response).build();
+ }
+
+ private static Map<String, Object> mapKey(final List<KeyPredicate> keys) throws EdmException {
+ Map<String, Object> keyMap = new HashMap<String, Object>();
+ for (final KeyPredicate key : keys) {
+ final EdmProperty property = key.getProperty();
+ final EdmSimpleType type = (EdmSimpleType) property.getType();
+ keyMap.put(property.getName(), type.valueOfString(key.getLiteral(), EdmLiteralKind.DEFAULT, property.getFacets(),
+ type.getDefaultType()));
+ }
+ return keyMap;
+ }
+
+ private static Map<String, Object> mapFunctionParameters(final Map<String, EdmLiteral> functionImportParameters)
+ throws EdmSimpleTypeException {
+ if (functionImportParameters == null) {
+ return Collections.emptyMap();
+ } else {
+ Map<String, Object> parameterMap = new HashMap<String, Object>();
+ for (final String parameterName : functionImportParameters.keySet()) {
+ final EdmLiteral literal = functionImportParameters.get(parameterName);
+ final EdmSimpleType type = literal.getType();
+ parameterMap.put(parameterName, type.valueOfString(literal.getLiteral(), EdmLiteralKind.DEFAULT, null, type
+ .getDefaultType()));
+ }
+ return parameterMap;
+ }
+ }
+
+ private Object retrieveData(final EdmEntitySet startEntitySet, final List<KeyPredicate> keyPredicates,
+ final EdmFunctionImport functionImport, final Map<String, Object> functionImportParameters,
+ final List<NavigationSegment> navigationSegments) throws ODataException {
+ Object data;
+ final Map<String, Object> keys = mapKey(keyPredicates);
+
+ ODataContext context = getContext();
+ final int timingHandle = context.startRuntimeMeasurement(getClass().getSimpleName(), "retrieveData");
+
+ data = functionImport == null ?
+ keys.isEmpty() ?
+ dataSource.readData(startEntitySet) : dataSource.readData(startEntitySet, keys) :
+ dataSource.readData(functionImport, functionImportParameters, keys);
+
+ EdmEntitySet currentEntitySet =
+ functionImport == null ? startEntitySet : functionImport.getEntitySet();
+ for (NavigationSegment navigationSegment : navigationSegments) {
+ data = dataSource.readRelatedData(
+ currentEntitySet,
+ data,
+ navigationSegment.getEntitySet(),
+ mapKey(navigationSegment.getKeyPredicates()));
+ currentEntitySet = navigationSegment.getEntitySet();
+ }
+
+ context.stopRuntimeMeasurement(timingHandle);
+
+ return data;
+ }
+
+ private <T> String constructETag(final EdmEntitySet entitySet, final T data) throws ODataException {
+ final EdmEntityType entityType = entitySet.getEntityType();
+ String eTag = null;
+ for (final String propertyName : entityType.getPropertyNames()) {
+ final EdmProperty property = (EdmProperty) entityType.getProperty(propertyName);
+ if (property.getFacets() != null && property.getFacets().getConcurrencyMode() == EdmConcurrencyMode.Fixed) {
+ final EdmSimpleType type = (EdmSimpleType) property.getType();
+ final String component = type.valueToString(valueAccess.getPropertyValue(data, property),
+ EdmLiteralKind.DEFAULT, property.getFacets());
+ eTag = eTag == null ? component : eTag + Edm.DELIMITER + component;
+ }
+ }
+ return eTag == null ? null : "W/\"" + eTag + "\"";
+ }
+
+ private <T> Map<String, ODataCallback> getCallbacks(final T data, final EdmEntityType entityType)
+ throws EdmException {
+ final List<String> navigationPropertyNames = entityType.getNavigationPropertyNames();
+ if (navigationPropertyNames.isEmpty()) {
+ return null;
+ } else {
+ final WriteCallback callback = new WriteCallback(data);
+ Map<String, ODataCallback> callbacks = new HashMap<String, ODataCallback>();
+ for (final String name : navigationPropertyNames) {
+ callbacks.put(name, callback);
+ }
+ return callbacks;
+ }
+ }
+
+ private class WriteCallback implements OnWriteEntryContent, OnWriteFeedContent {
+ private final Object data;
+
+ private <T> WriteCallback(final T data) {
+ this.data = data;
+ }
+
+ @Override
+ public WriteFeedCallbackResult retrieveFeedResult(final WriteFeedCallbackContext context)
+ throws ODataApplicationException {
+ try {
+ final EdmEntityType entityType =
+ context.getSourceEntitySet().getRelatedEntitySet(context.getNavigationProperty()).getEntityType();
+ List<Map<String, Object>> values = new ArrayList<Map<String, Object>>();
+ Object relatedData = null;
+ try {
+ relatedData = readRelatedData(context);
+ for (final Object entryData : (List<?>) relatedData) {
+ values.add(getStructuralTypeValueMap(entryData, entityType));
+ }
+ } catch (final ODataNotFoundException e) {
+ values.clear();
+ }
+ WriteFeedCallbackResult result = new WriteFeedCallbackResult();
+ result.setFeedData(values);
+ EntityProviderWriteProperties inlineProperties =
+ EntityProviderWriteProperties.serviceRoot(getContext().getPathInfo().getServiceRoot()).callbacks(
+ getCallbacks(relatedData, entityType)).expandSelectTree(context.getCurrentExpandSelectTreeNode())
+ .selfLink(context.getSelfLink()).build();
+ result.setInlineProperties(inlineProperties);
+ return result;
+ } catch (final ODataException e) {
+ throw new ODataApplicationException(e.getLocalizedMessage(), Locale.ROOT, e);
+ }
+ }
+
+ @Override
+ public WriteEntryCallbackResult retrieveEntryResult(final WriteEntryCallbackContext context)
+ throws ODataApplicationException {
+ try {
+ final EdmEntityType entityType =
+ context.getSourceEntitySet().getRelatedEntitySet(context.getNavigationProperty()).getEntityType();
+ WriteEntryCallbackResult result = new WriteEntryCallbackResult();
+ Object relatedData;
+ try {
+ relatedData = readRelatedData(context);
+ } catch (final ODataNotFoundException e) {
+ relatedData = null;
+ }
+ result.setEntryData(getStructuralTypeValueMap(relatedData, entityType));
+
+ EntityProviderWriteProperties inlineProperties =
+ EntityProviderWriteProperties.serviceRoot(getContext().getPathInfo().getServiceRoot()).callbacks(
+ getCallbacks(relatedData, entityType)).expandSelectTree(context.getCurrentExpandSelectTreeNode())
+ .build();
+ result.setInlineProperties(inlineProperties);
+ return result;
+ } catch (final ODataException e) {
+ throw new ODataApplicationException(e.getLocalizedMessage(), Locale.ROOT, e);
+ }
+ }
+
+ private Object readRelatedData(final WriteCallbackContext context) throws ODataException {
+ final EdmEntitySet entitySet = context.getSourceEntitySet();
+ return dataSource.readRelatedData(
+ entitySet,
+ data instanceof List ? readEntryData((List<?>) data, entitySet.getEntityType(), context
+ .extractKeyFromEntryData()) : data,
+ entitySet.getRelatedEntitySet(context.getNavigationProperty()),
+ Collections.<String, Object> emptyMap());
+ }
+
+ private <T> T readEntryData(final List<T> data, final EdmEntityType entityType, final Map<String, Object> key)
+ throws ODataException {
+ for (final T entryData : data) {
+ boolean found = true;
+ for (final EdmProperty keyProperty : entityType.getKeyProperties()) {
+ if (!valueAccess.getPropertyValue(entryData, keyProperty).equals(key.get(keyProperty.getName()))) {
+ found = false;
+ break;
+ }
+ }
+ if (found) {
+ return entryData;
+ }
+ }
+ return null;
+ }
+ }
+
+ private <T> ODataResponse writeEntry(final EdmEntitySet entitySet, final ExpandSelectTreeNode expandSelectTree,
+ final T data, final String contentType) throws ODataException, EntityProviderException {
+ final EdmEntityType entityType = entitySet.getEntityType();
+ final Map<String, Object> values = getStructuralTypeValueMap(data, entityType);
+
+ ODataContext context = getContext();
+ EntityProviderWriteProperties writeProperties = EntityProviderWriteProperties
+ .serviceRoot(context.getPathInfo().getServiceRoot())
+ .expandSelectTree(expandSelectTree)
+ .callbacks(getCallbacks(data, entityType))
+ .build();
+
+ final int timingHandle = context.startRuntimeMeasurement("EntityProvider", "writeEntry");
+
+ final ODataResponse response = EntityProvider.writeEntry(contentType, entitySet, values, writeProperties);
+
+ context.stopRuntimeMeasurement(timingHandle);
+
+ return response;
+ }
+
+ private ODataEntry parseEntry(final EdmEntitySet entitySet, final InputStream content,
+ final String requestContentType, final EntityProviderReadProperties properties) throws ODataBadRequestException {
+ ODataContext context = getContext();
+ final int timingHandle = context.startRuntimeMeasurement("EntityConsumer", "readEntry");
+
+ ODataEntry entryValues;
+ try {
+ entryValues = EntityProvider.readEntry(requestContentType, entitySet, content, properties);
+ } catch (final EntityProviderException e) {
+ throw new ODataBadRequestException(ODataBadRequestException.BODY, e);
+ }
+
+ context.stopRuntimeMeasurement(timingHandle);
+
+ return entryValues;
+ }
+
+ private Map<String, Object> parseLink(final EdmEntitySet entitySet, final InputStream content,
+ final String contentType) throws ODataException {
+ ODataContext context = getContext();
+ final int timingHandle = context.startRuntimeMeasurement("EntityProvider", "readLink");
+
+ final String uriString = EntityProvider.readLink(contentType, entitySet, content);
+
+ context.stopRuntimeMeasurement(timingHandle);
+
+ final Map<String, Object> targetKeys = parseLinkUri(entitySet, uriString);
+ if (targetKeys == null) {
+ throw new ODataBadRequestException(ODataBadRequestException.BODY);
+ }
+ return targetKeys;
+ }
+
+ private Map<String, Object> parseLinkUri(final EdmEntitySet targetEntitySet, final String uriString)
+ throws EdmException {
+ ODataContext context = getContext();
+ final int timingHandle = context.startRuntimeMeasurement("UriParser", "getKeyPredicatesFromEntityLink");
+
+ List<KeyPredicate> key = null;
+ try {
+ key = UriParser.getKeyPredicatesFromEntityLink(targetEntitySet, uriString,
+ context.getPathInfo().getServiceRoot());
+ } catch (ODataException e) {
+ // We don't understand the link target. This could also be seen as an error.
+ }
+
+ context.stopRuntimeMeasurement(timingHandle);
+
+ return key == null ? null : mapKey(key);
+ }
+
+ private <T> void createInlinedEntities(final EdmEntitySet entitySet, final T data, final ODataEntry entryValues)
+ throws ODataException {
+ final EdmEntityType entityType = entitySet.getEntityType();
+ for (final String navigationPropertyName : entityType.getNavigationPropertyNames()) {
+
+ final EdmNavigationProperty navigationProperty =
+ (EdmNavigationProperty) entityType.getProperty(navigationPropertyName);
+ final EdmEntitySet relatedEntitySet = entitySet.getRelatedEntitySet(navigationProperty);
+ final EdmEntityType relatedEntityType = relatedEntitySet.getEntityType();
+
+ final Object relatedValue = entryValues.getProperties().get(navigationPropertyName);
+ if (relatedValue == null) {
+ for (final String uriString : entryValues.getMetadata().getAssociationUris(navigationPropertyName)) {
+ final Map<String, Object> key = parseLinkUri(relatedEntitySet, uriString);
+ if (key != null) {
+ dataSource.writeRelation(entitySet, data, relatedEntitySet, key);
+ }
+ }
+
+ } else {
+ if (relatedValue instanceof ODataFeed) {
+ ODataFeed feed = (ODataFeed) relatedValue;
+ final List<ODataEntry> relatedValueList = feed.getEntries();
+ for (final ODataEntry relatedValues : relatedValueList) {
+ Object relatedData = dataSource.newDataObject(relatedEntitySet);
+ setStructuralTypeValuesFromMap(relatedData, relatedEntityType, relatedValues.getProperties(), false);
+ dataSource.createData(relatedEntitySet, relatedData);
+ dataSource.writeRelation(entitySet, data, relatedEntitySet, getStructuralTypeValueMap(relatedData,
+ relatedEntityType));
+ createInlinedEntities(relatedEntitySet, relatedData, relatedValues);
+ }
+ } else if (relatedValue instanceof ODataEntry) {
+ final ODataEntry relatedValueEntry = (ODataEntry) relatedValue;
+ Object relatedData = dataSource.newDataObject(relatedEntitySet);
+ setStructuralTypeValuesFromMap(relatedData, relatedEntityType, relatedValueEntry.getProperties(), false);
+ dataSource.createData(relatedEntitySet, relatedData);
+ dataSource.writeRelation(entitySet, data, relatedEntitySet, getStructuralTypeValueMap(relatedData,
+ relatedEntityType));
+ createInlinedEntities(relatedEntitySet, relatedData, relatedValueEntry);
+ } else {
+ throw new ODataException("Unexpected class for a related value: " + relatedValue.getClass().getSimpleName());
+ }
+
+ }
+ }
+ }
+
+ private <T> Integer applySystemQueryOptions(final EdmEntitySet entitySet, final List<T> data,
+ final FilterExpression filter, final InlineCount inlineCount, final OrderByExpression orderBy,
+ final String skipToken, final Integer skip, final Integer top) throws ODataException {
+ ODataContext context = getContext();
+ final int timingHandle = context.startRuntimeMeasurement(getClass().getSimpleName(), "applySystemQueryOptions");
+
+ if (filter != null) {
+ // Remove all elements the filter does not apply for.
+ // A for-each loop would not work with "remove", see Java documentation.
+ for (Iterator<T> iterator = data.iterator(); iterator.hasNext();) {
+ if (!appliesFilter(iterator.next(), filter)) {
+ iterator.remove();
+ }
+ }
+ }
+
+ final Integer count = inlineCount == InlineCount.ALLPAGES ? data.size() : null;
+
+ if (orderBy != null) {
+ sort(data, orderBy);
+ } else if (skipToken != null || skip != null || top != null) {
+ sortInDefaultOrder(entitySet, data);
+ }
+
+ if (skipToken != null) {
+ while (!data.isEmpty() && !getSkipToken(entitySet, data.get(0)).equals(skipToken)) {
+ data.remove(0);
+ }
+ }
+
+ if (skip != null) {
+ if (skip >= data.size()) {
+ data.clear();
+ } else {
+ for (int i = 0; i < skip; i++) {
+ data.remove(0);
+ }
+ }
+ }
+
+ if (top != null) {
+ while (data.size() > top) {
+ data.remove(top.intValue());
+ }
+ }
+
+ context.stopRuntimeMeasurement(timingHandle);
+
+ return count;
+ }
+
+ private <T> void sort(final List<T> data, final OrderByExpression orderBy) {
+ Collections.sort(data, new Comparator<T>() {
+ @Override
+ public int compare(final T entity1, final T entity2) {
+ try {
+ int result = 0;
+ for (final OrderExpression expression : orderBy.getOrders()) {
+ result = evaluateExpression(entity1, expression.getExpression()).compareTo(
+ evaluateExpression(entity2, expression.getExpression()));
+ if (expression.getSortOrder() == SortOrder.desc) {
+ result = -result;
+ }
+ if (result != 0) {
+ break;
+ }
+ }
+ return result;
+ } catch (final ODataException e) {
+ return 0;
+ }
+ }
+ });
+ }
+
+ private <T> void sortInDefaultOrder(final EdmEntitySet entitySet, final List<T> data) {
+ Collections.sort(data, new Comparator<T>() {
+ @Override
+ public int compare(final T entity1, final T entity2) {
+ try {
+ return getSkipToken(entitySet, entity1).compareTo(getSkipToken(entitySet, entity2));
+ } catch (final ODataException e) {
+ return 0;
+ }
+ }
+ });
+ }
+
+ private <T> boolean appliesFilter(final T data, final FilterExpression filter) throws ODataException {
+ ODataContext context = getContext();
+ final int timingHandle = context.startRuntimeMeasurement(getClass().getSimpleName(), "appliesFilter");
+
+ try {
+ return data != null && (filter == null || evaluateExpression(data, filter.getExpression()).equals("true"));
+ } catch (final RuntimeException e) {
+ return false;
+ } finally {
+ context.stopRuntimeMeasurement(timingHandle);
+ }
+ }
+
+ private <T> String evaluateExpression(final T data, final CommonExpression expression) throws ODataException {
+ switch (expression.getKind()) {
+ case UNARY:
+ final UnaryExpression unaryExpression = (UnaryExpression) expression;
+ final String operand = evaluateExpression(data, unaryExpression.getOperand());
+
+ switch (unaryExpression.getOperator()) {
+ case NOT:
+ return Boolean.toString(!Boolean.parseBoolean(operand));
+ case MINUS:
+ return operand.startsWith("-") ? operand.substring(1) : "-" + operand;
+ default:
+ throw new ODataNotImplementedException();
+ }
+
+ case BINARY:
+ final BinaryExpression binaryExpression = (BinaryExpression) expression;
+ final EdmSimpleType type = (EdmSimpleType) binaryExpression.getLeftOperand().getEdmType();
+ final String left = evaluateExpression(data, binaryExpression.getLeftOperand());
+ final String right = evaluateExpression(data, binaryExpression.getRightOperand());
+
+ switch (binaryExpression.getOperator()) {
+ case ADD:
+ if (binaryExpression.getEdmType() == EdmSimpleTypeKind.Decimal.getEdmSimpleTypeInstance()
+ || binaryExpression.getEdmType() == EdmSimpleTypeKind.Double.getEdmSimpleTypeInstance()
+ || binaryExpression.getEdmType() == EdmSimpleTypeKind.Single.getEdmSimpleTypeInstance()) {
+ return Double.toString(Double.valueOf(left) + Double.valueOf(right));
+ } else {
+ return Long.toString(Long.valueOf(left) + Long.valueOf(right));
+ }
+ case SUB:
+ if (binaryExpression.getEdmType() == EdmSimpleTypeKind.Decimal.getEdmSimpleTypeInstance()
+ || binaryExpression.getEdmType() == EdmSimpleTypeKind.Double.getEdmSimpleTypeInstance()
+ || binaryExpression.getEdmType() == EdmSimpleTypeKind.Single.getEdmSimpleTypeInstance()) {
+ return Double.toString(Double.valueOf(left) - Double.valueOf(right));
+ } else {
+ return Long.toString(Long.valueOf(left) - Long.valueOf(right));
+ }
+ case MUL:
+ if (binaryExpression.getEdmType() == EdmSimpleTypeKind.Decimal.getEdmSimpleTypeInstance()
+ || binaryExpression.getEdmType() == EdmSimpleTypeKind.Double.getEdmSimpleTypeInstance()
+ || binaryExpression.getEdmType() == EdmSimpleTypeKind.Single.getEdmSimpleTypeInstance()) {
+ return Double.toString(Double.valueOf(left) * Double.valueOf(right));
+ } else {
+ return Long.toString(Long.valueOf(left) * Long.valueOf(right));
+ }
+ case DIV:
+ final String number = Double.toString(Double.valueOf(left) / Double.valueOf(right));
+ return number.endsWith(".0") ? number.replace(".0", "") : number;
+ case MODULO:
+ if (binaryExpression.getEdmType() == EdmSimpleTypeKind.Decimal.getEdmSimpleTypeInstance()
+ || binaryExpression.getEdmType() == EdmSimpleTypeKind.Double.getEdmSimpleTypeInstance()
+ || binaryExpression.getEdmType() == EdmSimpleTypeKind.Single.getEdmSimpleTypeInstance()) {
+ return Double.toString(Double.valueOf(left) % Double.valueOf(right));
+ } else {
+ return Long.toString(Long.valueOf(left) % Long.valueOf(right));
+ }
+ case AND:
+ return Boolean.toString(left.equals("true") && right.equals("true"));
+ case OR:
+ return Boolean.toString(left.equals("true") || right.equals("true"));
+ case EQ:
+ return Boolean.toString(left.equals(right));
+ case NE:
+ return Boolean.toString(!left.equals(right));
+ case LT:
+ if (type == EdmSimpleTypeKind.String.getEdmSimpleTypeInstance()
+ || type == EdmSimpleTypeKind.DateTime.getEdmSimpleTypeInstance()
+ || type == EdmSimpleTypeKind.DateTimeOffset.getEdmSimpleTypeInstance()
+ || type == EdmSimpleTypeKind.Guid.getEdmSimpleTypeInstance()
+ || type == EdmSimpleTypeKind.Time.getEdmSimpleTypeInstance()) {
+ return Boolean.toString(left.compareTo(right) < 0);
+ } else {
+ return Boolean.toString(Double.valueOf(left) < Double.valueOf(right));
+ }
+ case LE:
+ if (type == EdmSimpleTypeKind.String.getEdmSimpleTypeInstance()
+ || type == EdmSimpleTypeKind.DateTime.getEdmSimpleTypeInstance()
+ || type == EdmSimpleTypeKind.DateTimeOffset.getEdmSimpleTypeInstance()
+ || type == EdmSimpleTypeKind.Guid.getEdmSimpleTypeInstance()
+ || type == EdmSimpleTypeKind.Time.getEdmSimpleTypeInstance()) {
+ return Boolean.toString(left.compareTo(right) <= 0);
+ } else {
+ return Boolean.toString(Double.valueOf(left) <= Double.valueOf(right));
+ }
+ case GT:
+ if (type == EdmSimpleTypeKind.String.getEdmSimpleTypeInstance()
+ || type == EdmSimpleTypeKind.DateTime.getEdmSimpleTypeInstance()
+ || type == EdmSimpleTypeKind.DateTimeOffset.getEdmSimpleTypeInstance()
+ || type == EdmSimpleTypeKind.Guid.getEdmSimpleTypeInstance()
+ || type == EdmSimpleTypeKind.Time.getEdmSimpleTypeInstance()) {
+ return Boolean.toString(left.compareTo(right) > 0);
+ } else {
+ return Boolean.toString(Double.valueOf(left) > Double.valueOf(right));
+ }
+ case GE:
+ if (type == EdmSimpleTypeKind.String.getEdmSimpleTypeInstance()
+ || type == EdmSimpleTypeKind.DateTime.getEdmSimpleTypeInstance()
+ || type == EdmSimpleTypeKind.DateTimeOffset.getEdmSimpleTypeInstance()
+ || type == EdmSimpleTypeKind.Guid.getEdmSimpleTypeInstance()
+ || type == EdmSimpleTypeKind.Time.getEdmSimpleTypeInstance()) {
+ return Boolean.toString(left.compareTo(right) >= 0);
+ } else {
+ return Boolean.toString(Double.valueOf(left) >= Double.valueOf(right));
+ }
+ case PROPERTY_ACCESS:
+ throw new ODataNotImplementedException();
+ default:
+ throw new ODataNotImplementedException();
+ }
+
+ case PROPERTY:
+ final EdmProperty property = (EdmProperty) ((PropertyExpression) expression).getEdmProperty();
+ final EdmSimpleType propertyType = (EdmSimpleType) property.getType();
+ return propertyType.valueToString(valueAccess.getPropertyValue(data, property), EdmLiteralKind.DEFAULT,
+ property.getFacets());
+
+ case MEMBER:
+ final MemberExpression memberExpression = (MemberExpression) expression;
+ final PropertyExpression propertyExpression = (PropertyExpression) memberExpression.getProperty();
+ final EdmProperty memberProperty = (EdmProperty) propertyExpression.getEdmProperty();
+ final EdmSimpleType memberType = (EdmSimpleType) memberExpression.getEdmType();
+ List<EdmProperty> propertyPath = new ArrayList<EdmProperty>();
+ CommonExpression currentExpression = memberExpression;
+ while (currentExpression != null) {
+ final PropertyExpression currentPropertyExpression =
+ (PropertyExpression) (currentExpression.getKind() == ExpressionKind.MEMBER ?
+ ((MemberExpression) currentExpression).getProperty() : currentExpression);
+ final EdmTyped currentProperty = currentPropertyExpression.getEdmProperty();
+ final EdmTypeKind kind = currentProperty.getType().getKind();
+ if (kind == EdmTypeKind.SIMPLE || kind == EdmTypeKind.COMPLEX) {
+ propertyPath.add(0, (EdmProperty) currentProperty);
+ } else {
+ throw new ODataNotImplementedException();
+ }
+ currentExpression =
+ currentExpression.getKind() == ExpressionKind.MEMBER ? ((MemberExpression) currentExpression).getPath()
+ : null;
+ }
+ return memberType.valueToString(getPropertyValue(data, propertyPath), EdmLiteralKind.DEFAULT, memberProperty
+ .getFacets());
+
+ case LITERAL:
+ final LiteralExpression literal = (LiteralExpression) expression;
+ final EdmSimpleType literalType = (EdmSimpleType) literal.getEdmType();
+ return literalType.valueToString(literalType.valueOfString(literal.getUriLiteral(), EdmLiteralKind.URI, null,
+ literalType.getDefaultType()),
+ EdmLiteralKind.DEFAULT, null);
+
+ case METHOD:
+ final MethodExpression methodExpression = (MethodExpression) expression;
+ final String first = evaluateExpression(data, methodExpression.getParameters().get(0));
+ final String second = methodExpression.getParameterCount() > 1 ?
+ evaluateExpression(data, methodExpression.getParameters().get(1)) : null;
+ final String third = methodExpression.getParameterCount() > 2 ?
+ evaluateExpression(data, methodExpression.getParameters().get(2)) : null;
+
+ switch (methodExpression.getMethod()) {
+ case ENDSWITH:
+ return Boolean.toString(first.endsWith(second));
+ case INDEXOF:
+ return Integer.toString(first.indexOf(second));
+ case STARTSWITH:
+ return Boolean.toString(first.startsWith(second));
+ case TOLOWER:
+ return first.toLowerCase(Locale.ROOT);
+ case TOUPPER:
+ return first.toUpperCase(Locale.ROOT);
+ case TRIM:
+ return first.trim();
+ case SUBSTRING:
+ final int offset = Integer.parseInt(second);
+ return first.substring(offset, offset + Integer.parseInt(third));
+ case SUBSTRINGOF:
+ return Boolean.toString(second.contains(first));
+ case CONCAT:
+ return first + second;
+ case LENGTH:
+ return Integer.toString(first.length());
+ case YEAR:
+ return String.valueOf(Integer.parseInt(first.substring(0, 4)));
+ case MONTH:
+ return String.valueOf(Integer.parseInt(first.substring(5, 7)));
+ case DAY:
+ return String.valueOf(Integer.parseInt(first.substring(8, 10)));
+ case HOUR:
+ return String.valueOf(Integer.parseInt(first.substring(11, 13)));
+ case MINUTE:
+ return String.valueOf(Integer.parseInt(first.substring(14, 16)));
+ case SECOND:
+ return String.valueOf(Integer.parseInt(first.substring(17, 19)));
+ case ROUND:
+ return Long.toString(Math.round(Double.valueOf(first)));
+ case FLOOR:
+ return Long.toString(Math.round(Math.floor(Double.valueOf(first))));
+ case CEILING:
+ return Long.toString(Math.round(Math.ceil(Double.valueOf(first))));
+ default:
+ throw new ODataNotImplementedException();
+ }
+
+ default:
+ throw new ODataNotImplementedException();
+ }
+ }
+
+ private <T> String getSkipToken(final EdmEntitySet entitySet, final T data) throws ODataException {
+ String skipToken = "";
+ for (final EdmProperty property : entitySet.getEntityType().getKeyProperties()) {
+ final EdmSimpleType type = (EdmSimpleType) property.getType();
+ skipToken = skipToken.concat(type.valueToString(valueAccess.getPropertyValue(data, property),
+ EdmLiteralKind.DEFAULT, property.getFacets()));
+ }
+ return skipToken;
+ }
+
+ private <T> Object getPropertyValue(final T data, final List<EdmProperty> propertyPath) throws ODataException {
+ Object dataObject = data;
+ for (final EdmProperty property : propertyPath) {
+ if (dataObject != null) {
+ dataObject = valueAccess.getPropertyValue(dataObject, property);
+ }
+ }
+ return dataObject;
+ }
+
+ private void handleMimeType(Object data, EdmMapping mapping, Map<String, Object> valueMap)
+ throws ODataException {
+ final String mimeTypeName = mapping.getMimeType();
+ if (mimeTypeName != null) {
+ Object value = valueAccess.getMappingValue(data, mapping);
+ valueMap.put(mimeTypeName, value);
+ if (mapping.getMediaResourceMimeTypeKey() != null) {
+ valueMap.put(mapping.getMediaResourceMimeTypeKey(), value);
+ }
+ }
+ }
+
+ private <T> Map<String, Object> getSimpleTypeValueMap(final T data, final List<EdmProperty> propertyPath)
+ throws ODataException {
+ final EdmProperty property = propertyPath.get(propertyPath.size() - 1);
+ Map<String, Object> valueWithMimeType = new HashMap<String, Object>();
+ valueWithMimeType.put(property.getName(), getPropertyValue(data, propertyPath));
+
+ handleMimeType(data, property.getMapping(), valueWithMimeType);
+
+ return valueWithMimeType;
+ }
+
+ private <T> Map<String, Object> getStructuralTypeValueMap(final T data, final EdmStructuralType type)
+ throws ODataException {
+ ODataContext context = getContext();
+ final int timingHandle = context.startRuntimeMeasurement(getClass().getSimpleName(), "getStructuralTypeValueMap");
+
+ Map<String, Object> valueMap = new HashMap<String, Object>();
+
+ EdmMapping mapping = type.getMapping();
+ if (mapping != null) {
+ handleMimeType(data, mapping, valueMap);
+ }
+
+ for (final String propertyName : type.getPropertyNames()) {
+ final EdmProperty property = (EdmProperty) type.getProperty(propertyName);
+ final Object value = valueAccess.getPropertyValue(data, property);
+
+ if (property.isSimple()) {
+ if (property.getMapping() == null || property.getMapping().getMimeType() == null) {
+ valueMap.put(propertyName, value);
+ } else {
+ // TODO: enable MIME type mapping outside the current subtree
+ valueMap.put(propertyName, getSimpleTypeValueMap(data, Arrays.asList(property)));
+ }
+ } else {
+ valueMap.put(propertyName, getStructuralTypeValueMap(value, (EdmStructuralType) property.getType()));
+ }
+ }
+
+ context.stopRuntimeMeasurement(timingHandle);
+
+ return valueMap;
+ }
+
+ private <T> Map<String, Object> getStructuralTypeTypeMap(final T data, final EdmStructuralType type)
+ throws ODataException {
+ ODataContext context = getContext();
+ final int timingHandle = context.startRuntimeMeasurement(getClass().getSimpleName(), "getStructuralTypeTypeMap");
+
+ Map<String, Object> typeMap = new HashMap<String, Object>();
+ for (final String propertyName : type.getPropertyNames()) {
+ final EdmProperty property = (EdmProperty) type.getProperty(propertyName);
+ if (property.isSimple()) {
+ typeMap.put(propertyName, valueAccess.getPropertyType(data, property));
+ } else {
+ typeMap.put(propertyName, getStructuralTypeTypeMap(valueAccess.getPropertyValue(data, property),
+ (EdmStructuralType) property.getType()));
+ }
+ }
+
+ context.stopRuntimeMeasurement(timingHandle);
+
+ return typeMap;
+ }
+
+ private <T> void setStructuralTypeValuesFromMap(final T data, final EdmStructuralType type,
+ final Map<String, Object> valueMap, final boolean merge) throws ODataException {
+ ODataContext context = getContext();
+ final int timingHandle =
+ context.startRuntimeMeasurement(getClass().getSimpleName(), "setStructuralTypeValuesFromMap");
+
+ for (final String propertyName : type.getPropertyNames()) {
+ final EdmProperty property = (EdmProperty) type.getProperty(propertyName);
+ if (type instanceof EdmEntityType && ((EdmEntityType) type).getKeyProperties().contains(property)) {
+ continue;
+ }
+ if (!merge || valueMap != null && valueMap.containsKey(propertyName)) {
+ final Object value = valueMap == null ? null : valueMap.get(propertyName);
+ if (property.isSimple()) {
+ valueAccess.setPropertyValue(data, property, value);
+ } else {
+ @SuppressWarnings("unchecked")
+ final Map<String, Object> values = (Map<String, Object>) value;
+ setStructuralTypeValuesFromMap(valueAccess.getPropertyValue(data, property),
+ (EdmStructuralType) property.getType(), values, merge);
+ }
+ }
+ }
+
+ context.stopRuntimeMeasurement(timingHandle);
+ }
+
+ @Override
+ public ODataResponse executeBatch(final BatchHandler handler, final String contentType, final InputStream content)
+ throws ODataException {
+ ODataResponse batchResponse;
+ List<BatchResponsePart> batchResponseParts = new ArrayList<BatchResponsePart>();
+ PathInfo pathInfo = getContext().getPathInfo();
+ EntityProviderBatchProperties batchProperties = EntityProviderBatchProperties.init().pathInfo(pathInfo).build();
+ List<BatchRequestPart> batchParts = EntityProvider.parseBatchRequest(contentType, content, batchProperties);
+ for (BatchRequestPart batchPart : batchParts) {
+ batchResponseParts.add(handler.handleBatchPart(batchPart));
+ }
+ batchResponse = EntityProvider.writeBatchResponse(batchResponseParts);
+ return batchResponse;
+ }
+
+ @Override
+ public BatchResponsePart executeChangeSet(final BatchHandler handler, final List<ODataRequest> requests)
+ throws ODataException {
+ List<ODataResponse> responses = new ArrayList<ODataResponse>();
+ for (ODataRequest request : requests) {
+ ODataResponse response = handler.handleRequest(request);
+ if (response.getStatus().getStatusCode() >= HttpStatusCodes.BAD_REQUEST.getStatusCode()) {
+ // Rollback
+ List<ODataResponse> errorResponses = new ArrayList<ODataResponse>(1);
+ errorResponses.add(response);
+ return BatchResponsePart.responses(errorResponses).changeSet(false).build();
+ }
+ responses.add(response);
+ }
+ return BatchResponsePart.responses(responses).changeSet(true).build();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d83070de/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/json/EdmAnnotationSerializer.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/json/EdmAnnotationSerializer.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/json/EdmAnnotationSerializer.java
index 10b8945..7dceba9 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/json/EdmAnnotationSerializer.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/json/EdmAnnotationSerializer.java
@@ -25,16 +25,12 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
-import java.util.Map;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
-import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
import org.apache.olingo.odata2.api.edm.EdmLiteralKind;
-import org.apache.olingo.odata2.api.edm.EdmSimpleType;
import org.apache.olingo.odata2.api.edm.EdmSimpleTypeException;
import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
import org.apache.olingo.odata2.core.annotation.edm.AnnotationHelper;
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d83070de/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/json/JsonConsumer.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/json/JsonConsumer.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/json/JsonConsumer.java
index 4a6d9ad..265484d 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/json/JsonConsumer.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/json/JsonConsumer.java
@@ -18,15 +18,17 @@
******************************************************************************/
package org.apache.olingo.odata2.core.annotation.processor.json;
-import com.google.gson.stream.JsonReader;
-import com.google.gson.stream.JsonToken;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
+
import org.apache.olingo.odata2.core.ep.util.FormatJson;
+import com.google.gson.stream.JsonReader;
+import com.google.gson.stream.JsonToken;
+
/**
*
*/
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d83070de/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/json/JsonWriter.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/json/JsonWriter.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/json/JsonWriter.java
index b972fed..a277b41 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/json/JsonWriter.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/json/JsonWriter.java
@@ -16,6 +16,7 @@ package org.apache.olingo.odata2.core.annotation.processor.json;
import java.io.IOException;
import java.io.Writer;
+
import org.apache.olingo.odata2.core.exception.ODataRuntimeException;
public class JsonWriter {
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d83070de/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProviderTest.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProviderTest.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProviderTest.java
index 509303c..c6a9219 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProviderTest.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProviderTest.java
@@ -15,9 +15,16 @@
*/
package org.apache.olingo.odata2.core.annotation.edm;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
+
import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
import org.apache.olingo.odata2.api.edm.FullQualifiedName;
import org.apache.olingo.odata2.api.edm.provider.Association;
@@ -43,11 +50,6 @@ import org.apache.olingo.odata2.core.annotation.model.Photo;
import org.apache.olingo.odata2.core.annotation.model.RefBase;
import org.apache.olingo.odata2.core.annotation.model.Room;
import org.apache.olingo.odata2.core.annotation.model.Team;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import org.junit.Test;
/**
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d83070de/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Building.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Building.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Building.java
index 9889c2e..9427151 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Building.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Building.java
@@ -21,6 +21,7 @@ package org.apache.olingo.odata2.core.annotation.model;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+
import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d83070de/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/City.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/City.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/City.java
index 6a117db..c063ffe 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/City.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/City.java
@@ -21,6 +21,7 @@ package org.apache.olingo.odata2.core.annotation.model;
import org.apache.olingo.odata2.api.annotation.edm.EdmComplexEntity;
import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
+
/**
*
*/
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d83070de/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Employee.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Employee.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Employee.java
index 5247448..07a7dcb 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Employee.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Employee.java
@@ -20,10 +20,11 @@ package org.apache.olingo.odata2.core.annotation.model;
import java.text.DateFormat;
import java.util.Calendar;
+
import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
-import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
import org.apache.olingo.odata2.api.annotation.edm.NavigationEnd;
import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d83070de/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Location.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Location.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Location.java
index b8b9725..242b4cf 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Location.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Location.java
@@ -21,6 +21,7 @@ package org.apache.olingo.odata2.core.annotation.model;
import org.apache.olingo.odata2.api.annotation.edm.EdmComplexEntity;
import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
+
/**
*
*/
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d83070de/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Manager.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Manager.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Manager.java
index 1000822..187d4f8 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Manager.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Manager.java
@@ -20,6 +20,7 @@ package org.apache.olingo.odata2.core.annotation.model;
import java.util.ArrayList;
import java.util.List;
+
import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
import org.apache.olingo.odata2.api.annotation.edm.NavigationEnd;
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d83070de/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/RefBase.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/RefBase.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/RefBase.java
index 15a7dcc..c38a506 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/RefBase.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/RefBase.java
@@ -17,8 +17,8 @@
package org.apache.olingo.odata2.core.annotation.model;
import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
+import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
/**
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d83070de/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Room.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Room.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Room.java
index e1c55ed..3628ac8 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Room.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Room.java
@@ -17,6 +17,7 @@ package org.apache.olingo.odata2.core.annotation.model;
import java.util.ArrayList;
import java.util.List;
+
import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d83070de/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Team.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Team.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Team.java
index 529ed5a..e3ea0cc 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Team.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Team.java
@@ -20,6 +20,7 @@ package org.apache.olingo.odata2.core.annotation.model;
import java.util.ArrayList;
import java.util.List;
+
import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
[46/52] Renamed project
Posted by mi...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/12ea18ae/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/ListsProcessor.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/ListsProcessor.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/ListsProcessor.java
deleted file mode 100644
index 19218d7..0000000
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/ListsProcessor.java
+++ /dev/null
@@ -1,1630 +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.core.annotation.processor;
-
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-
-import org.apache.olingo.odata2.api.ODataCallback;
-import org.apache.olingo.odata2.api.batch.BatchHandler;
-import org.apache.olingo.odata2.api.batch.BatchRequestPart;
-import org.apache.olingo.odata2.api.batch.BatchResponsePart;
-import org.apache.olingo.odata2.api.commons.HttpContentType;
-import org.apache.olingo.odata2.api.commons.HttpStatusCodes;
-import org.apache.olingo.odata2.api.commons.InlineCount;
-import org.apache.olingo.odata2.api.data.DataSource;
-import org.apache.olingo.odata2.api.data.DataSource.BinaryData;
-import org.apache.olingo.odata2.api.data.DataSourceProcessor;
-import org.apache.olingo.odata2.api.data.ValueAccess;
-import org.apache.olingo.odata2.api.edm.Edm;
-import org.apache.olingo.odata2.api.edm.EdmConcurrencyMode;
-import org.apache.olingo.odata2.api.edm.EdmEntitySet;
-import org.apache.olingo.odata2.api.edm.EdmEntityType;
-import org.apache.olingo.odata2.api.edm.EdmException;
-import org.apache.olingo.odata2.api.edm.EdmFunctionImport;
-import org.apache.olingo.odata2.api.edm.EdmLiteral;
-import org.apache.olingo.odata2.api.edm.EdmLiteralKind;
-import org.apache.olingo.odata2.api.edm.EdmMapping;
-import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
-import org.apache.olingo.odata2.api.edm.EdmNavigationProperty;
-import org.apache.olingo.odata2.api.edm.EdmProperty;
-import org.apache.olingo.odata2.api.edm.EdmSimpleType;
-import org.apache.olingo.odata2.api.edm.EdmSimpleTypeException;
-import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
-import org.apache.olingo.odata2.api.edm.EdmStructuralType;
-import org.apache.olingo.odata2.api.edm.EdmType;
-import org.apache.olingo.odata2.api.edm.EdmTypeKind;
-import org.apache.olingo.odata2.api.edm.EdmTyped;
-import org.apache.olingo.odata2.api.ep.EntityProvider;
-import org.apache.olingo.odata2.api.ep.EntityProviderBatchProperties;
-import org.apache.olingo.odata2.api.ep.EntityProviderException;
-import org.apache.olingo.odata2.api.ep.EntityProviderReadProperties;
-import org.apache.olingo.odata2.api.ep.EntityProviderWriteProperties;
-import org.apache.olingo.odata2.api.ep.callback.OnWriteEntryContent;
-import org.apache.olingo.odata2.api.ep.callback.OnWriteFeedContent;
-import org.apache.olingo.odata2.api.ep.callback.WriteCallbackContext;
-import org.apache.olingo.odata2.api.ep.callback.WriteEntryCallbackContext;
-import org.apache.olingo.odata2.api.ep.callback.WriteEntryCallbackResult;
-import org.apache.olingo.odata2.api.ep.callback.WriteFeedCallbackContext;
-import org.apache.olingo.odata2.api.ep.callback.WriteFeedCallbackResult;
-import org.apache.olingo.odata2.api.ep.entry.ODataEntry;
-import org.apache.olingo.odata2.api.ep.feed.ODataFeed;
-import org.apache.olingo.odata2.api.exception.ODataApplicationException;
-import org.apache.olingo.odata2.api.exception.ODataBadRequestException;
-import org.apache.olingo.odata2.api.exception.ODataException;
-import org.apache.olingo.odata2.api.exception.ODataHttpException;
-import org.apache.olingo.odata2.api.exception.ODataNotFoundException;
-import org.apache.olingo.odata2.api.exception.ODataNotImplementedException;
-import org.apache.olingo.odata2.api.processor.ODataContext;
-import org.apache.olingo.odata2.api.processor.ODataRequest;
-import org.apache.olingo.odata2.api.processor.ODataResponse;
-import org.apache.olingo.odata2.api.uri.ExpandSelectTreeNode;
-import org.apache.olingo.odata2.api.uri.KeyPredicate;
-import org.apache.olingo.odata2.api.uri.NavigationSegment;
-import org.apache.olingo.odata2.api.uri.PathInfo;
-import org.apache.olingo.odata2.api.uri.UriParser;
-import org.apache.olingo.odata2.api.uri.expression.BinaryExpression;
-import org.apache.olingo.odata2.api.uri.expression.CommonExpression;
-import org.apache.olingo.odata2.api.uri.expression.ExpressionKind;
-import org.apache.olingo.odata2.api.uri.expression.FilterExpression;
-import org.apache.olingo.odata2.api.uri.expression.LiteralExpression;
-import org.apache.olingo.odata2.api.uri.expression.MemberExpression;
-import org.apache.olingo.odata2.api.uri.expression.MethodExpression;
-import org.apache.olingo.odata2.api.uri.expression.OrderByExpression;
-import org.apache.olingo.odata2.api.uri.expression.OrderExpression;
-import org.apache.olingo.odata2.api.uri.expression.PropertyExpression;
-import org.apache.olingo.odata2.api.uri.expression.SortOrder;
-import org.apache.olingo.odata2.api.uri.expression.UnaryExpression;
-import org.apache.olingo.odata2.api.uri.info.DeleteUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetComplexPropertyUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetEntityCountUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetEntityLinkCountUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetEntityLinkUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetEntitySetCountUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetEntitySetLinksCountUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetEntitySetLinksUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetEntitySetUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetEntityUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetFunctionImportUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetMediaResourceUriInfo;
-import org.apache.olingo.odata2.api.uri.info.GetSimplePropertyUriInfo;
-import org.apache.olingo.odata2.api.uri.info.PostUriInfo;
-import org.apache.olingo.odata2.api.uri.info.PutMergePatchUriInfo;
-
-/**
- * Implementation of the centralized parts of OData processing,
- * allowing to use the simplified {@link DataSource} for the
- * actual data handling.
- *
- */
-public class ListsProcessor extends DataSourceProcessor {
-
- // TODO: Paging size should be configurable.
- private static final int SERVER_PAGING_SIZE = 100;
-
- public ListsProcessor(final DataSource dataSource, final ValueAccess valueAccess) {
- super(dataSource, valueAccess);
- }
-
- @Override
- public ODataResponse readEntitySet(final GetEntitySetUriInfo uriInfo, final String contentType)
- throws ODataException {
- ArrayList<Object> data = new ArrayList<Object>();
- try {
- data.addAll((List<?>) retrieveData(
- uriInfo.getStartEntitySet(),
- uriInfo.getKeyPredicates(),
- uriInfo.getFunctionImport(),
- mapFunctionParameters(uriInfo.getFunctionImportParameters()),
- uriInfo.getNavigationSegments()));
- } catch (final ODataNotFoundException e) {
- data.clear();
- }
-
- final EdmEntitySet entitySet = uriInfo.getTargetEntitySet();
- final InlineCount inlineCountType = uriInfo.getInlineCount();
- final Integer count = applySystemQueryOptions(
- entitySet,
- data,
- uriInfo.getFilter(),
- inlineCountType,
- uriInfo.getOrderBy(),
- uriInfo.getSkipToken(),
- uriInfo.getSkip(),
- uriInfo.getTop());
-
- ODataContext context = getContext();
- String nextLink = null;
-
- // Limit the number of returned entities and provide a "next" link
- // if there are further entities.
- // Almost all system query options in the current request must be carried
- // over to the URI for the "next" link, with the exception of $skiptoken
- // and $skip.
- if (data.size() > SERVER_PAGING_SIZE) {
- if (uriInfo.getOrderBy() == null
- && uriInfo.getSkipToken() == null
- && uriInfo.getSkip() == null
- && uriInfo.getTop() == null) {
- sortInDefaultOrder(entitySet, data);
- }
-
- // TODO: Percent-encode "next" link.
- nextLink = context.getPathInfo().getServiceRoot().relativize(context.getPathInfo().getRequestUri()).toString()
- .replaceAll("\\$skiptoken=.+?&?", "")
- .replaceAll("\\$skip=.+?&?", "")
- .replaceFirst("(?:\\?|&)$", ""); // Remove potentially trailing "?" or "&" left over from remove actions
- // above.
- nextLink += (nextLink.contains("?") ? "&" : "?")
- + "$skiptoken=" + getSkipToken(entitySet, data.get(SERVER_PAGING_SIZE));
-
- while (data.size() > SERVER_PAGING_SIZE) {
- data.remove(SERVER_PAGING_SIZE);
- }
- }
-
- final EdmEntityType entityType = entitySet.getEntityType();
- List<Map<String, Object>> values = new ArrayList<Map<String, Object>>();
- for (final Object entryData : data) {
- values.add(getStructuralTypeValueMap(entryData, entityType));
- }
-
- final EntityProviderWriteProperties feedProperties = EntityProviderWriteProperties
- .serviceRoot(context.getPathInfo().getServiceRoot())
- .inlineCountType(inlineCountType)
- .inlineCount(count)
- .expandSelectTree(UriParser.createExpandSelectTree(uriInfo.getSelect(), uriInfo.getExpand()))
- .callbacks(getCallbacks(data, entityType))
- .nextLink(nextLink)
- .build();
-
- final int timingHandle = context.startRuntimeMeasurement("EntityProvider", "writeFeed");
- final ODataResponse response = EntityProvider.writeFeed(contentType, entitySet, values, feedProperties);
-
- context.stopRuntimeMeasurement(timingHandle);
-
- return ODataResponse.fromResponse(response).build();
- }
-
- @Override
- public ODataResponse countEntitySet(final GetEntitySetCountUriInfo uriInfo, final String contentType)
- throws ODataException {
- ArrayList<Object> data = new ArrayList<Object>();
- try {
- data.addAll((List<?>) retrieveData(
- uriInfo.getStartEntitySet(),
- uriInfo.getKeyPredicates(),
- uriInfo.getFunctionImport(),
- mapFunctionParameters(uriInfo.getFunctionImportParameters()),
- uriInfo.getNavigationSegments()));
- } catch (final ODataNotFoundException e) {
- data.clear();
- }
-
- applySystemQueryOptions(
- uriInfo.getTargetEntitySet(),
- data,
- uriInfo.getFilter(),
- null,
- null,
- null,
- uriInfo.getSkip(),
- uriInfo.getTop());
-
- return ODataResponse.fromResponse(EntityProvider.writeText(String.valueOf(data.size()))).build();
- }
-
- @Override
- public ODataResponse readEntityLinks(final GetEntitySetLinksUriInfo uriInfo, final String contentType)
- throws ODataException {
- ArrayList<Object> data = new ArrayList<Object>();
- try {
- data.addAll((List<?>) retrieveData(
- uriInfo.getStartEntitySet(),
- uriInfo.getKeyPredicates(),
- uriInfo.getFunctionImport(),
- mapFunctionParameters(uriInfo.getFunctionImportParameters()),
- uriInfo.getNavigationSegments()));
- } catch (final ODataNotFoundException e) {
- data.clear();
- }
-
- final Integer count = applySystemQueryOptions(
- uriInfo.getTargetEntitySet(),
- data,
- uriInfo.getFilter(),
- uriInfo.getInlineCount(),
- null, // uriInfo.getOrderBy(),
- uriInfo.getSkipToken(),
- uriInfo.getSkip(),
- uriInfo.getTop());
-
- final EdmEntitySet entitySet = uriInfo.getTargetEntitySet();
-
- List<Map<String, Object>> values = new ArrayList<Map<String, Object>>();
- for (final Object entryData : data) {
- Map<String, Object> entryValues = new HashMap<String, Object>();
- for (final EdmProperty property : entitySet.getEntityType().getKeyProperties()) {
- entryValues.put(property.getName(), valueAccess.getPropertyValue(entryData, property));
- }
- values.add(entryValues);
- }
-
- ODataContext context = getContext();
- final EntityProviderWriteProperties entryProperties = EntityProviderWriteProperties
- .serviceRoot(context.getPathInfo().getServiceRoot())
- .inlineCountType(uriInfo.getInlineCount())
- .inlineCount(count)
- .build();
-
- final int timingHandle = context.startRuntimeMeasurement("EntityProvider", "writeLinks");
-
- final ODataResponse response = EntityProvider.writeLinks(contentType, entitySet, values, entryProperties);
-
- context.stopRuntimeMeasurement(timingHandle);
-
- return ODataResponse.fromResponse(response).build();
- }
-
- @Override
- public ODataResponse countEntityLinks(final GetEntitySetLinksCountUriInfo uriInfo, final String contentType)
- throws ODataException {
- return countEntitySet((GetEntitySetCountUriInfo) uriInfo, contentType);
- }
-
- @Override
- public ODataResponse readEntity(final GetEntityUriInfo uriInfo, final String contentType) throws ODataException {
- final Object data = retrieveData(
- uriInfo.getStartEntitySet(),
- uriInfo.getKeyPredicates(),
- uriInfo.getFunctionImport(),
- mapFunctionParameters(uriInfo.getFunctionImportParameters()),
- uriInfo.getNavigationSegments());
-
- if (!appliesFilter(data, uriInfo.getFilter())) {
- throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
- }
-
- final ExpandSelectTreeNode expandSelectTreeNode =
- UriParser.createExpandSelectTree(uriInfo.getSelect(), uriInfo.getExpand());
- ODataResponse odr =
- ODataResponse.fromResponse(writeEntry(uriInfo.getTargetEntitySet(), expandSelectTreeNode, data, contentType))
- .build();
-
- return odr;
- }
-
- @Override
- public ODataResponse existsEntity(final GetEntityCountUriInfo uriInfo, final String contentType)
- throws ODataException {
- final Object data = retrieveData(
- uriInfo.getStartEntitySet(),
- uriInfo.getKeyPredicates(),
- uriInfo.getFunctionImport(),
- mapFunctionParameters(uriInfo.getFunctionImportParameters()),
- uriInfo.getNavigationSegments());
-
- return ODataResponse.fromResponse(EntityProvider.writeText(appliesFilter(data, uriInfo.getFilter()) ? "1" : "0"))
- .build();
- }
-
- @Override
- public ODataResponse deleteEntity(final DeleteUriInfo uriInfo, final String contentType) throws ODataException {
- dataSource.deleteData(
- uriInfo.getStartEntitySet(),
- mapKey(uriInfo.getKeyPredicates()));
- return ODataResponse.newBuilder().build();
- }
-
- @Override
- public ODataResponse createEntity(final PostUriInfo uriInfo, final InputStream content,
- final String requestContentType, final String contentType) throws ODataException {
- final EdmEntitySet entitySet = uriInfo.getTargetEntitySet();
- final EdmEntityType entityType = entitySet.getEntityType();
-
- Object data = dataSource.newDataObject(entitySet);
- ExpandSelectTreeNode expandSelectTree = null;
-
- if (entityType.hasStream()) {
- dataSource.createData(entitySet, data);
- dataSource.writeBinaryData(entitySet, data,
- new BinaryData(EntityProvider.readBinary(content), requestContentType));
-
- } else {
- final EntityProviderReadProperties properties = EntityProviderReadProperties.init()
- .mergeSemantic(false)
- .addTypeMappings(getStructuralTypeTypeMap(data, entityType))
- .build();
- final ODataEntry entryValues = parseEntry(entitySet, content, requestContentType, properties);
-
- setStructuralTypeValuesFromMap(data, entityType, entryValues.getProperties(), false);
-
- dataSource.createData(entitySet, data);
-
- createInlinedEntities(entitySet, data, entryValues);
-
- expandSelectTree = entryValues.getExpandSelectTree();
- }
-
- // Link back to the entity the target entity set is related to, if any.
- final List<NavigationSegment> navigationSegments = uriInfo.getNavigationSegments();
- if (!navigationSegments.isEmpty()) {
- final List<NavigationSegment> previousSegments = navigationSegments.subList(0, navigationSegments.size() - 1);
- final Object sourceData = retrieveData(
- uriInfo.getStartEntitySet(),
- uriInfo.getKeyPredicates(),
- uriInfo.getFunctionImport(),
- mapFunctionParameters(uriInfo.getFunctionImportParameters()),
- previousSegments);
- final EdmEntitySet previousEntitySet = previousSegments.isEmpty() ?
- uriInfo.getStartEntitySet() : previousSegments.get(previousSegments.size() - 1).getEntitySet();
- dataSource.writeRelation(previousEntitySet, sourceData, entitySet, getStructuralTypeValueMap(data, entityType));
- }
-
- return ODataResponse.fromResponse(writeEntry(uriInfo.getTargetEntitySet(), expandSelectTree, data, contentType))
- .eTag(constructETag(entitySet, data)).build();
- }
-
- @Override
- public ODataResponse updateEntity(final PutMergePatchUriInfo uriInfo, final InputStream content,
- final String requestContentType, final boolean merge, final String contentType) throws ODataException {
- Object data = retrieveData(
- uriInfo.getStartEntitySet(),
- uriInfo.getKeyPredicates(),
- uriInfo.getFunctionImport(),
- mapFunctionParameters(uriInfo.getFunctionImportParameters()),
- uriInfo.getNavigationSegments());
-
- if (!appliesFilter(data, uriInfo.getFilter())) {
- throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
- }
-
- final EdmEntitySet entitySet = uriInfo.getTargetEntitySet();
- final EdmEntityType entityType = entitySet.getEntityType();
- final EntityProviderReadProperties properties = EntityProviderReadProperties.init()
- .mergeSemantic(merge)
- .addTypeMappings(getStructuralTypeTypeMap(data, entityType))
- .build();
- final ODataEntry entryValues = parseEntry(entitySet, content, requestContentType, properties);
-
- setStructuralTypeValuesFromMap(data, entityType, entryValues.getProperties(), merge);
-
- return ODataResponse.newBuilder().eTag(constructETag(entitySet, data)).build();
- }
-
- @Override
- public ODataResponse readEntityLink(final GetEntityLinkUriInfo uriInfo, final String contentType)
- throws ODataException {
- final Object data = retrieveData(
- uriInfo.getStartEntitySet(),
- uriInfo.getKeyPredicates(),
- uriInfo.getFunctionImport(),
- mapFunctionParameters(uriInfo.getFunctionImportParameters()),
- uriInfo.getNavigationSegments());
-
- // if (!appliesFilter(data, uriInfo.getFilter()))
- if (data == null) {
- throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
- }
-
- final EdmEntitySet entitySet = uriInfo.getTargetEntitySet();
-
- Map<String, Object> values = new HashMap<String, Object>();
- for (final EdmProperty property : entitySet.getEntityType().getKeyProperties()) {
- values.put(property.getName(), valueAccess.getPropertyValue(data, property));
- }
-
- ODataContext context = getContext();
- final EntityProviderWriteProperties entryProperties = EntityProviderWriteProperties
- .serviceRoot(context.getPathInfo().getServiceRoot())
- .build();
-
- final int timingHandle = context.startRuntimeMeasurement("EntityProvider", "writeLink");
-
- final ODataResponse response = EntityProvider.writeLink(contentType, entitySet, values, entryProperties);
-
- context.stopRuntimeMeasurement(timingHandle);
-
- return ODataResponse.fromResponse(response).build();
- }
-
- @Override
- public ODataResponse existsEntityLink(final GetEntityLinkCountUriInfo uriInfo, final String contentType)
- throws ODataException {
- return existsEntity((GetEntityCountUriInfo) uriInfo, contentType);
- }
-
- @Override
- public ODataResponse deleteEntityLink(final DeleteUriInfo uriInfo, final String contentType) throws ODataException {
- final List<NavigationSegment> navigationSegments = uriInfo.getNavigationSegments();
- final List<NavigationSegment> previousSegments = navigationSegments.subList(0, navigationSegments.size() - 1);
-
- final Object sourceData = retrieveData(
- uriInfo.getStartEntitySet(),
- uriInfo.getKeyPredicates(),
- uriInfo.getFunctionImport(),
- mapFunctionParameters(uriInfo.getFunctionImportParameters()),
- previousSegments);
-
- final EdmEntitySet entitySet = previousSegments.isEmpty() ?
- uriInfo.getStartEntitySet() : previousSegments.get(previousSegments.size() - 1).getEntitySet();
- final EdmEntitySet targetEntitySet = uriInfo.getTargetEntitySet();
- final Map<String, Object> keys = mapKey(uriInfo.getTargetKeyPredicates());
-
- final Object targetData = dataSource.readRelatedData(entitySet, sourceData, targetEntitySet, keys);
-
- // if (!appliesFilter(targetData, uriInfo.getFilter()))
- if (targetData == null) {
- throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
- }
-
- dataSource.deleteRelation(entitySet, sourceData, targetEntitySet, keys);
-
- return ODataResponse.newBuilder().build();
- }
-
- @Override
- public ODataResponse createEntityLink(final PostUriInfo uriInfo, final InputStream content,
- final String requestContentType, final String contentType) throws ODataException {
- final List<NavigationSegment> navigationSegments = uriInfo.getNavigationSegments();
- final List<NavigationSegment> previousSegments = navigationSegments.subList(0, navigationSegments.size() - 1);
-
- final Object sourceData = retrieveData(
- uriInfo.getStartEntitySet(),
- uriInfo.getKeyPredicates(),
- uriInfo.getFunctionImport(),
- mapFunctionParameters(uriInfo.getFunctionImportParameters()),
- previousSegments);
-
- final EdmEntitySet entitySet = previousSegments.isEmpty() ?
- uriInfo.getStartEntitySet() : previousSegments.get(previousSegments.size() - 1).getEntitySet();
- final EdmEntitySet targetEntitySet = uriInfo.getTargetEntitySet();
-
- final Map<String, Object> targetKeys = parseLink(targetEntitySet, content, requestContentType);
-
- dataSource.writeRelation(entitySet, sourceData, targetEntitySet, targetKeys);
-
- return ODataResponse.newBuilder().build();
- }
-
- @Override
- public ODataResponse updateEntityLink(final PutMergePatchUriInfo uriInfo, final InputStream content,
- final String requestContentType, final String contentType) throws ODataException {
- final List<NavigationSegment> navigationSegments = uriInfo.getNavigationSegments();
- final List<NavigationSegment> previousSegments = navigationSegments.subList(0, navigationSegments.size() - 1);
-
- final Object sourceData = retrieveData(
- uriInfo.getStartEntitySet(),
- uriInfo.getKeyPredicates(),
- uriInfo.getFunctionImport(),
- mapFunctionParameters(uriInfo.getFunctionImportParameters()),
- previousSegments);
-
- final EdmEntitySet entitySet = previousSegments.isEmpty() ?
- uriInfo.getStartEntitySet() : previousSegments.get(previousSegments.size() - 1).getEntitySet();
- final EdmEntitySet targetEntitySet = uriInfo.getTargetEntitySet();
- final Map<String, Object> keys = mapKey(uriInfo.getTargetKeyPredicates());
-
- final Object targetData = dataSource.readRelatedData(entitySet, sourceData, targetEntitySet, keys);
-
- if (!appliesFilter(targetData, uriInfo.getFilter())) {
- throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
- }
-
- dataSource.deleteRelation(entitySet, sourceData, targetEntitySet, keys);
-
- final Map<String, Object> newKeys = parseLink(targetEntitySet, content, requestContentType);
-
- dataSource.writeRelation(entitySet, sourceData, targetEntitySet, newKeys);
-
- return ODataResponse.newBuilder().build();
- }
-
- @Override
- public ODataResponse readEntityComplexProperty(final GetComplexPropertyUriInfo uriInfo, final String contentType)
- throws ODataException {
- Object data = retrieveData(
- uriInfo.getStartEntitySet(),
- uriInfo.getKeyPredicates(),
- uriInfo.getFunctionImport(),
- mapFunctionParameters(uriInfo.getFunctionImportParameters()),
- uriInfo.getNavigationSegments());
-
- // if (!appliesFilter(data, uriInfo.getFilter()))
- if (data == null) {
- throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
- }
-
- final List<EdmProperty> propertyPath = uriInfo.getPropertyPath();
- final EdmProperty property = propertyPath.get(propertyPath.size() - 1);
- final Object value = property.isSimple() ?
- property.getMapping() == null || property.getMapping().getMimeType() == null ?
- getPropertyValue(data, propertyPath) : getSimpleTypeValueMap(data, propertyPath) :
- getStructuralTypeValueMap(getPropertyValue(data, propertyPath), (EdmStructuralType) property.getType());
-
- ODataContext context = getContext();
- final int timingHandle = context.startRuntimeMeasurement("EntityProvider", "writeProperty");
-
- final ODataResponse response = EntityProvider.writeProperty(contentType, property, value);
-
- context.stopRuntimeMeasurement(timingHandle);
-
- return ODataResponse.fromResponse(response).eTag(constructETag(uriInfo.getTargetEntitySet(), data)).build();
- }
-
- @Override
- public ODataResponse readEntitySimpleProperty(final GetSimplePropertyUriInfo uriInfo, final String contentType)
- throws ODataException {
- return readEntityComplexProperty((GetComplexPropertyUriInfo) uriInfo, contentType);
- }
-
- @Override
- public ODataResponse readEntitySimplePropertyValue(final GetSimplePropertyUriInfo uriInfo, final String contentType)
- throws ODataException {
- Object data = retrieveData(
- uriInfo.getStartEntitySet(),
- uriInfo.getKeyPredicates(),
- uriInfo.getFunctionImport(),
- mapFunctionParameters(uriInfo.getFunctionImportParameters()),
- uriInfo.getNavigationSegments());
-
- // if (!appliesFilter(data, uriInfo.getFilter()))
- if (data == null) {
- throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
- }
-
- final List<EdmProperty> propertyPath = uriInfo.getPropertyPath();
- final EdmProperty property = propertyPath.get(propertyPath.size() - 1);
- final Object value = property.getMapping() == null || property.getMapping().getMimeType() == null ?
- getPropertyValue(data, propertyPath) : getSimpleTypeValueMap(data, propertyPath);
-
- return ODataResponse.fromResponse(EntityProvider.writePropertyValue(property, value)).eTag(
- constructETag(uriInfo.getTargetEntitySet(), data)).build();
- }
-
- @Override
- public ODataResponse deleteEntitySimplePropertyValue(final DeleteUriInfo uriInfo, final String contentType)
- throws ODataException {
- Object data = retrieveData(
- uriInfo.getStartEntitySet(),
- uriInfo.getKeyPredicates(),
- uriInfo.getFunctionImport(),
- mapFunctionParameters(uriInfo.getFunctionImportParameters()),
- uriInfo.getNavigationSegments());
-
- if (data == null) {
- throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
- }
-
- final List<EdmProperty> propertyPath = uriInfo.getPropertyPath();
- final EdmProperty property = propertyPath.get(propertyPath.size() - 1);
-
- data = getPropertyValue(data, propertyPath.subList(0, propertyPath.size() - 1));
- valueAccess.setPropertyValue(data, property, null);
- valueAccess.setMappingValue(data, property.getMapping(), null);
-
- return ODataResponse.newBuilder().build();
- }
-
- @Override
- public ODataResponse updateEntityComplexProperty(final PutMergePatchUriInfo uriInfo, final InputStream content,
- final String requestContentType, final boolean merge, final String contentType) throws ODataException {
- Object data = retrieveData(
- uriInfo.getStartEntitySet(),
- uriInfo.getKeyPredicates(),
- uriInfo.getFunctionImport(),
- mapFunctionParameters(uriInfo.getFunctionImportParameters()),
- uriInfo.getNavigationSegments());
-
- if (!appliesFilter(data, uriInfo.getFilter())) {
- throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
- }
-
- final List<EdmProperty> propertyPath = uriInfo.getPropertyPath();
- final EdmProperty property = propertyPath.get(propertyPath.size() - 1);
-
- data = getPropertyValue(data, propertyPath.subList(0, propertyPath.size() - 1));
-
- ODataContext context = getContext();
- int timingHandle = context.startRuntimeMeasurement("EntityConsumer", "readProperty");
-
- Map<String, Object> values;
- try {
- values =
- EntityProvider.readProperty(requestContentType, property, content, EntityProviderReadProperties.init()
- .mergeSemantic(merge).build());
- } catch (final EntityProviderException e) {
- throw new ODataBadRequestException(ODataBadRequestException.BODY, e);
- }
-
- context.stopRuntimeMeasurement(timingHandle);
-
- final Object value = values.get(property.getName());
- if (property.isSimple()) {
- valueAccess.setPropertyValue(data, property, value);
- } else {
- @SuppressWarnings("unchecked")
- final Map<String, Object> propertyValue = (Map<String, Object>) value;
- setStructuralTypeValuesFromMap(valueAccess.getPropertyValue(data, property),
- (EdmStructuralType) property.getType(), propertyValue, merge);
- }
-
- return ODataResponse.newBuilder().eTag(constructETag(uriInfo.getTargetEntitySet(), data)).build();
- }
-
- @Override
- public ODataResponse updateEntitySimpleProperty(final PutMergePatchUriInfo uriInfo, final InputStream content,
- final String requestContentType, final String contentType) throws ODataException {
- return updateEntityComplexProperty(uriInfo, content, requestContentType, false, contentType);
- }
-
- @Override
- public ODataResponse updateEntitySimplePropertyValue(final PutMergePatchUriInfo uriInfo, final InputStream content,
- final String requestContentType, final String contentType) throws ODataException {
- Object data = retrieveData(
- uriInfo.getStartEntitySet(),
- uriInfo.getKeyPredicates(),
- uriInfo.getFunctionImport(),
- mapFunctionParameters(uriInfo.getFunctionImportParameters()),
- uriInfo.getNavigationSegments());
-
- if (!appliesFilter(data, uriInfo.getFilter())) {
- throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
- }
-
- final List<EdmProperty> propertyPath = uriInfo.getPropertyPath();
- final EdmProperty property = propertyPath.get(propertyPath.size() - 1);
-
- data = getPropertyValue(data, propertyPath.subList(0, propertyPath.size() - 1));
-
- ODataContext context = getContext();
- int timingHandle = context.startRuntimeMeasurement("EntityConsumer", "readPropertyValue");
-
- Object value;
- try {
- value = EntityProvider.readPropertyValue(property, content);
- } catch (final EntityProviderException e) {
- throw new ODataBadRequestException(ODataBadRequestException.BODY, e);
- }
-
- context.stopRuntimeMeasurement(timingHandle);
-
- valueAccess.setPropertyValue(data, property, value);
- valueAccess.setMappingValue(data, property.getMapping(), requestContentType);
-
- return ODataResponse.newBuilder().eTag(constructETag(uriInfo.getTargetEntitySet(), data)).build();
- }
-
- @Override
- public ODataResponse readEntityMedia(final GetMediaResourceUriInfo uriInfo, final String contentType)
- throws ODataException {
- final Object data = retrieveData(
- uriInfo.getStartEntitySet(),
- uriInfo.getKeyPredicates(),
- uriInfo.getFunctionImport(),
- mapFunctionParameters(uriInfo.getFunctionImportParameters()),
- uriInfo.getNavigationSegments());
-
- if (!appliesFilter(data, uriInfo.getFilter())) {
- throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
- }
-
- final EdmEntitySet entitySet = uriInfo.getTargetEntitySet();
- final BinaryData binaryData = dataSource.readBinaryData(entitySet, data);
- if (binaryData == null) {
- throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
- }
-
- final String mimeType = binaryData.getMimeType() == null ?
- HttpContentType.APPLICATION_OCTET_STREAM : binaryData.getMimeType();
-
- return ODataResponse.fromResponse(EntityProvider.writeBinary(mimeType, binaryData.getData())).eTag(
- constructETag(entitySet, data)).build();
- }
-
- @Override
- public ODataResponse deleteEntityMedia(final DeleteUriInfo uriInfo, final String contentType) throws ODataException {
- final Object data = retrieveData(
- uriInfo.getStartEntitySet(),
- uriInfo.getKeyPredicates(),
- uriInfo.getFunctionImport(),
- mapFunctionParameters(uriInfo.getFunctionImportParameters()),
- uriInfo.getNavigationSegments());
-
- if (data == null) {
- throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
- }
-
- dataSource.writeBinaryData(uriInfo.getTargetEntitySet(), data, new BinaryData(null, null));
-
- return ODataResponse.newBuilder().build();
- }
-
- @Override
- public ODataResponse updateEntityMedia(final PutMergePatchUriInfo uriInfo, final InputStream content,
- final String requestContentType, final String contentType) throws ODataException {
- final Object data = retrieveData(
- uriInfo.getStartEntitySet(),
- uriInfo.getKeyPredicates(),
- uriInfo.getFunctionImport(),
- mapFunctionParameters(uriInfo.getFunctionImportParameters()),
- uriInfo.getNavigationSegments());
-
- if (!appliesFilter(data, uriInfo.getFilter())) {
- throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
- }
-
- ODataContext context = getContext();
- final int timingHandle = context.startRuntimeMeasurement("EntityProvider", "readBinary");
-
- final byte[] value = EntityProvider.readBinary(content);
-
- context.stopRuntimeMeasurement(timingHandle);
-
- final EdmEntitySet entitySet = uriInfo.getTargetEntitySet();
- dataSource.writeBinaryData(entitySet, data, new BinaryData(value, requestContentType));
-
- return ODataResponse.newBuilder().eTag(constructETag(entitySet, data)).build();
- }
-
- @Override
- public ODataResponse executeFunctionImport(final GetFunctionImportUriInfo uriInfo, final String contentType)
- throws ODataException {
- final EdmFunctionImport functionImport = uriInfo.getFunctionImport();
- final EdmType type = functionImport.getReturnType().getType();
-
- final Object data = dataSource.readData(
- functionImport,
- mapFunctionParameters(uriInfo.getFunctionImportParameters()),
- null);
-
- if (data == null) {
- throw new ODataNotFoundException(ODataHttpException.COMMON);
- }
-
- Object value;
- if (type.getKind() == EdmTypeKind.SIMPLE) {
- value = type == EdmSimpleTypeKind.Binary.getEdmSimpleTypeInstance() ?
- ((BinaryData) data).getData() : data;
- } else if (functionImport.getReturnType().getMultiplicity() == EdmMultiplicity.MANY) {
- List<Map<String, Object>> values = new ArrayList<Map<String, Object>>();
- for (final Object typeData : (List<?>) data) {
- values.add(getStructuralTypeValueMap(typeData, (EdmStructuralType) type));
- }
- value = values;
- } else {
- value = getStructuralTypeValueMap(data, (EdmStructuralType) type);
- }
-
- ODataContext context = getContext();
-
- final EntityProviderWriteProperties entryProperties = EntityProviderWriteProperties
- .serviceRoot(context.getPathInfo().getServiceRoot()).build();
-
- final int timingHandle = context.startRuntimeMeasurement("EntityProvider", "writeFunctionImport");
-
- final ODataResponse response =
- EntityProvider.writeFunctionImport(contentType, functionImport, value, entryProperties);
-
- context.stopRuntimeMeasurement(timingHandle);
-
- return ODataResponse.fromResponse(response).build();
- }
-
- @Override
- public ODataResponse executeFunctionImportValue(final GetFunctionImportUriInfo uriInfo, final String contentType)
- throws ODataException {
- final EdmFunctionImport functionImport = uriInfo.getFunctionImport();
- final EdmSimpleType type = (EdmSimpleType) functionImport.getReturnType().getType();
-
- final Object data = dataSource.readData(
- functionImport,
- mapFunctionParameters(uriInfo.getFunctionImportParameters()),
- null);
-
- if (data == null) {
- throw new ODataNotFoundException(ODataHttpException.COMMON);
- }
-
- ODataResponse response;
- if (type == EdmSimpleTypeKind.Binary.getEdmSimpleTypeInstance()) {
- response = EntityProvider.writeBinary(((BinaryData) data).getMimeType(), ((BinaryData) data).getData());
- } else {
- final String value = type.valueToString(data, EdmLiteralKind.DEFAULT, null);
- response = EntityProvider.writeText(value == null ? "" : value);
- }
- return ODataResponse.fromResponse(response).build();
- }
-
- private static Map<String, Object> mapKey(final List<KeyPredicate> keys) throws EdmException {
- Map<String, Object> keyMap = new HashMap<String, Object>();
- for (final KeyPredicate key : keys) {
- final EdmProperty property = key.getProperty();
- final EdmSimpleType type = (EdmSimpleType) property.getType();
- keyMap.put(property.getName(), type.valueOfString(key.getLiteral(), EdmLiteralKind.DEFAULT, property.getFacets(),
- type.getDefaultType()));
- }
- return keyMap;
- }
-
- private static Map<String, Object> mapFunctionParameters(final Map<String, EdmLiteral> functionImportParameters)
- throws EdmSimpleTypeException {
- if (functionImportParameters == null) {
- return Collections.emptyMap();
- } else {
- Map<String, Object> parameterMap = new HashMap<String, Object>();
- for (final String parameterName : functionImportParameters.keySet()) {
- final EdmLiteral literal = functionImportParameters.get(parameterName);
- final EdmSimpleType type = literal.getType();
- parameterMap.put(parameterName, type.valueOfString(literal.getLiteral(), EdmLiteralKind.DEFAULT, null, type
- .getDefaultType()));
- }
- return parameterMap;
- }
- }
-
- private Object retrieveData(final EdmEntitySet startEntitySet, final List<KeyPredicate> keyPredicates,
- final EdmFunctionImport functionImport, final Map<String, Object> functionImportParameters,
- final List<NavigationSegment> navigationSegments) throws ODataException {
- Object data;
- final Map<String, Object> keys = mapKey(keyPredicates);
-
- ODataContext context = getContext();
- final int timingHandle = context.startRuntimeMeasurement(getClass().getSimpleName(), "retrieveData");
-
- data = functionImport == null ?
- keys.isEmpty() ?
- dataSource.readData(startEntitySet) : dataSource.readData(startEntitySet, keys) :
- dataSource.readData(functionImport, functionImportParameters, keys);
-
- EdmEntitySet currentEntitySet =
- functionImport == null ? startEntitySet : functionImport.getEntitySet();
- for (NavigationSegment navigationSegment : navigationSegments) {
- data = dataSource.readRelatedData(
- currentEntitySet,
- data,
- navigationSegment.getEntitySet(),
- mapKey(navigationSegment.getKeyPredicates()));
- currentEntitySet = navigationSegment.getEntitySet();
- }
-
- context.stopRuntimeMeasurement(timingHandle);
-
- return data;
- }
-
- private <T> String constructETag(final EdmEntitySet entitySet, final T data) throws ODataException {
- final EdmEntityType entityType = entitySet.getEntityType();
- String eTag = null;
- for (final String propertyName : entityType.getPropertyNames()) {
- final EdmProperty property = (EdmProperty) entityType.getProperty(propertyName);
- if (property.getFacets() != null && property.getFacets().getConcurrencyMode() == EdmConcurrencyMode.Fixed) {
- final EdmSimpleType type = (EdmSimpleType) property.getType();
- final String component = type.valueToString(valueAccess.getPropertyValue(data, property),
- EdmLiteralKind.DEFAULT, property.getFacets());
- eTag = eTag == null ? component : eTag + Edm.DELIMITER + component;
- }
- }
- return eTag == null ? null : "W/\"" + eTag + "\"";
- }
-
- private <T> Map<String, ODataCallback> getCallbacks(final T data, final EdmEntityType entityType)
- throws EdmException {
- final List<String> navigationPropertyNames = entityType.getNavigationPropertyNames();
- if (navigationPropertyNames.isEmpty()) {
- return null;
- } else {
- final WriteCallback callback = new WriteCallback(data);
- Map<String, ODataCallback> callbacks = new HashMap<String, ODataCallback>();
- for (final String name : navigationPropertyNames) {
- callbacks.put(name, callback);
- }
- return callbacks;
- }
- }
-
- private class WriteCallback implements OnWriteEntryContent, OnWriteFeedContent {
- private final Object data;
-
- private <T> WriteCallback(final T data) {
- this.data = data;
- }
-
- @Override
- public WriteFeedCallbackResult retrieveFeedResult(final WriteFeedCallbackContext context)
- throws ODataApplicationException {
- try {
- final EdmEntityType entityType =
- context.getSourceEntitySet().getRelatedEntitySet(context.getNavigationProperty()).getEntityType();
- List<Map<String, Object>> values = new ArrayList<Map<String, Object>>();
- Object relatedData = null;
- try {
- relatedData = readRelatedData(context);
- for (final Object entryData : (List<?>) relatedData) {
- values.add(getStructuralTypeValueMap(entryData, entityType));
- }
- } catch (final ODataNotFoundException e) {
- values.clear();
- }
- WriteFeedCallbackResult result = new WriteFeedCallbackResult();
- result.setFeedData(values);
- EntityProviderWriteProperties inlineProperties =
- EntityProviderWriteProperties.serviceRoot(getContext().getPathInfo().getServiceRoot()).callbacks(
- getCallbacks(relatedData, entityType)).expandSelectTree(context.getCurrentExpandSelectTreeNode())
- .selfLink(context.getSelfLink()).build();
- result.setInlineProperties(inlineProperties);
- return result;
- } catch (final ODataException e) {
- throw new ODataApplicationException(e.getLocalizedMessage(), Locale.ROOT, e);
- }
- }
-
- @Override
- public WriteEntryCallbackResult retrieveEntryResult(final WriteEntryCallbackContext context)
- throws ODataApplicationException {
- try {
- final EdmEntityType entityType =
- context.getSourceEntitySet().getRelatedEntitySet(context.getNavigationProperty()).getEntityType();
- WriteEntryCallbackResult result = new WriteEntryCallbackResult();
- Object relatedData;
- try {
- relatedData = readRelatedData(context);
- } catch (final ODataNotFoundException e) {
- relatedData = null;
- }
-
- if (relatedData == null) {
- result.setEntryData(Collections.<String, Object> emptyMap());
- } else {
- result.setEntryData(getStructuralTypeValueMap(relatedData, entityType));
-
- EntityProviderWriteProperties inlineProperties =
- EntityProviderWriteProperties.serviceRoot(getContext().getPathInfo().getServiceRoot()).callbacks(
- getCallbacks(relatedData, entityType)).expandSelectTree(context.getCurrentExpandSelectTreeNode())
- .build();
- result.setInlineProperties(inlineProperties);
- }
- return result;
- } catch (final ODataException e) {
- throw new ODataApplicationException(e.getLocalizedMessage(), Locale.ROOT, e);
- }
- }
-
- private Object readRelatedData(final WriteCallbackContext context) throws ODataException {
- final EdmEntitySet entitySet = context.getSourceEntitySet();
- return dataSource.readRelatedData(
- entitySet,
- data instanceof List ? readEntryData((List<?>) data, entitySet.getEntityType(), context
- .extractKeyFromEntryData()) : data,
- entitySet.getRelatedEntitySet(context.getNavigationProperty()),
- Collections.<String, Object> emptyMap());
- }
-
- private <T> T readEntryData(final List<T> data, final EdmEntityType entityType, final Map<String, Object> key)
- throws ODataException {
- for (final T entryData : data) {
- boolean found = true;
- for (final EdmProperty keyProperty : entityType.getKeyProperties()) {
- if (!valueAccess.getPropertyValue(entryData, keyProperty).equals(key.get(keyProperty.getName()))) {
- found = false;
- break;
- }
- }
- if (found) {
- return entryData;
- }
- }
- return null;
- }
- }
-
- private <T> ODataResponse writeEntry(final EdmEntitySet entitySet, final ExpandSelectTreeNode expandSelectTree,
- final T data, final String contentType) throws ODataException, EntityProviderException {
- final EdmEntityType entityType = entitySet.getEntityType();
- final Map<String, Object> values = getStructuralTypeValueMap(data, entityType);
-
- ODataContext context = getContext();
- EntityProviderWriteProperties writeProperties = EntityProviderWriteProperties
- .serviceRoot(context.getPathInfo().getServiceRoot())
- .expandSelectTree(expandSelectTree)
- .callbacks(getCallbacks(data, entityType))
- .build();
-
- final int timingHandle = context.startRuntimeMeasurement("EntityProvider", "writeEntry");
-
- final ODataResponse response = EntityProvider.writeEntry(contentType, entitySet, values, writeProperties);
-
- context.stopRuntimeMeasurement(timingHandle);
-
- return response;
- }
-
- private ODataEntry parseEntry(final EdmEntitySet entitySet, final InputStream content,
- final String requestContentType, final EntityProviderReadProperties properties) throws ODataBadRequestException {
- ODataContext context = getContext();
- final int timingHandle = context.startRuntimeMeasurement("EntityConsumer", "readEntry");
-
- ODataEntry entryValues;
- try {
- entryValues = EntityProvider.readEntry(requestContentType, entitySet, content, properties);
- } catch (final EntityProviderException e) {
- throw new ODataBadRequestException(ODataBadRequestException.BODY, e);
- }
-
- context.stopRuntimeMeasurement(timingHandle);
-
- return entryValues;
- }
-
- private Map<String, Object> parseLink(final EdmEntitySet entitySet, final InputStream content,
- final String contentType) throws ODataException {
- ODataContext context = getContext();
- final int timingHandle = context.startRuntimeMeasurement("EntityProvider", "readLink");
-
- final String uriString = EntityProvider.readLink(contentType, entitySet, content);
-
- context.stopRuntimeMeasurement(timingHandle);
-
- final Map<String, Object> targetKeys = parseLinkUri(entitySet, uriString);
- if (targetKeys == null) {
- throw new ODataBadRequestException(ODataBadRequestException.BODY);
- }
- return targetKeys;
- }
-
- private Map<String, Object> parseLinkUri(final EdmEntitySet targetEntitySet, final String uriString)
- throws EdmException {
- ODataContext context = getContext();
- final int timingHandle = context.startRuntimeMeasurement("UriParser", "getKeyPredicatesFromEntityLink");
-
- List<KeyPredicate> key = null;
- try {
- key = UriParser.getKeyPredicatesFromEntityLink(targetEntitySet, uriString,
- context.getPathInfo().getServiceRoot());
- } catch (ODataException e) {
- // We don't understand the link target. This could also be seen as an error.
- }
-
- context.stopRuntimeMeasurement(timingHandle);
-
- return key == null ? null : mapKey(key);
- }
-
- private <T> void createInlinedEntities(final EdmEntitySet entitySet, final T data, final ODataEntry entryValues)
- throws ODataException {
- final EdmEntityType entityType = entitySet.getEntityType();
- for (final String navigationPropertyName : entityType.getNavigationPropertyNames()) {
-
- final EdmNavigationProperty navigationProperty =
- (EdmNavigationProperty) entityType.getProperty(navigationPropertyName);
- final EdmEntitySet relatedEntitySet = entitySet.getRelatedEntitySet(navigationProperty);
- final EdmEntityType relatedEntityType = relatedEntitySet.getEntityType();
-
- final Object relatedValue = entryValues.getProperties().get(navigationPropertyName);
- if (relatedValue == null) {
- for (final String uriString : entryValues.getMetadata().getAssociationUris(navigationPropertyName)) {
- final Map<String, Object> key = parseLinkUri(relatedEntitySet, uriString);
- if (key != null) {
- dataSource.writeRelation(entitySet, data, relatedEntitySet, key);
- }
- }
-
- } else {
- if (relatedValue instanceof ODataFeed) {
- ODataFeed feed = (ODataFeed) relatedValue;
- final List<ODataEntry> relatedValueList = feed.getEntries();
- for (final ODataEntry relatedValues : relatedValueList) {
- Object relatedData = dataSource.newDataObject(relatedEntitySet);
- setStructuralTypeValuesFromMap(relatedData, relatedEntityType, relatedValues.getProperties(), false);
- dataSource.createData(relatedEntitySet, relatedData);
- dataSource.writeRelation(entitySet, data, relatedEntitySet, getStructuralTypeValueMap(relatedData,
- relatedEntityType));
- createInlinedEntities(relatedEntitySet, relatedData, relatedValues);
- }
- } else if (relatedValue instanceof ODataEntry) {
- final ODataEntry relatedValueEntry = (ODataEntry) relatedValue;
- Object relatedData = dataSource.newDataObject(relatedEntitySet);
- setStructuralTypeValuesFromMap(relatedData, relatedEntityType, relatedValueEntry.getProperties(), false);
- dataSource.createData(relatedEntitySet, relatedData);
- dataSource.writeRelation(entitySet, data, relatedEntitySet, getStructuralTypeValueMap(relatedData,
- relatedEntityType));
- createInlinedEntities(relatedEntitySet, relatedData, relatedValueEntry);
- } else {
- throw new ODataException("Unexpected class for a related value: " + relatedValue.getClass().getSimpleName());
- }
-
- }
- }
- }
-
- private <T> Integer applySystemQueryOptions(final EdmEntitySet entitySet, final List<T> data,
- final FilterExpression filter, final InlineCount inlineCount, final OrderByExpression orderBy,
- final String skipToken, final Integer skip, final Integer top) throws ODataException {
- ODataContext context = getContext();
- final int timingHandle = context.startRuntimeMeasurement(getClass().getSimpleName(), "applySystemQueryOptions");
-
- if (filter != null) {
- // Remove all elements the filter does not apply for.
- // A for-each loop would not work with "remove", see Java documentation.
- for (Iterator<T> iterator = data.iterator(); iterator.hasNext();) {
- if (!appliesFilter(iterator.next(), filter)) {
- iterator.remove();
- }
- }
- }
-
- final Integer count = inlineCount == InlineCount.ALLPAGES ? data.size() : null;
-
- if (orderBy != null) {
- sort(data, orderBy);
- } else if (skipToken != null || skip != null || top != null) {
- sortInDefaultOrder(entitySet, data);
- }
-
- if (skipToken != null) {
- while (!data.isEmpty() && !getSkipToken(entitySet, data.get(0)).equals(skipToken)) {
- data.remove(0);
- }
- }
-
- if (skip != null) {
- if (skip >= data.size()) {
- data.clear();
- } else {
- for (int i = 0; i < skip; i++) {
- data.remove(0);
- }
- }
- }
-
- if (top != null) {
- while (data.size() > top) {
- data.remove(top.intValue());
- }
- }
-
- context.stopRuntimeMeasurement(timingHandle);
-
- return count;
- }
-
- private <T> void sort(final List<T> data, final OrderByExpression orderBy) {
- Collections.sort(data, new Comparator<T>() {
- @Override
- public int compare(final T entity1, final T entity2) {
- try {
- int result = 0;
- for (final OrderExpression expression : orderBy.getOrders()) {
- result = evaluateExpression(entity1, expression.getExpression()).compareTo(
- evaluateExpression(entity2, expression.getExpression()));
- if (expression.getSortOrder() == SortOrder.desc) {
- result = -result;
- }
- if (result != 0) {
- break;
- }
- }
- return result;
- } catch (final ODataException e) {
- return 0;
- }
- }
- });
- }
-
- private <T> void sortInDefaultOrder(final EdmEntitySet entitySet, final List<T> data) {
- Collections.sort(data, new Comparator<T>() {
- @Override
- public int compare(final T entity1, final T entity2) {
- try {
- return getSkipToken(entitySet, entity1).compareTo(getSkipToken(entitySet, entity2));
- } catch (final ODataException e) {
- return 0;
- }
- }
- });
- }
-
- private <T> boolean appliesFilter(final T data, final FilterExpression filter) throws ODataException {
- ODataContext context = getContext();
- final int timingHandle = context.startRuntimeMeasurement(getClass().getSimpleName(), "appliesFilter");
-
- try {
- return data != null && (filter == null || evaluateExpression(data, filter.getExpression()).equals("true"));
- } catch (final RuntimeException e) {
- return false;
- } finally {
- context.stopRuntimeMeasurement(timingHandle);
- }
- }
-
- private <T> String evaluateExpression(final T data, final CommonExpression expression) throws ODataException {
- switch (expression.getKind()) {
- case UNARY:
- final UnaryExpression unaryExpression = (UnaryExpression) expression;
- final String operand = evaluateExpression(data, unaryExpression.getOperand());
-
- switch (unaryExpression.getOperator()) {
- case NOT:
- return Boolean.toString(!Boolean.parseBoolean(operand));
- case MINUS:
- return operand.startsWith("-") ? operand.substring(1) : "-" + operand;
- default:
- throw new ODataNotImplementedException();
- }
-
- case BINARY:
- final BinaryExpression binaryExpression = (BinaryExpression) expression;
- final EdmSimpleType type = (EdmSimpleType) binaryExpression.getLeftOperand().getEdmType();
- final String left = evaluateExpression(data, binaryExpression.getLeftOperand());
- final String right = evaluateExpression(data, binaryExpression.getRightOperand());
-
- switch (binaryExpression.getOperator()) {
- case ADD:
- if (binaryExpression.getEdmType() == EdmSimpleTypeKind.Decimal.getEdmSimpleTypeInstance()
- || binaryExpression.getEdmType() == EdmSimpleTypeKind.Double.getEdmSimpleTypeInstance()
- || binaryExpression.getEdmType() == EdmSimpleTypeKind.Single.getEdmSimpleTypeInstance()) {
- return Double.toString(Double.valueOf(left) + Double.valueOf(right));
- } else {
- return Long.toString(Long.valueOf(left) + Long.valueOf(right));
- }
- case SUB:
- if (binaryExpression.getEdmType() == EdmSimpleTypeKind.Decimal.getEdmSimpleTypeInstance()
- || binaryExpression.getEdmType() == EdmSimpleTypeKind.Double.getEdmSimpleTypeInstance()
- || binaryExpression.getEdmType() == EdmSimpleTypeKind.Single.getEdmSimpleTypeInstance()) {
- return Double.toString(Double.valueOf(left) - Double.valueOf(right));
- } else {
- return Long.toString(Long.valueOf(left) - Long.valueOf(right));
- }
- case MUL:
- if (binaryExpression.getEdmType() == EdmSimpleTypeKind.Decimal.getEdmSimpleTypeInstance()
- || binaryExpression.getEdmType() == EdmSimpleTypeKind.Double.getEdmSimpleTypeInstance()
- || binaryExpression.getEdmType() == EdmSimpleTypeKind.Single.getEdmSimpleTypeInstance()) {
- return Double.toString(Double.valueOf(left) * Double.valueOf(right));
- } else {
- return Long.toString(Long.valueOf(left) * Long.valueOf(right));
- }
- case DIV:
- final String number = Double.toString(Double.valueOf(left) / Double.valueOf(right));
- return number.endsWith(".0") ? number.replace(".0", "") : number;
- case MODULO:
- if (binaryExpression.getEdmType() == EdmSimpleTypeKind.Decimal.getEdmSimpleTypeInstance()
- || binaryExpression.getEdmType() == EdmSimpleTypeKind.Double.getEdmSimpleTypeInstance()
- || binaryExpression.getEdmType() == EdmSimpleTypeKind.Single.getEdmSimpleTypeInstance()) {
- return Double.toString(Double.valueOf(left) % Double.valueOf(right));
- } else {
- return Long.toString(Long.valueOf(left) % Long.valueOf(right));
- }
- case AND:
- return Boolean.toString(left.equals("true") && right.equals("true"));
- case OR:
- return Boolean.toString(left.equals("true") || right.equals("true"));
- case EQ:
- return Boolean.toString(left.equals(right));
- case NE:
- return Boolean.toString(!left.equals(right));
- case LT:
- if (type == EdmSimpleTypeKind.String.getEdmSimpleTypeInstance()
- || type == EdmSimpleTypeKind.DateTime.getEdmSimpleTypeInstance()
- || type == EdmSimpleTypeKind.DateTimeOffset.getEdmSimpleTypeInstance()
- || type == EdmSimpleTypeKind.Guid.getEdmSimpleTypeInstance()
- || type == EdmSimpleTypeKind.Time.getEdmSimpleTypeInstance()) {
- return Boolean.toString(left.compareTo(right) < 0);
- } else {
- return Boolean.toString(Double.valueOf(left) < Double.valueOf(right));
- }
- case LE:
- if (type == EdmSimpleTypeKind.String.getEdmSimpleTypeInstance()
- || type == EdmSimpleTypeKind.DateTime.getEdmSimpleTypeInstance()
- || type == EdmSimpleTypeKind.DateTimeOffset.getEdmSimpleTypeInstance()
- || type == EdmSimpleTypeKind.Guid.getEdmSimpleTypeInstance()
- || type == EdmSimpleTypeKind.Time.getEdmSimpleTypeInstance()) {
- return Boolean.toString(left.compareTo(right) <= 0);
- } else {
- return Boolean.toString(Double.valueOf(left) <= Double.valueOf(right));
- }
- case GT:
- if (type == EdmSimpleTypeKind.String.getEdmSimpleTypeInstance()
- || type == EdmSimpleTypeKind.DateTime.getEdmSimpleTypeInstance()
- || type == EdmSimpleTypeKind.DateTimeOffset.getEdmSimpleTypeInstance()
- || type == EdmSimpleTypeKind.Guid.getEdmSimpleTypeInstance()
- || type == EdmSimpleTypeKind.Time.getEdmSimpleTypeInstance()) {
- return Boolean.toString(left.compareTo(right) > 0);
- } else {
- return Boolean.toString(Double.valueOf(left) > Double.valueOf(right));
- }
- case GE:
- if (type == EdmSimpleTypeKind.String.getEdmSimpleTypeInstance()
- || type == EdmSimpleTypeKind.DateTime.getEdmSimpleTypeInstance()
- || type == EdmSimpleTypeKind.DateTimeOffset.getEdmSimpleTypeInstance()
- || type == EdmSimpleTypeKind.Guid.getEdmSimpleTypeInstance()
- || type == EdmSimpleTypeKind.Time.getEdmSimpleTypeInstance()) {
- return Boolean.toString(left.compareTo(right) >= 0);
- } else {
- return Boolean.toString(Double.valueOf(left) >= Double.valueOf(right));
- }
- case PROPERTY_ACCESS:
- throw new ODataNotImplementedException();
- default:
- throw new ODataNotImplementedException();
- }
-
- case PROPERTY:
- final EdmProperty property = (EdmProperty) ((PropertyExpression) expression).getEdmProperty();
- final EdmSimpleType propertyType = (EdmSimpleType) property.getType();
- return propertyType.valueToString(valueAccess.getPropertyValue(data, property), EdmLiteralKind.DEFAULT,
- property.getFacets());
-
- case MEMBER:
- final MemberExpression memberExpression = (MemberExpression) expression;
- final PropertyExpression propertyExpression = (PropertyExpression) memberExpression.getProperty();
- final EdmProperty memberProperty = (EdmProperty) propertyExpression.getEdmProperty();
- final EdmSimpleType memberType = (EdmSimpleType) memberExpression.getEdmType();
- List<EdmProperty> propertyPath = new ArrayList<EdmProperty>();
- CommonExpression currentExpression = memberExpression;
- while (currentExpression != null) {
- final PropertyExpression currentPropertyExpression =
- (PropertyExpression) (currentExpression.getKind() == ExpressionKind.MEMBER ?
- ((MemberExpression) currentExpression).getProperty() : currentExpression);
- final EdmTyped currentProperty = currentPropertyExpression.getEdmProperty();
- final EdmTypeKind kind = currentProperty.getType().getKind();
- if (kind == EdmTypeKind.SIMPLE || kind == EdmTypeKind.COMPLEX) {
- propertyPath.add(0, (EdmProperty) currentProperty);
- } else {
- throw new ODataNotImplementedException();
- }
- currentExpression =
- currentExpression.getKind() == ExpressionKind.MEMBER ? ((MemberExpression) currentExpression).getPath()
- : null;
- }
- return memberType.valueToString(getPropertyValue(data, propertyPath), EdmLiteralKind.DEFAULT, memberProperty
- .getFacets());
-
- case LITERAL:
- final LiteralExpression literal = (LiteralExpression) expression;
- final EdmSimpleType literalType = (EdmSimpleType) literal.getEdmType();
- return literalType.valueToString(literalType.valueOfString(literal.getUriLiteral(), EdmLiteralKind.URI, null,
- literalType.getDefaultType()),
- EdmLiteralKind.DEFAULT, null);
-
- case METHOD:
- final MethodExpression methodExpression = (MethodExpression) expression;
- final String first = evaluateExpression(data, methodExpression.getParameters().get(0));
- final String second = methodExpression.getParameterCount() > 1 ?
- evaluateExpression(data, methodExpression.getParameters().get(1)) : null;
- final String third = methodExpression.getParameterCount() > 2 ?
- evaluateExpression(data, methodExpression.getParameters().get(2)) : null;
-
- switch (methodExpression.getMethod()) {
- case ENDSWITH:
- return Boolean.toString(first.endsWith(second));
- case INDEXOF:
- return Integer.toString(first.indexOf(second));
- case STARTSWITH:
- return Boolean.toString(first.startsWith(second));
- case TOLOWER:
- return first.toLowerCase(Locale.ROOT);
- case TOUPPER:
- return first.toUpperCase(Locale.ROOT);
- case TRIM:
- return first.trim();
- case SUBSTRING:
- final int offset = Integer.parseInt(second);
- return first.substring(offset, offset + Integer.parseInt(third));
- case SUBSTRINGOF:
- return Boolean.toString(second.contains(first));
- case CONCAT:
- return first + second;
- case LENGTH:
- return Integer.toString(first.length());
- case YEAR:
- return String.valueOf(Integer.parseInt(first.substring(0, 4)));
- case MONTH:
- return String.valueOf(Integer.parseInt(first.substring(5, 7)));
- case DAY:
- return String.valueOf(Integer.parseInt(first.substring(8, 10)));
- case HOUR:
- return String.valueOf(Integer.parseInt(first.substring(11, 13)));
- case MINUTE:
- return String.valueOf(Integer.parseInt(first.substring(14, 16)));
- case SECOND:
- return String.valueOf(Integer.parseInt(first.substring(17, 19)));
- case ROUND:
- return Long.toString(Math.round(Double.valueOf(first)));
- case FLOOR:
- return Long.toString(Math.round(Math.floor(Double.valueOf(first))));
- case CEILING:
- return Long.toString(Math.round(Math.ceil(Double.valueOf(first))));
- default:
- throw new ODataNotImplementedException();
- }
-
- default:
- throw new ODataNotImplementedException();
- }
- }
-
- private <T> String getSkipToken(final EdmEntitySet entitySet, final T data) throws ODataException {
- String skipToken = "";
- for (final EdmProperty property : entitySet.getEntityType().getKeyProperties()) {
- final EdmSimpleType type = (EdmSimpleType) property.getType();
- skipToken = skipToken.concat(type.valueToString(valueAccess.getPropertyValue(data, property),
- EdmLiteralKind.DEFAULT, property.getFacets()));
- }
- return skipToken;
- }
-
- private <T> Object getPropertyValue(final T data, final List<EdmProperty> propertyPath) throws ODataException {
- Object dataObject = data;
- for (final EdmProperty property : propertyPath) {
- if (dataObject != null) {
- dataObject = valueAccess.getPropertyValue(dataObject, property);
- }
- }
- return dataObject;
- }
-
- private void handleMimeType(Object data, EdmMapping mapping, Map<String, Object> valueMap)
- throws ODataException {
- final String mimeTypeName = mapping.getMimeType();
- if (mimeTypeName != null) {
- Object value = valueAccess.getMappingValue(data, mapping);
- valueMap.put(mimeTypeName, value);
- if (mapping.getMediaResourceMimeTypeKey() != null) {
- valueMap.put(mapping.getMediaResourceMimeTypeKey(), value);
- }
- }
- }
-
- private <T> Map<String, Object> getSimpleTypeValueMap(final T data, final List<EdmProperty> propertyPath)
- throws ODataException {
- final EdmProperty property = propertyPath.get(propertyPath.size() - 1);
- Map<String, Object> valueWithMimeType = new HashMap<String, Object>();
- valueWithMimeType.put(property.getName(), getPropertyValue(data, propertyPath));
-
- handleMimeType(data, property.getMapping(), valueWithMimeType);
-
- return valueWithMimeType;
- }
-
- private <T> Map<String, Object> getStructuralTypeValueMap(final T data, final EdmStructuralType type)
- throws ODataException {
- ODataContext context = getContext();
- final int timingHandle = context.startRuntimeMeasurement(getClass().getSimpleName(), "getStructuralTypeValueMap");
-
- Map<String, Object> valueMap = new HashMap<String, Object>();
-
- EdmMapping mapping = type.getMapping();
- if (mapping != null) {
- handleMimeType(data, mapping, valueMap);
- }
-
- for (final String propertyName : type.getPropertyNames()) {
- final EdmProperty property = (EdmProperty) type.getProperty(propertyName);
- final Object value = valueAccess.getPropertyValue(data, property);
-
- if (property.isSimple()) {
- if (property.getMapping() == null || property.getMapping().getMimeType() == null) {
- valueMap.put(propertyName, value);
- } else {
- // TODO: enable MIME type mapping outside the current subtree
- valueMap.put(propertyName, getSimpleTypeValueMap(data, Arrays.asList(property)));
- }
- } else {
- valueMap.put(propertyName, getStructuralTypeValueMap(value, (EdmStructuralType) property.getType()));
- }
- }
-
- context.stopRuntimeMeasurement(timingHandle);
-
- return valueMap;
- }
-
- private <T> Map<String, Object> getStructuralTypeTypeMap(final T data, final EdmStructuralType type)
- throws ODataException {
- ODataContext context = getContext();
- final int timingHandle = context.startRuntimeMeasurement(getClass().getSimpleName(), "getStructuralTypeTypeMap");
-
- Map<String, Object> typeMap = new HashMap<String, Object>();
- for (final String propertyName : type.getPropertyNames()) {
- final EdmProperty property = (EdmProperty) type.getProperty(propertyName);
- if (property.isSimple()) {
- typeMap.put(propertyName, valueAccess.getPropertyType(data, property));
- } else {
- typeMap.put(propertyName, getStructuralTypeTypeMap(valueAccess.getPropertyValue(data, property),
- (EdmStructuralType) property.getType()));
- }
- }
-
- context.stopRuntimeMeasurement(timingHandle);
-
- return typeMap;
- }
-
- private <T> void setStructuralTypeValuesFromMap(final T data, final EdmStructuralType type,
- final Map<String, Object> valueMap, final boolean merge) throws ODataException {
- ODataContext context = getContext();
- final int timingHandle =
- context.startRuntimeMeasurement(getClass().getSimpleName(), "setStructuralTypeValuesFromMap");
-
- for (final String propertyName : type.getPropertyNames()) {
- final EdmProperty property = (EdmProperty) type.getProperty(propertyName);
- if (type instanceof EdmEntityType && ((EdmEntityType) type).getKeyProperties().contains(property)) {
- Object v = valueAccess.getPropertyValue(data, property);
- if(v != null) {
- continue;
- }
- }
-
- if (!merge || valueMap != null && valueMap.containsKey(propertyName)) {
- final Object value = valueMap == null ? null : valueMap.get(propertyName);
- if (property.isSimple()) {
- valueAccess.setPropertyValue(data, property, value);
- } else {
- @SuppressWarnings("unchecked")
- final Map<String, Object> values = (Map<String, Object>) value;
- setStructuralTypeValuesFromMap(valueAccess.getPropertyValue(data, property),
- (EdmStructuralType) property.getType(), values, merge);
- }
- }
- }
-
- context.stopRuntimeMeasurement(timingHandle);
- }
-
- @Override
- public ODataResponse executeBatch(final BatchHandler handler, final String contentType, final InputStream content)
- throws ODataException {
- ODataResponse batchResponse;
- List<BatchResponsePart> batchResponseParts = new ArrayList<BatchResponsePart>();
- PathInfo pathInfo = getContext().getPathInfo();
- EntityProviderBatchProperties batchProperties = EntityProviderBatchProperties.init().pathInfo(pathInfo).build();
- List<BatchRequestPart> batchParts = EntityProvider.parseBatchRequest(contentType, content, batchProperties);
- for (BatchRequestPart batchPart : batchParts) {
- batchResponseParts.add(handler.handleBatchPart(batchPart));
- }
- batchResponse = EntityProvider.writeBatchResponse(batchResponseParts);
- return batchResponse;
- }
-
- @Override
- public BatchResponsePart executeChangeSet(final BatchHandler handler, final List<ODataRequest> requests)
- throws ODataException {
- List<ODataResponse> responses = new ArrayList<ODataResponse>();
- for (ODataRequest request : requests) {
- ODataResponse response = handler.handleRequest(request);
- if (response.getStatus().getStatusCode() >= HttpStatusCodes.BAD_REQUEST.getStatusCode()) {
- // Rollback
- List<ODataResponse> errorResponses = new ArrayList<ODataResponse>(1);
- errorResponses.add(response);
- return BatchResponsePart.responses(errorResponses).changeSet(false).build();
- }
- responses.add(response);
- }
- return BatchResponsePart.responses(responses).changeSet(true).build();
- }
-}
[31/52] git commit: Added missing EdmConcurrencyControl annotation
Posted by mi...@apache.org.
Added missing EdmConcurrencyControl annotation
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/aeca3dfd
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/aeca3dfd
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/aeca3dfd
Branch: refs/heads/master
Commit: aeca3dfd1c5ce4f3d279160e39bc71a2f0d2a401
Parents: 4d80947
Author: Michael Bolz <mi...@apache.org>
Authored: Fri Nov 29 14:47:36 2013 +0100
Committer: Michael Bolz <mi...@apache.org>
Committed: Fri Nov 29 14:47:36 2013 +0100
----------------------------------------------------------------------
.../annotation/edm/EdmConcurrencyControl.java | 36 ++++++++++++++++++++
1 file changed, 36 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/aeca3dfd/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmConcurrencyControl.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmConcurrencyControl.java b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmConcurrencyControl.java
new file mode 100644
index 0000000..a94e369
--- /dev/null
+++ b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmConcurrencyControl.java
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * 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.api.annotation.edm;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Related to <code>ConcurrencyMode</code> in OData specification.
+ * If a property is annotated with {@link EdmConcurrencyControl}
+ * this is equivalent with <code>ConcurrencyMode = FIXED</code>.
+ * Default of a property not annotated with {@link EdmConcurrencyControl}
+ * this is equivalent with <code>ConcurrencyMode = NONE</code>.
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.ANNOTATION_TYPE)
+public @interface EdmConcurrencyControl {
+}
[30/52] git commit: Refactored EdmNavigationProperty annotation
Posted by mi...@apache.org.
Refactored EdmNavigationProperty annotation
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/4d80947e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/4d80947e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/4d80947e
Branch: refs/heads/master
Commit: 4d80947e511a900383315c08c2b7ae9826470840
Parents: f97d37f
Author: Michael Bolz <mi...@apache.org>
Authored: Thu Nov 21 09:35:49 2013 +0100
Committer: Michael Bolz <mi...@apache.org>
Committed: Thu Nov 21 10:50:25 2013 +0100
----------------------------------------------------------------------
.../annotation/data/AnnotationInMemoryDs.java | 120 +++++-----
.../annotation/data/AnnotationValueAccess.java | 38 +---
.../odata2/core/annotation/data/DataStore.java | 63 +++---
.../annotation/edm/AnnotationEdmProvider.java | 127 ++++++-----
.../core/annotation/edm/AnnotationHelper.java | 218 +++++++++----------
.../annotation/processor/ListsProcessor.java | 7 +-
.../data/AnnotationsInMemoryDsTest.java | 79 ++++---
.../edm/AnnotationEdmProviderTest.java | 20 +-
.../odata2/core/annotation/model/Building.java | 19 +-
.../odata2/core/annotation/model/Employee.java | 38 ++--
.../odata2/core/annotation/model/Manager.java | 10 +-
.../odata2/core/annotation/model/Room.java | 13 +-
.../odata2/core/annotation/model/Team.java | 12 +-
.../edm-annotation-webref/pom.xml | 10 -
.../odata2/ref/annotation/model/Building.java | 10 +-
.../odata2/ref/annotation/model/Employee.java | 35 +--
.../odata2/ref/annotation/model/Manager.java | 5 +-
.../odata2/ref/annotation/model/Room.java | 12 +-
.../odata2/ref/annotation/model/Team.java | 11 +-
.../processor/AnnotationPocServiceFactory.java | 36 ++-
.../src/main/webapp/index.jsp | 26 ++-
.../annotation/edm/EdmNavigationProperty.java | 11 +-
.../api/annotation/edm/NavigationEnd.java | 35 ---
23 files changed, 453 insertions(+), 502 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/4d80947e/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationInMemoryDs.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationInMemoryDs.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationInMemoryDs.java
index 6414264..d7c7f59 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationInMemoryDs.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationInMemoryDs.java
@@ -21,7 +21,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceContent;
import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceMimeType;
import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
@@ -46,7 +45,7 @@ public class AnnotationInMemoryDs implements ListsDataSource {
List<Class<?>> foundClasses = ClassHelper.loadClasses(packageToScan, new ClassHelper.ClassValidator() {
@Override
public boolean isClassValid(Class<?> c) {
- return null != c.getAnnotation(EdmEntityType.class);
+ return null != c.getAnnotation(org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet.class);
}
});
@@ -58,8 +57,9 @@ public class AnnotationInMemoryDs implements ListsDataSource {
for (Class<?> clz : foundClasses) {
DataStore<Object> dhs = (DataStore<Object>) DataStore.createInMemory(clz);
- String entityTypeName = ANNOTATION_HELPER.extractEntityTypeName(clz);
- dataStores.put(entityTypeName, dhs);
+ org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet entitySet =
+ clz.getAnnotation(org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet.class);
+ dataStores.put(entitySet.name(), dhs);
}
}
@@ -69,11 +69,11 @@ public class AnnotationInMemoryDs implements ListsDataSource {
@Override
public List<?> readData(EdmEntitySet entitySet) throws ODataNotImplementedException,
- ODataNotFoundException, EdmException, ODataApplicationException {
+ ODataNotFoundException, EdmException, ODataApplicationException {
DataStore<Object> holder = getDataStore(entitySet);
if (holder != null) {
- return new ArrayList(holder.read());
+ return new ArrayList<Object>(holder.read());
}
throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
@@ -81,7 +81,7 @@ public class AnnotationInMemoryDs implements ListsDataSource {
@Override
public Object readData(EdmEntitySet entitySet, Map<String, Object> keys)
- throws ODataNotFoundException, EdmException, ODataApplicationException {
+ throws ODataNotFoundException, EdmException, ODataApplicationException {
DataStore<Object> store = getDataStore(entitySet);
if (store != null) {
@@ -99,71 +99,72 @@ public class AnnotationInMemoryDs implements ListsDataSource {
@Override
public Object readData(EdmFunctionImport function, Map<String, Object> parameters, Map<String, Object> keys)
- throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException {
+ throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException {
throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
}
@Override
public Object readRelatedData(EdmEntitySet sourceEntitySet, Object sourceData, EdmEntitySet targetEntitySet,
- Map<String, Object> targetKeys)
- throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException {
+ Map<String, Object> targetKeys)
+ throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException {
- if (targetKeys.isEmpty()) {
- String sourceName = sourceEntitySet.getEntityType().getName();
- DataStore sourceStore = dataStores.get(sourceName);
+ DataStore<?> sourceStore = dataStores.get(sourceEntitySet.getName());
+ DataStore<?> targetStore = dataStores.get(targetEntitySet.getName());
- String targetName = targetEntitySet.getEntityType().getName();
- DataStore targetStore = dataStores.get(targetName);
-
- AnnotationHelper.AnnotatedNavInfo navigationInfo = extractNavigationInfo(sourceStore, targetStore);
+ Field sourceField = extractSourceField(sourceStore, targetStore);
+ if (sourceField == null) {
+ throw new ODataRuntimeException("Missing source field for related data (sourceStore='" + sourceStore
+ + "', targetStore='" + targetStore + "').");
+ }
- Field sourceFieldAtTarget = navigationInfo.getToField();
- if (sourceFieldAtTarget == null) {
- throw new ODataRuntimeException("Missing source field for related data.");
+ Object navigationInstance = getValue(sourceField, sourceData);
+ List<Object> resultData = new ArrayList<Object>();
+ for (Object targetInstance : targetStore.read()) {
+ if (navigationInstance instanceof Collection) {
+ for (Object object : (Collection<?>) navigationInstance) {
+ if (ANNOTATION_HELPER.keyMatch(targetInstance, object)) {
+ resultData.add(targetInstance);
+ }
+ }
+ } else if (ANNOTATION_HELPER.keyMatch(targetInstance, navigationInstance)) {
+ resultData.add(targetInstance);
}
+ }
- Collection targetData = targetStore.read();
- List resultData = new ArrayList();
- for (Object targetInstance : targetData) {
- Object targetNavigationInstance = getValue(sourceFieldAtTarget, targetInstance);
- if(targetNavigationInstance instanceof Collection) {
- Collection c = (Collection) targetNavigationInstance;
- for (Object object : c) {
- if (ANNOTATION_HELPER.keyMatch(sourceData, object)) {
- resultData.add(targetInstance);
- }
+ EdmNavigationProperty navProperty = sourceField.getAnnotation(EdmNavigationProperty.class);
+ if (navProperty.toMultiplicity() == EdmMultiplicity.MANY) {
+ if (targetKeys.isEmpty()) {
+ return resultData;
+ } else {
+ for (Object result : resultData) {
+ if (ANNOTATION_HELPER.keyMatch(result, targetKeys)) {
+ return result;
}
- } else if (ANNOTATION_HELPER.keyMatch(sourceData, targetNavigationInstance)) {
- resultData.add(targetInstance);
}
- }
-
- if(resultData.isEmpty()) {
return null;
- } else if(navigationInfo.getToMultiplicity() == EdmMultiplicity.ONE) {
- return resultData.get(0);
- } else {
- return resultData;
}
} else {
- throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
+ if (resultData.isEmpty()) {
+ return null;
+ }
+ return resultData.get(0);
}
}
@Override
public BinaryData readBinaryData(EdmEntitySet entitySet, Object mediaLinkEntryData)
- throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException {
+ throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException {
Object data = ANNOTATION_HELPER.getValueForField(mediaLinkEntryData, EdmMediaResourceContent.class);
Object mimeType = ANNOTATION_HELPER.getValueForField(mediaLinkEntryData, EdmMediaResourceMimeType.class);
- BinaryData db = new BinaryData((byte[])data, String.valueOf(mimeType));
+ BinaryData db = new BinaryData((byte[]) data, String.valueOf(mimeType));
return db;
}
@Override
public Object newDataObject(EdmEntitySet entitySet)
- throws ODataNotImplementedException, EdmException, ODataApplicationException {
+ throws ODataNotImplementedException, EdmException, ODataApplicationException {
DataStore<Object> dataStore = getDataStore(entitySet);
if (dataStore != null) {
@@ -175,7 +176,7 @@ public class AnnotationInMemoryDs implements ListsDataSource {
@Override
public void writeBinaryData(EdmEntitySet entitySet, Object mediaLinkEntryData, BinaryData binaryData)
- throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException {
+ throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException {
throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
}
@@ -199,7 +200,7 @@ public class AnnotationInMemoryDs implements ListsDataSource {
@Override
public void deleteData(EdmEntitySet entitySet, Map<String, Object> keys)
- throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException {
+ throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException {
DataStore<Object> dataStore = getDataStore(entitySet);
Object keyInstance = dataStore.createInstance();
ANNOTATION_HELPER.setKeyFields(keyInstance, keys);
@@ -208,7 +209,7 @@ public class AnnotationInMemoryDs implements ListsDataSource {
@Override
public void createData(EdmEntitySet entitySet, Object data)
- throws ODataNotImplementedException, EdmException, ODataApplicationException {
+ throws ODataNotImplementedException, EdmException, ODataApplicationException {
DataStore<Object> dataStore = getDataStore(entitySet);
dataStore.create(data);
@@ -216,19 +217,18 @@ public class AnnotationInMemoryDs implements ListsDataSource {
@Override
public void deleteRelation(EdmEntitySet sourceEntitySet, Object sourceData, EdmEntitySet targetEntitySet,
- Map<String, Object> targetKeys)
- throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException {
+ Map<String, Object> targetKeys)
+ throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException {
throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
}
@Override
public void writeRelation(EdmEntitySet sourceEntitySet, Object sourceData, EdmEntitySet targetEntitySet,
- Map<String, Object> targetKeys)
- throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException {
+ Map<String, Object> targetKeys)
+ throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException {
throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
}
-
/**
* Returns corresponding DataStore for EdmEntitySet or if no data store is registered an
* ODataRuntimeException is thrown.
@@ -240,9 +240,9 @@ public class AnnotationInMemoryDs implements ListsDataSource {
* @throws ODataRuntimeException if no DataStore is found
*/
private DataStore<Object> getDataStore(EdmEntitySet entitySet) throws EdmException {
- final String name = entitySet.getEntityType().getName();
+ final String name = entitySet.getName();
DataStore<Object> dataStore = dataStores.get(name);
- if(dataStore == null) {
+ if (dataStore == null) {
throw new ODataRuntimeException("No DataStore found for entity set '" + entitySet + "'.");
}
return dataStore;
@@ -257,17 +257,17 @@ public class AnnotationInMemoryDs implements ListsDataSource {
return value;
} catch (IllegalArgumentException e) {
throw new ODataRuntimeException("Error for getting value of field '"
- + field + "' at instance '" + instance + "'.", e);
+ + field + "' at instance '" + instance + "'.", e);
} catch (IllegalAccessException e) {
throw new ODataRuntimeException("Error for getting value of field '"
- + field + "' at instance '" + instance + "'.", e);
+ + field + "' at instance '" + instance + "'.", e);
}
}
- private AnnotationHelper.AnnotatedNavInfo extractNavigationInfo(DataStore sourceStore, DataStore targetStore) {
- Class sourceDataTypeClass = sourceStore.getDataTypeClass();
- Class targetDataTypeClass = targetStore.getDataTypeClass();
-
- return ANNOTATION_HELPER.getCommonNavigationInfo(sourceDataTypeClass, targetDataTypeClass);
+ private Field extractSourceField(DataStore<?> sourceStore, DataStore<?> targetStore) {
+ Class<?> sourceDataTypeClass = sourceStore.getDataTypeClass();
+ Class<?> targetDataTypeClass = targetStore.getDataTypeClass();
+
+ return ANNOTATION_HELPER.getCommonNavigationInfo(sourceDataTypeClass, targetDataTypeClass).getFromField();
}
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/4d80947e/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationValueAccess.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationValueAccess.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationValueAccess.java
index ceea74d..3408c84 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationValueAccess.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationValueAccess.java
@@ -18,23 +18,19 @@
******************************************************************************/
package org.apache.olingo.odata2.core.annotation.data;
-import java.util.Collection;
import org.apache.olingo.odata2.api.data.ValueAccess;
import org.apache.olingo.odata2.api.edm.EdmMapping;
import org.apache.olingo.odata2.api.edm.EdmProperty;
import org.apache.olingo.odata2.api.exception.ODataException;
-import org.apache.olingo.odata2.api.exception.ODataHttpException;
-import org.apache.olingo.odata2.api.exception.ODataNotFoundException;
import org.apache.olingo.odata2.api.exception.ODataNotImplementedException;
import org.apache.olingo.odata2.core.annotation.edm.AnnotationHelper;
-import org.apache.olingo.odata2.core.exception.ODataRuntimeException;
/**
*
*/
public class AnnotationValueAccess implements ValueAccess {
private final AnnotationHelper annotationHelper = new AnnotationHelper();
-
+
/**
* Retrieves the value of an EDM property for the given data object.
* @param data the Java data object
@@ -43,22 +39,7 @@ public class AnnotationValueAccess implements ValueAccess {
*/
@Override
public <T> Object getPropertyValue(final T data, final EdmProperty property) throws ODataException {
- if(data == null) {
- if(property.getFacets() == null || property.getFacets().isNullable()) {
- return null;
- }
- throw new ODataRuntimeException("Invalid value for data '" + data + "' and property '" + property + "'.");
- }
-
- if(data instanceof Collection) {
- Collection c = (Collection) data;
- for (Object object : c) {
- if(annotationHelper.isEdmAnnotated(object)) {
- return annotationHelper.getValueForProperty(object, property.getName());
- }
- }
- }
- if(annotationHelper.isEdmAnnotated(data)) {
+ if (annotationHelper.isEdmAnnotated(data)) {
return annotationHelper.getValueForProperty(data, property.getName());
}
throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
@@ -72,7 +53,7 @@ public class AnnotationValueAccess implements ValueAccess {
*/
@Override
public <T, V> void setPropertyValue(T data, final EdmProperty property, final V value) throws ODataException {
- if(annotationHelper.isEdmAnnotated(data)) {
+ if (annotationHelper.isEdmAnnotated(data)) {
annotationHelper.setValueForProperty(data, property.getName(), value);
} else {
throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
@@ -86,9 +67,9 @@ public class AnnotationValueAccess implements ValueAccess {
* @return the requested Java type
*/
public <T> Class<?> getPropertyType(final T data, final EdmProperty property) throws ODataException {
- if(annotationHelper.isEdmAnnotated(data)) {
+ if (annotationHelper.isEdmAnnotated(data)) {
Class<?> fieldType = annotationHelper.getFieldTypeForProperty(data, property.getName());
- if(fieldType == null) {
+ if (fieldType == null) {
throw new ODataException("No field type found for property " + property);
}
return fieldType;
@@ -103,7 +84,10 @@ public class AnnotationValueAccess implements ValueAccess {
* @return the requested value
*/
public <T> Object getMappingValue(final T data, final EdmMapping mapping) throws ODataException {
- throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
+ if (mapping != null && mapping.getMediaResourceMimeTypeKey() != null) {
+ return annotationHelper.getValueForProperty(data, mapping.getMediaResourceMimeTypeKey());
+ }
+ return null;
}
/**
@@ -113,6 +97,8 @@ public class AnnotationValueAccess implements ValueAccess {
* @param value the new value
*/
public <T, V> void setMappingValue(T data, final EdmMapping mapping, final V value) throws ODataException {
- throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
+ if (mapping != null && mapping.getMediaResourceMimeTypeKey() != null) {
+ annotationHelper.setValueForProperty(data, mapping.getMediaResourceMimeTypeKey(), value);
+ }
}
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/4d80947e/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/DataStore.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/DataStore.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/DataStore.java
index 55a839e..f52e023 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/DataStore.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/DataStore.java
@@ -28,11 +28,6 @@ import java.util.Locale;
import java.util.Map;
import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
-import org.apache.olingo.odata2.api.annotation.edm.ds.EntityCreate;
-import org.apache.olingo.odata2.api.annotation.edm.ds.EntityDelete;
-import org.apache.olingo.odata2.api.annotation.edm.ds.EntityRead;
-import org.apache.olingo.odata2.api.annotation.edm.ds.EntitySetRead;
-import org.apache.olingo.odata2.api.annotation.edm.ds.EntityUpdate;
import org.apache.olingo.odata2.api.exception.ODataApplicationException;
import org.apache.olingo.odata2.core.annotation.edm.AnnotationHelper;
import org.apache.olingo.odata2.core.exception.ODataRuntimeException;
@@ -47,25 +42,26 @@ public class DataStore<T> {
private final Class<T> dataTypeClass;
private int idCounter = 1;
-
+
private static class InMemoryDataStore {
private static final Map<Class<?>, DataStore<?>> c2ds = new HashMap<Class<?>, DataStore<?>>();
+
@SuppressWarnings("unchecked")
static DataStore<?> getInstance(Class<?> clz) {
DataStore<?> ds = c2ds.get(clz);
- if(ds == null) {
+ if (ds == null) {
ds = new DataStore<Object>((Class<Object>) clz);
c2ds.put(clz, ds);
}
return ds;
}
}
-
+
@SuppressWarnings("unchecked")
public static <T> DataStore<T> createInMemory(Class<T> clazz) {
return (DataStore<T>) InMemoryDataStore.getInstance(clazz);
}
-
+
private DataStore(List<T> wrapStore, Class<T> clz) {
dataStore = wrapStore;
dataTypeClass = clz;
@@ -74,15 +70,15 @@ public class DataStore<T> {
private DataStore(Class<T> clz) {
this(new ArrayList<T>(), clz);
}
-
+
public Class<T> getDataTypeClass() {
return dataTypeClass;
}
-
+
public String getEntityTypeName() {
return ANNOTATION_HELPER.extractEntityTypeName(dataTypeClass);
}
-
+
public T createInstance() {
try {
return dataTypeClass.newInstance();
@@ -92,8 +88,7 @@ public class DataStore<T> {
throw new ODataRuntimeException("Unable to create instance of class '" + dataTypeClass + "'.", e);
}
}
-
- @EntityRead
+
public T read(T obj) {
List<Object> objKeys = getKeys(obj);
for (T stored : dataStore) {
@@ -104,19 +99,18 @@ public class DataStore<T> {
return null;
}
- @EntitySetRead
public Collection<T> read() {
return Collections.unmodifiableCollection(dataStore);
}
- @EntityCreate
public T create(T object) throws DataStoreException {
- createKeys(object);
+ if (read(object) != null || getKeys(object).contains(null)) {
+ createKeys(object);
+ }
dataStore.add(object);
return object;
}
- @EntityUpdate
public T update(T object) {
T stored = read(object);
dataStore.remove(stored);
@@ -124,55 +118,54 @@ public class DataStore<T> {
return object;
}
- @EntityDelete
public T delete(T object) {
T stored = read(object);
- if(stored != null) {
+ if (stored != null) {
dataStore.remove(stored);
}
return stored;
}
-
+
private List<Object> getKeys(T object) {
Map<String, Object> keys = ANNOTATION_HELPER.getValueForAnnotatedFields(object, EdmKey.class);
-
+
// XXX: list should be in a defined order -> better to create an 'Key' object which is comparable
- List<Object> keyList = new ArrayList(keys.values());
+ List<Object> keyList = new ArrayList<Object>(keys.values());
return keyList;
}
-
+
private T createKeys(T object) throws DataStoreException {
List<Field> fields = ANNOTATION_HELPER.getAnnotatedFields(object, EdmKey.class);
- if(fields.isEmpty()) {
+ if (fields.isEmpty()) {
throw new DataStoreException("No EdmKey annotated fields found for class " + object.getClass());
}
Map<String, Object> fieldName2KeyValue = new HashMap<String, Object>();
-
+
for (Field field : fields) {
Object key = createKey(field);
fieldName2KeyValue.put(ANNOTATION_HELPER.getCanonicalName(field), key);
}
-
+
ANNOTATION_HELPER.setValuesToAnnotatedFields(fieldName2KeyValue, object, EdmKey.class);
-
+
return object;
}
private Object createKey(Field field) {
Class<?> type = field.getType();
-
- if(type == String.class) {
+
+ if (type == String.class) {
return String.valueOf(idCounter++);
- } else if(type == Integer.class || type == int.class) {
+ } else if (type == Integer.class || type == int.class) {
return Integer.valueOf(idCounter++);
- } else if(type == Long.class || type == long.class) {
+ } else if (type == Long.class || type == long.class) {
return Long.valueOf(idCounter++);
}
-
+
throw new UnsupportedOperationException("Automated key generation for type '" + type
- + "' is not supported (caused on field '" + field + "').");
+ + "' is not supported (caused on field '" + field + "').");
}
-
+
public static class DataStoreException extends ODataApplicationException {
public DataStoreException(String message) {
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/4d80947e/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java
index 8f9a2f4..5d705dc 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java
@@ -20,13 +20,17 @@ package org.apache.olingo.odata2.core.annotation.edm;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
+import java.math.BigDecimal;
+import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Collections;
+import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.UUID;
import org.apache.olingo.odata2.api.annotation.edm.EdmComplexType;
import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
@@ -35,7 +39,6 @@ import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceContent;
import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
-import org.apache.olingo.odata2.api.annotation.edm.NavigationEnd;
import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
import org.apache.olingo.odata2.api.edm.FullQualifiedName;
@@ -97,7 +100,7 @@ public class AnnotationEdmProvider extends EdmProvider {
return ANNOTATION_HELPER.isEdmAnnotated(c);
}
});
-
+
init();
}
@@ -126,7 +129,7 @@ public class AnnotationEdmProvider extends EdmProvider {
@Override
public AssociationSet getAssociationSet(String entityContainer, FullQualifiedName association,
- String sourceEntitySetName, String sourceEntitySetRole) throws ODataException {
+ String sourceEntitySetName, String sourceEntitySetRole) throws ODataException {
EntityContainer container = name2Container.get(entityContainer);
if (container != null) {
List<AssociationSet> associations = container.getAssociationSets();
@@ -134,12 +137,12 @@ public class AnnotationEdmProvider extends EdmProvider {
if (associationSet.getAssociation().equals(association)) {
final AssociationSetEnd endOne = associationSet.getEnd1();
if (endOne.getRole().equals(sourceEntitySetRole)
- && endOne.getEntitySet().equals(sourceEntitySetName)) {
+ && endOne.getEntitySet().equals(sourceEntitySetName)) {
return associationSet;
}
final AssociationSetEnd endTwo = associationSet.getEnd2();
if (endTwo.getRole().equals(sourceEntitySetRole)
- && endTwo.getEntitySet().equals(sourceEntitySetName)) {
+ && endTwo.getEntitySet().equals(sourceEntitySetName)) {
return associationSet;
}
}
@@ -273,14 +276,14 @@ public class AnnotationEdmProvider extends EdmProvider {
private void handleEntityContainer(Class<?> aClass) {
EdmEntityType entityType = aClass.getAnnotation(EdmEntityType.class);
if (entityType != null) {
- String containerName = getCanonicalContainerName(entityType);
+ String containerName = DEFAULT_CONTAINER_NAME;
ContainerBuilder builder = containerName2ContainerBuilder.get(containerName);
if (builder == null) {
builder = ContainerBuilder.init(entityType.namespace(), containerName);
containerName2ContainerBuilder.put(containerName, builder);
}
EdmEntitySet entitySet = aClass.getAnnotation(EdmEntitySet.class);
- if(entitySet != null) {
+ if (entitySet != null) {
FullQualifiedName typeName = createFqnForEntityType(aClass, entityType);
builder.addEntitySet(createEntitySet(typeName, entitySet));
}
@@ -293,8 +296,8 @@ public class AnnotationEdmProvider extends EdmProvider {
private FullQualifiedName createFqnForEntityType(Class<?> annotatedClass, EdmEntityType entityType) {
String name = entityType.name();
- if(name.isEmpty()) {
- return new FullQualifiedName(entityType.namespace(), annotatedClass.getSimpleName());
+ if (name.isEmpty()) {
+ return new FullQualifiedName(entityType.namespace(), annotatedClass.getSimpleName());
} else {
return new FullQualifiedName(entityType.namespace(), entityType.name());
}
@@ -321,10 +324,6 @@ public class AnnotationEdmProvider extends EdmProvider {
}
}
- private String getCanonicalContainerName(EdmEntityType entity) {
- return DEFAULT_CONTAINER_NAME;
- }
-
//
//
//
@@ -340,10 +339,10 @@ public class AnnotationEdmProvider extends EdmProvider {
private final List<NavigationProperty> navProperties = new ArrayList<NavigationProperty>();
private final List<Association> associations = new ArrayList<Association>();
-// public TypeBuilder(String namespace, String name) {
-// this.namespace = namespace;
-// this.name = name;
-// }
+ // public TypeBuilder(String namespace, String name) {
+ // this.namespace = namespace;
+ // this.name = name;
+ // }
public TypeBuilder(FullQualifiedName fqn) {
this.namespace = fqn.getNamespace();
this.name = fqn.getName();
@@ -382,7 +381,7 @@ public class AnnotationEdmProvider extends EdmProvider {
associations.add(association);
}
EdmMediaResourceContent emrc = field.getAnnotation(EdmMediaResourceContent.class);
- if(emrc != null) {
+ if (emrc != null) {
isMediaResource = true;
}
}
@@ -416,7 +415,7 @@ public class AnnotationEdmProvider extends EdmProvider {
complexType.setBaseType(baseEntityType);
}
return complexType.setName(name)
- .setProperties(properties);
+ .setProperties(properties);
}
public EntityType buildEntityType() {
@@ -431,9 +430,9 @@ public class AnnotationEdmProvider extends EdmProvider {
entityType.setNavigationProperties(navProperties);
}
return entityType.setName(name)
- .setAbstract(isAbstract)
- .setHasStream(isMediaResource)
- .setProperties(properties);
+ .setAbstract(isAbstract)
+ .setHasStream(isMediaResource)
+ .setProperties(properties);
}
public Collection<Association> buildAssociations() {
@@ -450,13 +449,12 @@ public class AnnotationEdmProvider extends EdmProvider {
}
private Property createProperty(EdmProperty ep, Field field, String defaultNamespace) {
- if(isAnnotatedEntity(field.getType())) {
+ if (isAnnotatedEntity(field.getType())) {
return createComplexProperty(field, defaultNamespace);
} else {
return createSimpleProperty(ep, field);
}
}
-
private Property createSimpleProperty(EdmProperty ep, Field field) {
SimpleProperty sp = new SimpleProperty();
@@ -477,7 +475,7 @@ public class AnnotationEdmProvider extends EdmProvider {
// settings from property
String entityName = ANNOTATION_HELPER.getPropertyName(field);
cp.setName(entityName);
-
+
// settings from related complex entity
EdmComplexType ece = field.getType().getAnnotation(EdmComplexType.class);
String complexEntityNamespace = ece.namespace();
@@ -491,18 +489,14 @@ public class AnnotationEdmProvider extends EdmProvider {
private NavigationProperty createNavigationProperty(String namespace, EdmNavigationProperty enp, Field field) {
NavigationProperty navProp = new NavigationProperty();
- String entityName = ANNOTATION_HELPER.getPropertyName(field);
- navProp.setName(entityName);
- //
- NavigationEnd from = enp.from();
- String fromRole = ANNOTATION_HELPER.extractRoleName(from, field.getDeclaringClass());
+ navProp.setName(ANNOTATION_HELPER.getPropertyName(field));
+ String fromRole = ANNOTATION_HELPER.extractFromRoleName(enp, field);
navProp.setFromRole(fromRole);
- NavigationEnd to = enp.to();
- String toRole = ANNOTATION_HELPER.extractRoleName(to, field.getType());
+ String toRole = ANNOTATION_HELPER.extractToRoleName(enp, field);
navProp.setToRole(toRole);
- String relationshipName = ANNOTATION_HELPER.extractRelationshipName(enp, fromRole, toRole);
+ String relationshipName = ANNOTATION_HELPER.extractRelationshipName(enp, field);
navProp.setRelationship(new FullQualifiedName(namespace, relationshipName));
return navProp;
@@ -511,18 +505,32 @@ public class AnnotationEdmProvider extends EdmProvider {
private EdmSimpleTypeKind getEdmSimpleType(Class<?> type) {
if (type == String.class) {
return EdmSimpleTypeKind.String;
+ } else if (type == boolean.class || type == Boolean.class) {
+ return EdmSimpleTypeKind.Boolean;
+ } else if (type == byte.class || type == Byte.class) {
+ return EdmSimpleTypeKind.SByte;
+ } else if (type == short.class || type == Short.class) {
+ return EdmSimpleTypeKind.Int16;
} else if (type == int.class || type == Integer.class) {
return EdmSimpleTypeKind.Int32;
- } else if (type == double.class || type == Double.class) {
- return EdmSimpleTypeKind.Double;
} else if (type == long.class || type == Long.class) {
return EdmSimpleTypeKind.Int64;
- } else if (type == Calendar.class) {
- return EdmSimpleTypeKind.DateTime;
+ } else if (type == double.class || type == Double.class) {
+ return EdmSimpleTypeKind.Double;
+ } else if (type == float.class || type == Float.class) {
+ return EdmSimpleTypeKind.Single;
+ } else if (type == BigInteger.class || type == BigDecimal.class) {
+ return EdmSimpleTypeKind.Decimal;
} else if (type == Byte[].class || type == byte[].class) {
return EdmSimpleTypeKind.Binary;
+ } else if (type == Date.class) {
+ return EdmSimpleTypeKind.DateTime;
+ } else if (type == Calendar.class) {
+ return EdmSimpleTypeKind.DateTimeOffset;
+ } else if (type == UUID.class) {
+ return EdmSimpleTypeKind.Guid;
} else {
- throw new UnsupportedOperationException("Not yet supported type '" + type + "'.");
+ throw new UnsupportedOperationException("Not yet supported type '" + type + "'.");
}
}
@@ -552,29 +560,18 @@ public class AnnotationEdmProvider extends EdmProvider {
Association association = new Association();
EdmNavigationProperty navigation = field.getAnnotation(EdmNavigationProperty.class);
- NavigationEnd from = navigation.from();
AssociationEnd fromEnd = new AssociationEnd();
fromEnd.setRole(navProperty.getFromRole());
- String typeName = ANNOTATION_HELPER.extractEntitTypeName(from, field.getDeclaringClass());
+ String typeName = ANNOTATION_HELPER.extractEntityTypeName(field.getDeclaringClass());
fromEnd.setType(new FullQualifiedName(namespace, typeName));
- fromEnd.setMultiplicity(from.multiplicity());
+ fromEnd.setMultiplicity(EdmMultiplicity.ONE);
association.setEnd1(fromEnd);
- NavigationEnd to = navigation.to();
AssociationEnd toEnd = new AssociationEnd();
toEnd.setRole(navProperty.getToRole());
- String toTypeName = ANNOTATION_HELPER.extractEntitTypeName(to, field.getType());
+ String toTypeName = ANNOTATION_HELPER.extractEntitTypeName(navigation, field);
toEnd.setType(new FullQualifiedName(namespace, toTypeName));
-
- EdmMultiplicity toMultiplicity = to.multiplicity();
- Class<?> toClass = field.getType();
- boolean isCollectionType = toClass.isArray() || Collection.class.isAssignableFrom(toClass);
- if (toMultiplicity == EdmMultiplicity.ONE && isCollectionType) {
- // XXX: magic, please check and or remove/refactore
- toEnd.setMultiplicity(EdmMultiplicity.MANY);
- } else {
- toEnd.setMultiplicity(toMultiplicity);
- }
+ toEnd.setMultiplicity(ANNOTATION_HELPER.getMultiplicity(navigation, field));
association.setEnd2(toEnd);
String associationName = navProperty.getRelationship().getName();
@@ -585,7 +582,7 @@ public class AnnotationEdmProvider extends EdmProvider {
private String getCanonicalName(Field field) {
return ANNOTATION_HELPER.getCanonicalName(field);
}
-
+
private boolean isAnnotatedEntity(Class<?> clazz) {
return ANNOTATION_HELPER.isEdmTypeAnnotated(clazz);
}
@@ -594,7 +591,7 @@ public class AnnotationEdmProvider extends EdmProvider {
static class SchemaBuilder {
final private String namespace;
-// private String alias;
+ // private String alias;
private final List<Using> usings = new ArrayList<Using>();
private final List<EntityType> entityTypes = new ArrayList<EntityType>();
private final List<ComplexType> complexTypes = new ArrayList<ComplexType>();
@@ -641,7 +638,7 @@ public class AnnotationEdmProvider extends EdmProvider {
AssociationEnd oneEnd2 = associationOne.getEnd2();
AssociationEnd twoEnd1 = associationTwo.getEnd1();
AssociationEnd twoEnd2 = associationTwo.getEnd2();
- AssociationEnd[] oneEnds = new AssociationEnd[]{oneEnd1, oneEnd2};
+ AssociationEnd[] oneEnds = new AssociationEnd[] { oneEnd1, oneEnd2 };
for (AssociationEnd associationEnd : oneEnds) {
if (associationEnd.getRole().equals(twoEnd1.getRole())) {
@@ -677,10 +674,11 @@ public class AnnotationEdmProvider extends EdmProvider {
final private String name;
final private String namespace;
private boolean defaultContainer = true;
- private List<EntitySet> entitySets = new ArrayList<EntitySet>();
- private List<AssociationSet> associationSets = new ArrayList<AssociationSet>();
- private List<FunctionImport> functionImports = new ArrayList<FunctionImport>();
-// private Documentation documentation;
+ private final List<EntitySet> entitySets = new ArrayList<EntitySet>();
+ private final List<AssociationSet> associationSets = new ArrayList<AssociationSet>();
+ private final List<FunctionImport> functionImports = new ArrayList<FunctionImport>();
+
+ // private Documentation documentation;
private ContainerBuilder(String namespace, String containerName) {
this.namespace = namespace;
@@ -704,7 +702,7 @@ public class AnnotationEdmProvider extends EdmProvider {
entitySets.add(entitySet);
return this;
}
-
+
public void addAssociationSets(Collection<Association> associations) {
for (Association association : associations) {
AssociationSet as = new AssociationSet();
@@ -716,12 +714,12 @@ public class AnnotationEdmProvider extends EdmProvider {
asEnd1.setEntitySet(getEntitySetName(association.getEnd1()));
asEnd1.setRole(association.getEnd1().getRole());
as.setEnd1(asEnd1);
-
+
AssociationSetEnd asEnd2 = new AssociationSetEnd();
asEnd2.setEntitySet(getEntitySetName(association.getEnd2()));
asEnd2.setRole(association.getEnd2().getRole());
as.setEnd2(asEnd2);
-
+
associationSets.add(as);
}
}
@@ -736,10 +734,9 @@ public class AnnotationEdmProvider extends EdmProvider {
return ec;
}
-
private String getEntitySetName(AssociationEnd end) {
for (EntitySet entitySet : entitySets) {
- if(entitySet.getEntityType().equals(end.getType())) {
+ if (entitySet.getEntityType().equals(end.getType())) {
return entitySet.getName();
}
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/4d80947e/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java
index dfa461a..7e92284 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java
@@ -16,7 +16,9 @@ package org.apache.olingo.odata2.core.annotation.edm;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
+import java.lang.reflect.ParameterizedType;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
@@ -29,7 +31,6 @@ import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
-import org.apache.olingo.odata2.api.annotation.edm.NavigationEnd;
import org.apache.olingo.odata2.api.edm.EdmLiteralKind;
import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
import org.apache.olingo.odata2.api.edm.EdmSimpleTypeException;
@@ -43,6 +44,13 @@ import org.apache.olingo.odata2.core.exception.ODataRuntimeException;
*/
public class AnnotationHelper {
+ /**
+ * Compare keys of both instances.
+ *
+ * @param firstInstance
+ * @param secondInstance
+ * @return
+ */
public boolean keyMatch(Object firstInstance, Object secondInstance) {
if (firstInstance == null || secondInstance == null) {
return false;
@@ -53,13 +61,29 @@ public class AnnotationHelper {
Map<String, Object> firstKeyFields = getValueForAnnotatedFields(firstInstance, EdmKey.class);
Map<String, Object> secondKeyFields = getValueForAnnotatedFields(secondInstance, EdmKey.class);
- if (firstKeyFields.size() != secondKeyFields.size()) {
+ return keyValuesMatch(firstKeyFields, secondKeyFields);
+ }
+
+ /**
+ * Compare keys of instance with key values in map.
+ *
+ * @param instance
+ * @param keyName2Value
+ * @return
+ */
+ public boolean keyMatch(Object instance, Map<String, Object> keyName2Value) {
+ Map<String, Object> instanceKeyFields = getValueForAnnotatedFields(instance, EdmKey.class);
+ return keyValuesMatch(instanceKeyFields, keyName2Value);
+ }
+
+ private boolean keyValuesMatch(Map<String, Object> firstKeyValues, Map<String, Object> secondKeyValues) {
+ if (firstKeyValues.size() != secondKeyValues.size()) {
return false;
} else {
- Set<Map.Entry<String, Object>> entries = firstKeyFields.entrySet();
+ Set<Map.Entry<String, Object>> entries = firstKeyValues.entrySet();
for (Map.Entry<String, Object> entry : entries) {
Object firstKey = entry.getValue();
- Object secondKey = secondKeyFields.get(entry.getKey());
+ Object secondKey = secondKeyValues.get(entry.getKey());
if (!isEqual(firstKey, secondKey)) {
return false;
}
@@ -67,7 +91,7 @@ public class AnnotationHelper {
return true;
}
}
-
+
private boolean isEqual(Object firstKey, Object secondKey) {
if (firstKey == null) {
if (secondKey == null) {
@@ -80,19 +104,20 @@ public class AnnotationHelper {
}
}
- public String extractEntitTypeName(NavigationEnd navEnd, Class<?> fallbackClass) {
- Class<?> entityTypeClass = navEnd.entitySet();
+ public String extractEntitTypeName(EdmNavigationProperty enp, Class<?> fallbackClass) {
+ Class<?> entityTypeClass = enp.toType();
+ return extractEntityTypeName(entityTypeClass == Object.class ? fallbackClass : entityTypeClass);
+ }
+
+ public String extractEntitTypeName(EdmNavigationProperty enp, Field field) {
+ Class<?> entityTypeClass = enp.toType();
if (entityTypeClass == Object.class) {
- return extractEntityTypeName(fallbackClass);
- }
- EdmEntityType type = entityTypeClass.getAnnotation(EdmEntityType.class);
- if (type == null) {
- return null;
- }
- if(type.name().isEmpty()) {
- return extractEntityTypeName(fallbackClass);
+ Class<?> toClass = field.getType();
+ return extractEntityTypeName((toClass.isArray() || Collection.class.isAssignableFrom(toClass) ?
+ (Class<?>) ((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0] : toClass));
+ } else {
+ return extractEntityTypeName(entityTypeClass);
}
- return type.name();
}
/**
@@ -165,7 +190,7 @@ public class AnnotationHelper {
EdmNavigationProperty navProperty = field.getAnnotation(EdmNavigationProperty.class);
if (navProperty == null) {
throw new EdmAnnotationException("Given field '" + field
- + "' has no EdmProperty or EdmNavigationProperty annotation.");
+ + "' has no EdmProperty or EdmNavigationProperty annotation.");
}
return navProperty.name();
}
@@ -180,53 +205,54 @@ public class AnnotationHelper {
return propertyName;
}
- public String extractRoleName(NavigationEnd navigationEnd, Class<?> fallbackClass) {
- String role = navigationEnd.role();
- if (role.isEmpty()) {
- role = getCanonicalRole(navigationEnd, fallbackClass);
- }
- return role;
+ public String extractFromRoleName(EdmNavigationProperty enp, Field field) {
+ return getCanonicalRole(field.getDeclaringClass());
}
-
- public String getCanonicalRole(NavigationEnd navEnd, Class<?> fallbackClass) {
- String toRole = extractEntityTypeName(navEnd.entitySet());
- if (toRole == null) {
- toRole = extractEntityTypeName(fallbackClass);
+
+ public String extractToRoleName(EdmNavigationProperty enp, Field field) {
+ String role = enp.toRole();
+ if (role.isEmpty()) {
+ role = getCanonicalRole(
+ field.getType().isArray() || Collection.class.isAssignableFrom(field.getType()) ?
+ (Class<?>) ((ParameterizedType) field.getGenericType()).getActualTypeArguments()[0] : field.getType());
}
+ return role;
+ }
+
+ public String getCanonicalRole(Class<?> fallbackClass) {
+ String toRole = extractEntityTypeName(fallbackClass);
return "r_" + toRole;
}
public String extractRelationshipName(EdmNavigationProperty enp, Field field) {
- String fromRole = extractRoleName(enp.from(), field.getDeclaringClass());
- String toRole = extractRoleName(enp.to(), field.getType());
-
- return extractRelationshipName(enp, fromRole, toRole);
- }
-
- public String extractRelationshipName(EdmNavigationProperty enp, String fromRole, String toRole) {
- String relationshipName = enp.association();
- if(relationshipName.isEmpty()) {
- if(fromRole.compareTo(toRole) > 0) {
- relationshipName = toRole + "-" + fromRole;
- } else {
- relationshipName = fromRole + "-" + toRole;
- }
+ String relationshipName = enp.association();
+ if (relationshipName.isEmpty()) {
+ final String fromRole = extractFromRoleName(enp, field);
+ final String toRole = extractToRoleName(enp, field);
+ if (fromRole.compareTo(toRole) > 0) {
+ relationshipName = toRole + "-" + fromRole;
+ } else {
+ relationshipName = fromRole + "-" + toRole;
}
- return relationshipName;
+ }
+ return relationshipName;
}
- public static final class ODataAnnotationException extends ODataException {
+ public EdmMultiplicity getMultiplicity(EdmNavigationProperty enp, Field field) {
+ EdmMultiplicity multiplicity = enp.toMultiplicity();
+ final boolean isCollectionType = field.getType().isArray() || Collection.class.isAssignableFrom(field.getType());
- public ODataAnnotationException(String message) {
- super(message);
+ if (multiplicity == EdmMultiplicity.ONE && isCollectionType) {
+ return EdmMultiplicity.MANY;
}
+ return multiplicity;
}
public <T> T setKeyFields(T instance, Map<String, Object> keys) {
List<Field> fields = getAnnotatedFields(instance, EdmKey.class);
if (fields.size() != keys.size()) {
throw new IllegalStateException("Wrong amount of key properties. Expected read keys = "
- + fields + " given key predicates = " + keys);
+ + fields + " given key predicates = " + keys);
}
for (Field field : fields) {
@@ -238,15 +264,21 @@ public class AnnotationHelper {
return instance;
}
- public static class AnnotatedNavInfo {
+ public static final class ODataAnnotationException extends ODataException {
+ public ODataAnnotationException(String message) {
+ super(message);
+ }
+ }
+
+ public class AnnotatedNavInfo {
private final Field fromField;
private final Field toField;
private final EdmNavigationProperty fromNavigation;
private final EdmNavigationProperty toNavigation;
public AnnotatedNavInfo(Field fromField, Field toField, EdmNavigationProperty fromNavigation,
- EdmNavigationProperty toNavigation) {
+ EdmNavigationProperty toNavigation) {
this.fromField = fromField;
this.toField = toField;
this.fromNavigation = fromNavigation;
@@ -262,33 +294,11 @@ public class AnnotationHelper {
}
public EdmMultiplicity getFromMultiplicity() {
- EdmMultiplicity from = fromNavigation.from().multiplicity();
- EdmMultiplicity to = toNavigation.to().multiplicity();
-
- if (from.equals(to)) {
- return from;
- } else {
- if (EdmMultiplicity.MANY == from || EdmMultiplicity.MANY == to) {
- return EdmMultiplicity.MANY;
- } else {
- return EdmMultiplicity.ONE;
- }
- }
+ return getMultiplicity(toNavigation, toField);
}
public EdmMultiplicity getToMultiplicity() {
- EdmMultiplicity from = fromNavigation.to().multiplicity();
- EdmMultiplicity to = toNavigation.from().multiplicity();
-
- if (from.equals(to)) {
- return from;
- } else {
- if (EdmMultiplicity.MANY == from || EdmMultiplicity.MANY == to) {
- return EdmMultiplicity.MANY;
- } else {
- return EdmMultiplicity.ONE;
- }
- }
+ return getMultiplicity(fromNavigation, fromField);
}
}
@@ -296,12 +306,12 @@ public class AnnotationHelper {
List<Field> sourceFields = getAnnotatedFields(sourceClass, EdmNavigationProperty.class);
List<Field> targetFields = getAnnotatedFields(targetClass, EdmNavigationProperty.class);
- for (Field targetField : targetFields) {
- for (Field sourceField : sourceFields) {
- EdmNavigationProperty sourceNav = sourceField.getAnnotation(EdmNavigationProperty.class);
- EdmNavigationProperty targetNav = targetField.getAnnotation(EdmNavigationProperty.class);
- String sourceAssociation = extractRelationshipName(sourceNav, sourceField);
- String targetAssociation = extractRelationshipName(targetNav, targetField);
+ for (Field sourceField : sourceFields) {
+ final EdmNavigationProperty sourceNav = sourceField.getAnnotation(EdmNavigationProperty.class);
+ final String sourceAssociation = extractRelationshipName(sourceNav, sourceField);
+ for (Field targetField : targetFields) {
+ final EdmNavigationProperty targetNav = targetField.getAnnotation(EdmNavigationProperty.class);
+ final String targetAssociation = extractRelationshipName(targetNav, targetField);
if (sourceAssociation.equals(targetAssociation)) {
return new AnnotatedNavInfo(sourceField, targetField, sourceNav, targetNav);
}
@@ -310,22 +320,6 @@ public class AnnotationHelper {
return null;
}
- public Field getCommonNavigationFieldFromTarget(Class<?> sourceClass, Class<?> targetClass) {
- List<Field> sourceFields = getAnnotatedFields(sourceClass, EdmNavigationProperty.class);
- List<Field> targetFields = getAnnotatedFields(targetClass, EdmNavigationProperty.class);
-
- for (Field targetField : targetFields) {
- for (Field sourcField : sourceFields) {
- EdmNavigationProperty sourceNav = sourcField.getAnnotation(EdmNavigationProperty.class);
- EdmNavigationProperty targetNav = targetField.getAnnotation(EdmNavigationProperty.class);
- if (sourceNav.association().equals(targetNav.association())) {
- return targetField;
- }
- }
- }
- return null;
- }
-
public Class<?> getFieldTypeForProperty(Object instance, String propertyName) throws ODataAnnotationException {
if (instance == null) {
return null;
@@ -334,7 +328,7 @@ public class AnnotationHelper {
Field field = getFieldForPropertyName(instance, propertyName, instance.getClass(), true);
if (field == null) {
throw new ODataAnnotationException("No field for property '" + propertyName
- + "' found at class '" + instance.getClass() + "'.");
+ + "' found at class '" + instance.getClass() + "'.");
}
return field.getType();
}
@@ -347,7 +341,7 @@ public class AnnotationHelper {
Field field = getFieldForPropertyName(instance, propertyName, instance.getClass(), true);
if (field == null) {
throw new ODataAnnotationException("No field for property '" + propertyName
- + "' found at class '" + instance.getClass() + "'.");
+ + "' found at class '" + instance.getClass() + "'.");
}
return getFieldValue(instance, field);
}
@@ -362,7 +356,7 @@ public class AnnotationHelper {
}
private Field getFieldForPropertyName(Object instance, String propertyName,
- Class<?> resultClass, boolean inherited) {
+ Class<?> resultClass, boolean inherited) {
if (instance == null) {
return null;
}
@@ -402,17 +396,17 @@ public class AnnotationHelper {
}
private Object getValueForField(Object instance, Class<?> resultClass,
- Class<? extends Annotation> annotation, boolean inherited) {
+ Class<? extends Annotation> annotation, boolean inherited) {
return getValueForField(instance, null, resultClass, annotation, inherited);
}
public Map<String, Object> getValueForAnnotatedFields(Object instance,
- Class<? extends Annotation> annotation) {
+ Class<? extends Annotation> annotation) {
return getValueForAnnotatedFields(instance, instance.getClass(), annotation, true);
}
private Map<String, Object> getValueForAnnotatedFields(Object instance, Class<?> resultClass,
- Class<? extends Annotation> annotation, boolean inherited) {
+ Class<? extends Annotation> annotation, boolean inherited) {
if (instance == null) {
return null;
}
@@ -423,7 +417,9 @@ public class AnnotationHelper {
for (Field field : fields) {
if (field.getAnnotation(annotation) != null) {
Object value = getFieldValue(instance, field);
- fieldName2Value.put(field.getName(), value);
+ final EdmProperty property = field.getAnnotation(EdmProperty.class);
+ final String name = property == null || property.name().isEmpty() ? field.getName() : property.name();
+ fieldName2Value.put(name, value);
}
}
@@ -437,7 +433,7 @@ public class AnnotationHelper {
}
public void setValuesToAnnotatedFields(Map<String, Object> fieldName2Value, Object instance,
- Class<? extends Annotation> annotation) {
+ Class<? extends Annotation> annotation) {
List<Field> fields = getAnnotatedFields(instance, annotation);
// XXX: refactore
@@ -470,7 +466,7 @@ public class AnnotationHelper {
* @return
*/
private List<Field> getAnnotatedFields(Class<?> resultClass,
- Class<? extends Annotation> annotation, boolean inherited) {
+ Class<? extends Annotation> annotation, boolean inherited) {
if (resultClass == null) {
return null;
}
@@ -494,7 +490,7 @@ public class AnnotationHelper {
}
private Object getValueForField(Object instance, String fieldName, Class<?> resultClass,
- Class<? extends Annotation> annotation, boolean inherited) {
+ Class<? extends Annotation> annotation, boolean inherited) {
if (instance == null) {
return null;
}
@@ -502,7 +498,7 @@ public class AnnotationHelper {
Field[] fields = resultClass.getDeclaredFields();
for (Field field : fields) {
if (field.getAnnotation(annotation) != null
- && (fieldName == null || field.getName().equals(fieldName))) {
+ && (fieldName == null || field.getName().equals(fieldName))) {
return getFieldValue(instance, field);
}
}
@@ -532,8 +528,8 @@ public class AnnotationHelper {
private void setFieldValue(Object instance, Field field, Object propertyValue) {
try {
if (propertyValue != null
- && field.getType() != propertyValue.getClass()
- && propertyValue.getClass() == String.class) {
+ && field.getType() != propertyValue.getClass()
+ && propertyValue.getClass() == String.class) {
propertyValue = convert(field, (String) propertyValue);
}
boolean access = field.isAccessible();
@@ -548,15 +544,15 @@ public class AnnotationHelper {
}
public Object convert(Field field, String propertyValue) {
- Class fieldClass = field.getType();
+ Class<?> fieldClass = field.getType();
try {
EdmProperty property = field.getAnnotation(EdmProperty.class);
EdmSimpleTypeKind type = property.type();
return type.getEdmSimpleTypeInstance().valueOfString(propertyValue,
- EdmLiteralKind.DEFAULT, null, fieldClass);
+ EdmLiteralKind.DEFAULT, null, fieldClass);
} catch (EdmSimpleTypeException ex) {
throw new ODataRuntimeException("Conversion failed for string property with error: "
- + ex.getMessage(), ex);
+ + ex.getMessage(), ex);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/4d80947e/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/ListsProcessor.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/ListsProcessor.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/ListsProcessor.java
index f659383..b4a2c6f 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/ListsProcessor.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/ListsProcessor.java
@@ -1001,9 +1001,8 @@ public class ListsProcessor extends ODataSingleProcessor {
relatedData = null;
}
- if(relatedData == null) {
- result.setEntryData(new HashMap<String, Object>());
- return result;
+ if (relatedData == null) {
+ result.setEntryData(Collections.<String, Object> emptyMap());
} else {
result.setEntryData(getStructuralTypeValueMap(relatedData, entityType));
@@ -1012,8 +1011,8 @@ public class ListsProcessor extends ODataSingleProcessor {
getCallbacks(relatedData, entityType)).expandSelectTree(context.getCurrentExpandSelectTreeNode())
.build();
result.setInlineProperties(inlineProperties);
- return result;
}
+ return result;
} catch (final ODataException e) {
throw new ODataApplicationException(e.getLocalizedMessage(), Locale.ROOT, e);
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/4d80947e/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/data/AnnotationsInMemoryDsTest.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/data/AnnotationsInMemoryDsTest.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/data/AnnotationsInMemoryDsTest.java
index 0aaf309..3063004 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/data/AnnotationsInMemoryDsTest.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/data/AnnotationsInMemoryDsTest.java
@@ -17,18 +17,17 @@ package org.apache.olingo.odata2.core.annotation.data;
import java.util.HashMap;
import java.util.Map;
+
import org.apache.olingo.odata2.api.edm.EdmEntitySet;
import org.apache.olingo.odata2.api.edm.EdmEntityType;
import org.apache.olingo.odata2.api.edm.FullQualifiedName;
-import org.apache.olingo.odata2.api.edm.provider.EntityType;
-import org.apache.olingo.odata2.api.exception.ODataApplicationException;
+import org.apache.olingo.odata2.api.edm.provider.EntitySet;
import org.apache.olingo.odata2.api.exception.ODataException;
import org.apache.olingo.odata2.core.annotation.edm.AnnotationEdmProvider;
import org.apache.olingo.odata2.core.annotation.model.Building;
import org.apache.olingo.odata2.core.annotation.model.ModelSharedConstants;
import org.apache.olingo.odata2.core.annotation.model.Photo;
import org.junit.Assert;
-import org.junit.Ignore;
import org.junit.Test;
import org.mockito.Mockito;
@@ -36,7 +35,7 @@ import org.mockito.Mockito;
*
*/
public class AnnotationsInMemoryDsTest {
-
+
private final AnnotationInMemoryDs datasource;
private AnnotationEdmProvider edmProvider;
private static final String DEFAULT_CONTAINER = ModelSharedConstants.CONTAINER_1;
@@ -47,59 +46,55 @@ public class AnnotationsInMemoryDsTest {
edmProvider = new AnnotationEdmProvider(Building.class.getPackage().getName());
}
-
- @Test(expected = ODataApplicationException.class)
- public void invalidEntity() throws Exception {
- EdmEntitySet edmEntitySet = createMockedEdmEntitySet("Building");
-
- datasource.createData(edmEntitySet, this);
- }
+ // @Test(expected = ODataApplicationException.class)
+ // public void invalidEntity() throws Exception {
+ // EdmEntitySet edmEntitySet = createMockedEdmEntitySet("Buildings");
+ //
+ // datasource.createData(edmEntitySet, this);
+ // }
@Test
public void createSimpleEntity() throws Exception {
- EdmEntitySet edmEntitySet = createMockedEdmEntitySet("Building");
-
+ EdmEntitySet edmEntitySet = createMockedEdmEntitySet("Buildings");
+
Building building = new Building();
building.setName("Common Building");
datasource.createData(edmEntitySet, building);
-
+
Map<String, Object> keys = new HashMap<String, Object>();
keys.put("Id", "1");
-
+
Building read = (Building) datasource.readData(edmEntitySet, keys);
Assert.assertEquals("Common Building", read.getName());
}
@Test
public void createEntityTwoKeys() throws Exception {
- EdmEntitySet edmEntitySet = createMockedEdmEntitySet("Photo");
-
+ EdmEntitySet edmEntitySet = createMockedEdmEntitySet("Photos");
+
Photo photo = new Photo();
photo.setName("BigPicture");
photo.setType("PNG");
photo.setImageUri("https://localhost/image.png");
photo.setImageType("image/png");
datasource.createData(edmEntitySet, photo);
-
+
Map<String, Object> keys = new HashMap<String, Object>();
-// keys.put("ImageFormat", "PNG");
-// keys.put("Name", "BigPicture");
- keys.put("Name", "1");
- keys.put("ImageFormat", "2");
-
+ keys.put("ImageFormat", "PNG");
+ keys.put("Name", "BigPicture");
+
Photo read = (Photo) datasource.readData(edmEntitySet, keys);
-// Assert.assertEquals("BigPicture", read.getName());
- Assert.assertEquals("1", read.getName());
- Assert.assertEquals("2", read.getType());
+ Assert.assertEquals("BigPicture", read.getName());
+ Assert.assertEquals("PNG", read.getType());
Assert.assertEquals("image/png", read.getImageType());
Assert.assertEquals("https://localhost/image.png", read.getImageUri());
}
@Test
-// @Ignore("Rethink update method")
+ // @Ignore("Rethink update method")
public void createAndUpdateEntityTwoKeys() throws Exception {
- EdmEntitySet edmEntitySet = createMockedEdmEntitySet("Photo");
-
+ EdmEntitySet edmEntitySet = createMockedEdmEntitySet("Photos");
+
Photo photo = new Photo();
final String nameKeyValue = "BigPicture";
final String typeKeyValue = "PNG";
@@ -108,34 +103,33 @@ public class AnnotationsInMemoryDsTest {
photo.setImageUri("https://localhost/image.png");
photo.setImageType("image/png");
datasource.createData(edmEntitySet, photo);
-
+
Map<String, Object> keys = new HashMap<String, Object>();
keys.put("Name", "1");
keys.put("ImageFormat", "2");
-
+
Photo read = (Photo) datasource.readData(edmEntitySet, keys);
Assert.assertEquals("1", read.getName());
Assert.assertEquals("2", read.getType());
Assert.assertEquals("image/png", read.getImageType());
Assert.assertEquals("https://localhost/image.png", read.getImageUri());
-
// update
Photo updatedPhoto = new Photo();
-// updatedPhoto.setName(nameKeyValue);
-// updatedPhoto.setType(typeKeyValue);
+ // updatedPhoto.setName(nameKeyValue);
+ // updatedPhoto.setType(typeKeyValue);
updatedPhoto.setName("1");
updatedPhoto.setType("2");
updatedPhoto.setImageUri("https://localhost/image.jpg");
updatedPhoto.setImageType("image/jpg");
datasource.updateData(edmEntitySet, updatedPhoto);
-
+
Map<String, Object> updatedKeys = new HashMap<String, Object>();
-// updatedKeys.put("Name", nameKeyValue);
-// updatedKeys.put("ImageFormat", typeKeyValue);
+ // updatedKeys.put("Name", nameKeyValue);
+ // updatedKeys.put("ImageFormat", typeKeyValue);
updatedKeys.put("Name", "1");
updatedKeys.put("ImageFormat", "2");
-
+
Photo readUpdated = (Photo) datasource.readData(edmEntitySet, updatedKeys);
Assert.assertEquals("1", readUpdated.getName());
Assert.assertEquals("2", readUpdated.getType());
@@ -144,14 +138,15 @@ public class AnnotationsInMemoryDsTest {
}
private EdmEntitySet createMockedEdmEntitySet(String entitySetName) throws ODataException {
-// EntitySet entitySet = edmProvider.getEntitySet(DEFAULT_CONTAINER, entitySetName);
- EntityType entityType = edmProvider.getEntityType(new FullQualifiedName(DEFAULT_NAMESPACE, entitySetName));
-
+ EntitySet entitySet = edmProvider.getEntitySet(DEFAULT_CONTAINER, entitySetName);
+ FullQualifiedName entityType = entitySet.getEntityType();
+
EdmEntitySet edmEntitySet = Mockito.mock(EdmEntitySet.class);
+ Mockito.when(edmEntitySet.getName()).thenReturn(entitySetName);
EdmEntityType edmEntityType = Mockito.mock(EdmEntityType.class);
Mockito.when(edmEntitySet.getEntityType()).thenReturn(edmEntityType);
Mockito.when(edmEntityType.getName()).thenReturn(entityType.getName());
-
+
return edmEntitySet;
}
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/4d80947e/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProviderTest.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProviderTest.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProviderTest.java
index 4d1a6b7..b772d6c 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProviderTest.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProviderTest.java
@@ -86,7 +86,7 @@ public class AnnotationEdmProviderTest {
final List<PropertyRef> employeeKeys = employee.getKey().getKeys();
assertEquals(1, employeeKeys.size());
assertEquals("EmployeeId", employeeKeys.get(0).getName());
- assertEquals(4, employee.getProperties().size());
+ assertEquals(6, employee.getProperties().size());
assertEquals(3, employee.getNavigationProperties().size());
List<Schema> schemas = localAep.getSchemas();
@@ -165,7 +165,7 @@ public class AnnotationEdmProviderTest {
private void validateAssociation(Association association) {
String name = association.getName();
- if(name.equals("RoomEmployees")) {
+ if(name.equals("r_Employee-r_Room")) {
validateAssociation(association,
"r_Room", EdmMultiplicity.ONE, defaultFqn("Room"),
"r_Employee", EdmMultiplicity.MANY, defaultFqn("Employee"));
@@ -176,8 +176,8 @@ public class AnnotationEdmProviderTest {
} else if(name.equals("ManagerEmployees")) {
validateAssociation(association,
"r_Manager", EdmMultiplicity.ONE, defaultFqn("Manager"),
- "r_Employees", EdmMultiplicity.MANY, defaultFqn("Employee"));
- } else if(name.equals("r_Employee-r_Team")) {
+ "r_Employee", EdmMultiplicity.MANY, defaultFqn("Employee"));
+ } else if(name.equals("TeamEmployees")) {
validateAssociation(association,
"r_Team", EdmMultiplicity.ONE, defaultFqn("Team"),
"r_Employee", EdmMultiplicity.MANY, defaultFqn("Employee"));
@@ -227,16 +227,16 @@ public class AnnotationEdmProviderTest {
final List<PropertyRef> employeeKeys = employee.getKey().getKeys();
assertEquals(1, employeeKeys.size());
assertEquals("EmployeeId", employeeKeys.get(0).getName());
- assertEquals(4, employee.getProperties().size());
+ assertEquals(6, employee.getProperties().size());
assertEquals(3, employee.getNavigationProperties().size());
for (NavigationProperty navigationProperty : employee.getNavigationProperties()) {
if (navigationProperty.getName().equals("ne_Manager")) {
- validateNavProperty(navigationProperty, "ManagerEmployees", "r_Employees", "r_Manager");
+ validateNavProperty(navigationProperty, "ManagerEmployees", "r_Employee", "r_Manager");
} else if (navigationProperty.getName().equals("ne_Team")) {
- validateNavProperty(navigationProperty, "r_Employee-r_Team", "r_Employee", "r_Team");
+ validateNavProperty(navigationProperty, "TeamEmployees", "r_Employee", "r_Team");
} else if (navigationProperty.getName().equals("ne_Room")) {
- validateNavProperty(navigationProperty, "RoomEmployees", "r_Employee", "r_Room");
+ validateNavProperty(navigationProperty, "r_Employee-r_Room", "r_Employee", "r_Room");
} else {
fail("Got unexpected navigation property with name '" + navigationProperty.getName() + "'.");
}
@@ -254,7 +254,7 @@ public class AnnotationEdmProviderTest {
assertEquals(1, team.getProperties().size());
assertEquals(1, team.getNavigationProperties().size());
NavigationProperty navigationProperty= team.getNavigationProperties().get(0);
- validateNavProperty(navigationProperty, "r_Employee-r_Team", "r_Team", "r_Employee");
+ validateNavProperty(navigationProperty, "TeamEmployees", "r_Team", "r_Employee");
}
@Test
@@ -335,7 +335,7 @@ public class AnnotationEdmProviderTest {
for (NavigationProperty navigationProperty : navigationProperties) {
if(navigationProperty.getName().equals("nr_Employees")) {
- validateNavProperty(navigationProperty, "RoomEmployees", "r_Room", "r_Employee");
+ validateNavProperty(navigationProperty, "r_Employee-r_Room", "r_Room", "r_Employee");
} else if(navigationProperty.getName().equals("nr_Building")) {
validateNavProperty(navigationProperty, "BuildingRooms", "r_Room", "r_Building");
} else {
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/4d80947e/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Building.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Building.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Building.java
index f1a3fa9..15cd3ae 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Building.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Building.java
@@ -21,32 +21,34 @@ package org.apache.olingo.odata2.core.annotation.model;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
-import org.apache.olingo.odata2.api.annotation.edm.NavigationEnd;
import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
/**
*
*/
-@EdmEntityType(name="Building", namespace=ModelSharedConstants.NAMESPACE_1)
+@EdmEntityType(name = "Building", namespace = ModelSharedConstants.NAMESPACE_1)
@EdmEntitySet(name = "Buildings")
public class Building {
@EdmKey
- @EdmProperty(type = EdmSimpleTypeKind.String)
+ @EdmProperty(type = EdmSimpleTypeKind.Int32)
private String id;
@EdmProperty
private String name;
+ @EdmProperty(name = "Image", type = EdmSimpleTypeKind.Binary)
private byte[] image;
- @EdmNavigationProperty(name="nb_rooms", association="BuildingRooms",
- to = @NavigationEnd(role = "r_Room", entitySet=Room.class, multiplicity = EdmMultiplicity.MANY))
+ @EdmNavigationProperty(name = "nb_Rooms", toType = Room.class,
+ association = "BuildingRooms", toMultiplicity = EdmMultiplicity.MANY)
private List<Room> rooms = new ArrayList<Room>();
+ public Building() {}
+
public String getId() {
return id;
}
@@ -77,10 +79,7 @@ public class Building {
@Override
public int hashCode() {
- if(id == null) {
- return 0;
- }
- return id.hashCode();
+ return id == null ? 0 : id.hashCode();
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/4d80947e/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Employee.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Employee.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Employee.java
index a384689..dc97c68 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Employee.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Employee.java
@@ -20,53 +20,54 @@ package org.apache.olingo.odata2.core.annotation.model;
import java.text.DateFormat;
import java.util.Calendar;
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
+import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceContent;
+import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceMimeType;
import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
-import org.apache.olingo.odata2.api.annotation.edm.NavigationEnd;
-import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
/**
*
*/
-@EdmEntityType(name="Employee", namespace=ModelSharedConstants.NAMESPACE_1)
+@EdmEntityType(name = "Employee", namespace = ModelSharedConstants.NAMESPACE_1)
@EdmEntitySet(name = "Employees")
public class Employee {
private static int counter = 1;
@EdmKey
- @EdmProperty(name="EmployeeId", type = EdmSimpleTypeKind.Int32)
- private int employeeId;
- @EdmProperty(name="EmployeeName")
+ @EdmProperty(name = "EmployeeId", type = EdmSimpleTypeKind.String)
+ private String employeeId;
+ @EdmProperty(name = "EmployeeName")
private String employeeName;
@EdmProperty
private int age;
- @EdmNavigationProperty(name="ne_Manager", association="ManagerEmployees",
- from = @NavigationEnd(role="r_Employees", entitySet=Employee.class, multiplicity=EdmMultiplicity.MANY))//,
-// to = @NavigationEnd(type = "Manager"))
+ @EdmNavigationProperty(name = "ne_Manager", association = "ManagerEmployees")
private Manager manager;
- @EdmNavigationProperty(name = "ne_Team")
+ @EdmNavigationProperty(name = "ne_Team", association = "TeamEmployees")
private Team team;
- @EdmNavigationProperty(name = "ne_Room", association = "RoomEmployees",
- from = @NavigationEnd(multiplicity = EdmMultiplicity.MANY))
+ @EdmNavigationProperty(name = "ne_Room")
private Room room;
+ @EdmMediaResourceMimeType
private String imageType;
+ @EdmMediaResourceContent
private byte[] image;
+ @EdmProperty(name = "ImageUrl")
private String imageUrl;
+ @EdmProperty(name = "EntryDate", type = EdmSimpleTypeKind.DateTime)
private Calendar entryDate;
- @EdmProperty(name="Location")
+ @EdmProperty(name = "Location")
private Location location;
- public Employee(final int employeeId, final String name) {
+ public Employee(final String employeeId, final String name) {
this.employeeId = employeeId;
setEmployeeName(name);
}
public String getId() {
- return Integer.toString(employeeId);
+ return employeeId;
}
public void setEmployeeName(final String employeeName) {
@@ -154,7 +155,10 @@ public class Employee {
@Override
public int hashCode() {
- return employeeId;
+ if (employeeId == null) {
+ return 0;
+ }
+ return employeeId.hashCode();
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/4d80947e/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Manager.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Manager.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Manager.java
index fcfbf7d..7785d3c 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Manager.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Manager.java
@@ -20,24 +20,24 @@ package org.apache.olingo.odata2.core.annotation.model;
import java.util.ArrayList;
import java.util.List;
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
-import org.apache.olingo.odata2.api.annotation.edm.NavigationEnd;
+import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
/**
*
*/
-@EdmEntityType(name = "Manager", namespace = ModelSharedConstants.NAMESPACE_1)
+@EdmEntityType(name = "Manager", namespace = ModelSharedConstants.NAMESPACE_1)
@EdmEntitySet(name = "Managers")
public class Manager extends Employee {
@EdmNavigationProperty(name = "nm_Employees", association = "ManagerEmployees",
- to = @NavigationEnd(role = "r_Employees", entitySet = Employee.class))
+ toMultiplicity = EdmMultiplicity.MANY)
private List<Employee> employees = new ArrayList<Employee>();
- public Manager(final int id, final String name) {
+ public Manager(final String id, final String name) {
super(id, name);
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/4d80947e/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Room.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Room.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Room.java
index 14319ef..7c9e486 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Room.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Room.java
@@ -17,13 +17,11 @@ package org.apache.olingo.odata2.core.annotation.model;
import java.util.ArrayList;
import java.util.List;
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
-import org.apache.olingo.odata2.api.annotation.edm.NavigationEnd;
-import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
/**
*
@@ -36,12 +34,9 @@ public class Room extends RefBase {
private Integer seats;
@EdmProperty
private Integer version;
- @EdmNavigationProperty(name = "nr_Building", association = "BuildingRooms",
- from = @NavigationEnd(role = "r_Room", multiplicity = EdmMultiplicity.MANY))
+ @EdmNavigationProperty(name = "nr_Building", association = "BuildingRooms")
private Building building;
- @EdmNavigationProperty(name = "nr_Employees", association = "RoomEmployees",
-// from = @NavigationEnd(role = "r_Room", entitySet = Room.class, multiplicity = EdmMultiplicity.ONE),
- to = @NavigationEnd(entitySet = Employee.class, multiplicity = EdmMultiplicity.MANY))
+ @EdmNavigationProperty(name = "nr_Employees")
private List<Employee> employees = new ArrayList<Employee>();
public Room(final int id, final String name) {
@@ -84,7 +79,7 @@ public class Room extends RefBase {
@Override
public boolean equals(final Object obj) {
return this == obj
- || obj != null && getClass() == obj.getClass() && id == ((Room) obj).id;
+ || obj != null && getClass() == obj.getClass() && id == ((Room) obj).id;
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/4d80947e/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Team.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Team.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Team.java
index e24c28b..6e3463b 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Team.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Team.java
@@ -20,31 +20,29 @@ package org.apache.olingo.odata2.core.annotation.model;
import java.util.ArrayList;
import java.util.List;
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
-import org.apache.olingo.odata2.api.annotation.edm.NavigationEnd;
import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
/**
*
*/
-@EdmEntityType(name="Team", namespace = ModelSharedConstants.NAMESPACE_1)
+@EdmEntityType(name = "Team", namespace = ModelSharedConstants.NAMESPACE_1)
@EdmEntitySet(name = "Teams")
public class Team extends RefBase {
@EdmProperty(type = EdmSimpleTypeKind.Boolean)
private Boolean isScrumTeam;
- @EdmNavigationProperty(name = "ne_Teams",
- to = @NavigationEnd(entitySet = Employee.class, multiplicity = EdmMultiplicity.MANY))
+ @EdmNavigationProperty(name = "nt_Employees", association = "TeamEmployees", toMultiplicity = EdmMultiplicity.MANY)
private List<Employee> employees = new ArrayList<Employee>();
public Team() {
super(-1, null);
}
-
+
public Team(final int id, final String name) {
super(id, name);
}
@@ -56,7 +54,7 @@ public class Team extends RefBase {
public void setScrumTeam(final Boolean isScrumTeam) {
this.isScrumTeam = isScrumTeam;
}
-
+
public void addEmployee(Employee e) {
this.employees.add(e);
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/4d80947e/odata2-edm-annotation/edm-annotation-webref/pom.xml
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/pom.xml b/odata2-edm-annotation/edm-annotation-webref/pom.xml
index cfc7f92..9f4e99f 100644
--- a/odata2-edm-annotation/edm-annotation-webref/pom.xml
+++ b/odata2-edm-annotation/edm-annotation-webref/pom.xml
@@ -100,16 +100,6 @@ the License. -->
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.1</version>
</dependency>
- <dependency>
- <groupId>org.glassfish.jersey.containers</groupId>
- <artifactId>jersey-container-servlet</artifactId>
- <version>2.0</version>
- </dependency>
- <dependency>
- <groupId>org.glassfish.jersey.core</groupId>
- <artifactId>jersey-client</artifactId>
- <version>2.0</version>
- </dependency>
</dependencies>
<profiles>
[21/52] git commit: Refactored Edm* annotations
Posted by mi...@apache.org.
Refactored Edm* annotations
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/c6791509
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/c6791509
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/c6791509
Branch: refs/heads/master
Commit: c679150943a681f106c571c0ce94f5946ba303df
Parents: d641fd1
Author: Michael Bolz <mi...@apache.org>
Authored: Thu Nov 14 06:30:53 2013 +0100
Committer: Michael Bolz <mi...@apache.org>
Committed: Thu Nov 14 06:32:26 2013 +0100
----------------------------------------------------------------------
.../annotation/edm/AnnotationEdmProvider.java | 84 ++++++++++++++------
.../core/annotation/edm/AnnotationHelper.java | 13 ++-
.../processor/json/EdmAnnotationSerializer.java | 8 +-
.../odata2/core/annotation/model/Building.java | 9 ++-
.../odata2/core/annotation/model/City.java | 4 +-
.../odata2/core/annotation/model/Employee.java | 9 ++-
.../odata2/core/annotation/model/Location.java | 4 +-
.../odata2/core/annotation/model/Manager.java | 9 ++-
.../annotation/model/ModelSharedConstants.java | 2 +-
.../odata2/core/annotation/model/Room.java | 13 +--
.../odata2/core/annotation/model/Team.java | 11 +--
.../odata2/ref/annotation/model/Building.java | 9 ++-
.../odata2/ref/annotation/model/City.java | 4 +-
.../odata2/ref/annotation/model/Employee.java | 15 ++--
.../odata2/ref/annotation/model/Location.java | 4 +-
.../odata2/ref/annotation/model/Manager.java | 9 ++-
.../odata2/ref/annotation/model/Photo.java | 5 +-
.../odata2/ref/annotation/model/Room.java | 15 ++--
.../odata2/ref/annotation/model/Team.java | 9 ++-
.../api/annotation/edm/EdmComplexEntity.java | 31 --------
.../api/annotation/edm/EdmComplexType.java | 31 ++++++++
.../odata2/api/annotation/edm/EdmEntitySet.java | 31 ++++++++
.../api/annotation/edm/EdmEntityType.java | 3 -
.../odata2/api/annotation/edm/EdmFacets.java | 4 +-
.../api/annotation/edm/EdmFunctionImport.java | 49 ++++++++++++
.../edm/EdmFunctionImportParameter.java | 33 ++++++++
.../annotation/edm/EdmNavigationProperty.java | 4 +-
.../odata2/api/annotation/edm/EdmProperty.java | 3 -
.../api/annotation/edm/NavigationEnd.java | 3 +-
29 files changed, 290 insertions(+), 138 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c6791509/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java
index 6fb69b7..4ce8563 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java
@@ -27,7 +27,8 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import org.apache.olingo.odata2.api.annotation.edm.EdmComplexEntity;
+import org.apache.olingo.odata2.api.annotation.edm.EdmComplexType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceContent;
@@ -74,6 +75,7 @@ public class AnnotationEdmProvider extends EdmProvider {
private final Map<String, ContainerBuilder> containerName2ContainerBuilder = new HashMap<String, ContainerBuilder>();
private final Map<String, Schema> namespace2Schema = new HashMap<String, Schema>();
private EntityContainer defaultContainer;
+ private String DEFAULT_CONTAINER_NAME = "DefaultContainer";
public AnnotationEdmProvider(Collection<Class<?>> annotatedClasses) {
@@ -240,7 +242,7 @@ public class AnnotationEdmProvider extends EdmProvider {
if (et != null) {
updateSchema(aClass, et);
}
- EdmComplexEntity ect = aClass.getAnnotation(EdmComplexEntity.class);
+ EdmComplexType ect = aClass.getAnnotation(EdmComplexType.class);
if (ect != null) {
updateSchema(aClass, ect);
}
@@ -258,7 +260,7 @@ public class AnnotationEdmProvider extends EdmProvider {
b.addAssociations(typeBuilder.buildAssociations());
}
- private void updateSchema(Class<?> aClass, EdmComplexEntity et) {
+ private void updateSchema(Class<?> aClass, EdmComplexType et) {
String namespace = et.namespace();
SchemaBuilder b = namespace2SchemaBuilder.get(namespace);
if (b == null) {
@@ -270,22 +272,33 @@ public class AnnotationEdmProvider extends EdmProvider {
}
private void handleEntityContainer(Class<?> aClass) {
- EdmEntityType entity = aClass.getAnnotation(EdmEntityType.class);
- if (entity != null && !entity.entitySetName().isEmpty()) {
- String containerName = entity.container();
+ EdmEntityType entityType = aClass.getAnnotation(EdmEntityType.class);
+ if (entityType != null) {
+ String containerName = getContainerName(entityType);
ContainerBuilder builder = containerName2ContainerBuilder.get(containerName);
if (builder == null) {
- builder = ContainerBuilder.init(entity.namespace(), containerName);
+ builder = ContainerBuilder.init(entityType.namespace(), containerName);
containerName2ContainerBuilder.put(containerName, builder);
}
- builder.addEntitySet(createEntitySet(entity));
+ EdmEntitySet entitySet = aClass.getAnnotation(EdmEntitySet.class);
+ if(entitySet != null) {
+ FullQualifiedName typeName = createFqnForEntityType(aClass, entityType);
+ builder.addEntitySet(createEntitySet(typeName, entitySet));
+ }
}
}
- private EntitySet createEntitySet(EdmEntityType entity) {
- FullQualifiedName typeName = new FullQualifiedName(entity.namespace(), entity.name());
+ private EntitySet createEntitySet(FullQualifiedName typeName, EdmEntitySet entitySet) {
+ return new EntitySet().setName(entitySet.name()).setEntityType(typeName);
+ }
- return new EntitySet().setName(entity.entitySetName()).setEntityType(typeName);
+ private FullQualifiedName createFqnForEntityType(Class<?> annotatedClass, EdmEntityType entityType) {
+ String name = entityType.name();
+ if(name.isEmpty()) {
+ return new FullQualifiedName(entityType.namespace(), annotatedClass.getSimpleName());
+ } else {
+ return new FullQualifiedName(entityType.namespace(), entityType.name());
+ }
}
private void finish() {
@@ -309,6 +322,10 @@ public class AnnotationEdmProvider extends EdmProvider {
}
}
+ private String getContainerName(EdmEntityType entity) {
+ return DEFAULT_CONTAINER_NAME;
+ }
+
//
//
//
@@ -333,7 +350,7 @@ public class AnnotationEdmProvider extends EdmProvider {
return new TypeBuilder(entity.namespace(), entity.name()).withClass(aClass);
}
- public static TypeBuilder init(EdmComplexEntity entity, Class<?> aClass) {
+ public static TypeBuilder init(EdmComplexType entity, Class<?> aClass) {
return new TypeBuilder(entity.namespace(), entity.name()).withClass(aClass);
}
@@ -465,7 +482,7 @@ public class AnnotationEdmProvider extends EdmProvider {
cp.setName(entityName);
// settings from related complex entity
- EdmComplexEntity ece = field.getType().getAnnotation(EdmComplexEntity.class);
+ EdmComplexType ece = field.getType().getAnnotation(EdmComplexType.class);
String complexEntityNamespace = ece.namespace();
if (complexEntityNamespace.isEmpty()) {
complexEntityNamespace = defaultNamespace;
@@ -482,7 +499,7 @@ public class AnnotationEdmProvider extends EdmProvider {
entityName = getCanonicalName(field);
}
navProp.setName(entityName);
- navProp.setRelationship(new FullQualifiedName(namespace, enp.relationship()));
+ navProp.setRelationship(new FullQualifiedName(namespace, enp.association()));
//
NavigationEnd from = enp.from();
String fromRole = from.role();
@@ -547,30 +564,34 @@ public class AnnotationEdmProvider extends EdmProvider {
}
private Association createAssociation(Field field, NavigationProperty navProperty) {
- Association a = new Association();
- a.setName(navProperty.getRelationship().getName());
+ Association association = new Association();
+ association.setName(navProperty.getRelationship().getName());
EdmNavigationProperty navigation = field.getAnnotation(EdmNavigationProperty.class);
NavigationEnd from = navigation.from();
AssociationEnd fromEnd = new AssociationEnd();
fromEnd.setRole(navProperty.getFromRole());
- String typeName = from.type();
+ String typeName = extractEntitTypeName(from);
if (typeName.isEmpty()) {
- typeName = name;
+ Class<?> fromClass = field.getDeclaringClass();
+ EdmEntityType entityType = fromClass.getAnnotation(EdmEntityType.class);
+ typeName = entityType.name();
}
fromEnd.setType(new FullQualifiedName(namespace, typeName));
fromEnd.setMultiplicity(from.multiplicity());
- a.setEnd1(fromEnd);
+ association.setEnd1(fromEnd);
NavigationEnd to = navigation.to();
AssociationEnd toEnd = new AssociationEnd();
toEnd.setRole(navProperty.getToRole());
final FullQualifiedName toFqn;
- if (to.type().isEmpty()) {
+ String toTypeName = extractEntitTypeName(to);
+ if (toTypeName.isEmpty()) {
Class<?> toClass = field.getType();
- toFqn = new FullQualifiedName(namespace, toClass.getSimpleName());
+ EdmEntityType entityType = toClass.getAnnotation(EdmEntityType.class);
+ toFqn = new FullQualifiedName(namespace, entityType.name());
} else {
- toFqn = new FullQualifiedName(namespace, to.type());
+ toFqn = new FullQualifiedName(namespace, toTypeName);
}
toEnd.setType(toFqn);
@@ -584,9 +605,9 @@ public class AnnotationEdmProvider extends EdmProvider {
toEnd.setMultiplicity(toMultiplicity);
}
- a.setEnd2(toEnd);
+ association.setEnd2(toEnd);
- return a;
+ return association;
}
private String getCanonicalName(Field field) {
@@ -594,10 +615,22 @@ public class AnnotationEdmProvider extends EdmProvider {
}
private boolean isAnnotatedEntity(Class<?> clazz) {
- boolean isComplexEntity = clazz.getAnnotation(EdmComplexEntity.class) != null;
+ boolean isComplexEntity = clazz.getAnnotation(EdmComplexType.class) != null;
boolean isEntity = clazz.getAnnotation(EdmEntityType.class) != null;
return isComplexEntity || isEntity;
}
+
+ private String extractEntitTypeName(NavigationEnd navEnd) {
+ Class<?> entityTypeClass = navEnd.entitySet();
+ if(entityTypeClass == Object.class) {
+ return "";
+ }
+ EdmEntityType type = entityTypeClass.getAnnotation(EdmEntityType.class);
+ if(type == null) {
+ return "";
+ }
+ return type.name();
+ }
}
static class SchemaBuilder {
@@ -745,6 +778,7 @@ public class AnnotationEdmProvider extends EdmProvider {
return ec;
}
+
private String getEntitySetName(AssociationEnd end) {
for (EntitySet entitySet : entitySets) {
if(entitySet.getEntityType().equals(end.getType())) {
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c6791509/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java
index 1e1d31b..d43f8c9 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java
@@ -23,10 +23,9 @@ import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import org.apache.olingo.odata2.api.annotation.edm.EdmComplexEntity;
+import org.apache.olingo.odata2.api.annotation.edm.EdmComplexType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
@@ -35,7 +34,6 @@ import org.apache.olingo.odata2.api.edm.EdmLiteralKind;
import org.apache.olingo.odata2.api.edm.EdmSimpleTypeException;
import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
import org.apache.olingo.odata2.api.exception.ODataException;
-import org.apache.olingo.odata2.core.annotation.ds.DataStore;
import org.apache.olingo.odata2.core.exception.ODataRuntimeException;
/**
@@ -109,7 +107,7 @@ public class AnnotationHelper {
for (Field sourcField : sourceFields) {
EdmNavigationProperty sourceNav = sourcField.getAnnotation(EdmNavigationProperty.class);
EdmNavigationProperty targetNav = targetField.getAnnotation(EdmNavigationProperty.class);
- if (sourceNav.relationship().equals(targetNav.relationship())) {
+ if (sourceNav.association().equals(targetNav.association())) {
return targetField;
}
}
@@ -388,8 +386,9 @@ public class AnnotationHelper {
return false;
} else {
final boolean isEntity = null != clazz.getAnnotation(EdmEntityType.class);
- final boolean isComplexEntity = null != clazz.getAnnotation(EdmComplexEntity.class);
- return isEntity || isComplexEntity;
+ final boolean isEntitySet = null != clazz.getAnnotation(EdmEntitySet.class);
+ final boolean isComplexEntity = null != clazz.getAnnotation(EdmComplexType.class);
+ return isEntity || isComplexEntity || isEntitySet;
}
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c6791509/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/json/EdmAnnotationSerializer.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/json/EdmAnnotationSerializer.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/json/EdmAnnotationSerializer.java
index 7dceba9..6e1d8ea 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/json/EdmAnnotationSerializer.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/json/EdmAnnotationSerializer.java
@@ -25,8 +25,8 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
-import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
@@ -122,12 +122,12 @@ public class EdmAnnotationSerializer {
private boolean writeEdmNavigationProperty(Object entity, JsonWriter json, Field field)
throws IllegalArgumentException, IllegalAccessException {
EdmNavigationProperty navProperty = field.getAnnotation(EdmNavigationProperty.class);
- EdmEntityType entityType = entity.getClass().getAnnotation(EdmEntityType.class);
+ EdmEntitySet entitySet = entity.getClass().getAnnotation(EdmEntitySet.class);
if (navProperty != null) {
field.setAccessible(true);
Object keyValue = extractEdmKey(entity);
- json.writeStringProperty("uri", baseUri + entityType.entitySetName() + "('" + keyValue.toString() + "')"
- + "/" + navProperty.relationship());
+ json.writeStringProperty("uri", baseUri + entitySet.name() + "('" + keyValue.toString() + "')"
+ + "/" + navProperty.association());
return true;
}
return false;
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c6791509/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Building.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Building.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Building.java
index 9427151..2abf4e3 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Building.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Building.java
@@ -21,6 +21,7 @@ package org.apache.olingo.odata2.core.annotation.model;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
@@ -33,8 +34,8 @@ import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
/**
*
*/
-@EdmEntityType(name="Building", namespace=ModelSharedConstants.NAMESPACE_1,
- entitySetName = "Buildings", container="Container1")
+@EdmEntityType(name="Building", namespace=ModelSharedConstants.NAMESPACE_1)
+@EdmEntitySet(name = "Buildings")
public class Building {
@EdmKey
@EdmProperty(type = EdmSimpleTypeKind.String)
@@ -42,8 +43,8 @@ public class Building {
@EdmProperty
private String name;
private byte[] image;
- @EdmNavigationProperty(name="nb_rooms", relationship="BuildingRooms",
- to = @NavigationEnd(role = "r_Room", type="Room", multiplicity = EdmMultiplicity.MANY))
+ @EdmNavigationProperty(name="nb_rooms", association="BuildingRooms",
+ to = @NavigationEnd(role = "r_Room", entitySet=Room.class, multiplicity = EdmMultiplicity.MANY))
private List<Room> rooms = new ArrayList<Room>();
public Building() {
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c6791509/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/City.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/City.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/City.java
index c063ffe..7b866a3 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/City.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/City.java
@@ -18,14 +18,14 @@
******************************************************************************/
package org.apache.olingo.odata2.core.annotation.model;
-import org.apache.olingo.odata2.api.annotation.edm.EdmComplexEntity;
+import org.apache.olingo.odata2.api.annotation.edm.EdmComplexType;
import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
/**
*
*/
-@EdmComplexEntity(name="c_City", namespace = ModelSharedConstants.NAMESPACE_1)
+@EdmComplexType(name="c_City", namespace = ModelSharedConstants.NAMESPACE_1)
public class City {
@EdmProperty
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c6791509/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Employee.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Employee.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Employee.java
index 07a7dcb..6eda19c 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Employee.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Employee.java
@@ -20,6 +20,7 @@ package org.apache.olingo.odata2.core.annotation.model;
import java.text.DateFormat;
import java.util.Calendar;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
@@ -32,8 +33,8 @@ import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
/**
*
*/
-@EdmEntityType(name="Employee", namespace=ModelSharedConstants.NAMESPACE_1,
- entitySetName = "Employees", container=ModelSharedConstants.CONTAINER_1)
+@EdmEntityType(name="Employee", namespace=ModelSharedConstants.NAMESPACE_1)
+@EdmEntitySet(name = "Employees")
public class Employee {
private static int counter = 1;
@EdmKey
@@ -43,8 +44,8 @@ public class Employee {
private String employeeName;
@EdmProperty
private int age;
- @EdmNavigationProperty(name="ne_Manager", relationship="ManagerEmployees",
- from = @NavigationEnd(role="r_Employees", multiplicity = EdmMultiplicity.MANY))//,
+ @EdmNavigationProperty(name="ne_Manager", association="ManagerEmployees",
+ from = @NavigationEnd(role="r_Employees", entitySet=Employee.class, multiplicity=EdmMultiplicity.MANY))//,
// to = @NavigationEnd(type = "Manager"))
private Manager manager;
private Team team;
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c6791509/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Location.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Location.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Location.java
index 242b4cf..7f3f082 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Location.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Location.java
@@ -18,14 +18,14 @@
******************************************************************************/
package org.apache.olingo.odata2.core.annotation.model;
-import org.apache.olingo.odata2.api.annotation.edm.EdmComplexEntity;
+import org.apache.olingo.odata2.api.annotation.edm.EdmComplexType;
import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
/**
*
*/
-@EdmComplexEntity(name = "c_Location", namespace = ModelSharedConstants.NAMESPACE_1)
+@EdmComplexType(name = "c_Location", namespace = ModelSharedConstants.NAMESPACE_1)
public class Location {
@EdmProperty
private String country;
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c6791509/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Manager.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Manager.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Manager.java
index 187d4f8..fcfbf7d 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Manager.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Manager.java
@@ -20,6 +20,7 @@ package org.apache.olingo.odata2.core.annotation.model;
import java.util.ArrayList;
import java.util.List;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
@@ -28,12 +29,12 @@ import org.apache.olingo.odata2.api.annotation.edm.NavigationEnd;
/**
*
*/
-@EdmEntityType(name = "Manager", namespace = ModelSharedConstants.NAMESPACE_1,
- entitySetName = "Managers", container = ModelSharedConstants.CONTAINER_1)
+@EdmEntityType(name = "Manager", namespace = ModelSharedConstants.NAMESPACE_1)
+@EdmEntitySet(name = "Managers")
public class Manager extends Employee {
- @EdmNavigationProperty(name = "nm_Employees", relationship = "ManagerEmployees",
- to = @NavigationEnd(role = "r_Employees", type = "Employee"))
+ @EdmNavigationProperty(name = "nm_Employees", association = "ManagerEmployees",
+ to = @NavigationEnd(role = "r_Employees", entitySet = Employee.class))
private List<Employee> employees = new ArrayList<Employee>();
public Manager(final int id, final String name) {
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c6791509/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/ModelSharedConstants.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/ModelSharedConstants.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/ModelSharedConstants.java
index f87165f..1d44498 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/ModelSharedConstants.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/ModelSharedConstants.java
@@ -21,5 +21,5 @@ package org.apache.olingo.odata2.core.annotation.model;
public interface ModelSharedConstants {
String NAMESPACE_1 = "RefScenario";
- String CONTAINER_1 = "Container1";
+ String CONTAINER_1 = "DefaultContainer";
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c6791509/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Room.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Room.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Room.java
index 3628ac8..2f6be68 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Room.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Room.java
@@ -17,6 +17,7 @@ package org.apache.olingo.odata2.core.annotation.model;
import java.util.ArrayList;
import java.util.List;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
@@ -27,20 +28,20 @@ import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
/**
*
*/
-@EdmEntityType(name = "Room", namespace = ModelSharedConstants.NAMESPACE_1,
- entitySetName = "Rooms", container = ModelSharedConstants.CONTAINER_1)
+@EdmEntityType(name = "Room", namespace = ModelSharedConstants.NAMESPACE_1)
+@EdmEntitySet(name = "Rooms")
public class Room extends RefBase {
@EdmProperty
private Integer seats;
@EdmProperty
private Integer version;
- @EdmNavigationProperty(name = "nr_Building", relationship = "BuildingRooms",
+ @EdmNavigationProperty(name = "nr_Building", association = "BuildingRooms",
from = @NavigationEnd(role = "r_Room", multiplicity = EdmMultiplicity.MANY))
private Building building;
- @EdmNavigationProperty(name = "nr_Employees", relationship = "RoomEmployees",
- from = @NavigationEnd(role = "r_Room", type = "Room", multiplicity = EdmMultiplicity.ONE),
- to = @NavigationEnd(role = "r_Employees", type = "Employee", multiplicity = EdmMultiplicity.MANY))
+ @EdmNavigationProperty(name = "nr_Employees", association = "RoomEmployees",
+ from = @NavigationEnd(role = "r_Room", entitySet = Room.class, multiplicity = EdmMultiplicity.ONE),
+ to = @NavigationEnd(role = "r_Employees", entitySet = Employee.class, multiplicity = EdmMultiplicity.MANY))
private List<Employee> employees = new ArrayList<Employee>();
public Room(final int id, final String name) {
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c6791509/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Team.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Team.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Team.java
index e3ea0cc..2d37be4 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Team.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Team.java
@@ -20,6 +20,7 @@ package org.apache.olingo.odata2.core.annotation.model;
import java.util.ArrayList;
import java.util.List;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
@@ -31,14 +32,14 @@ import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
/**
*
*/
-@EdmEntityType(name="Team", namespace = ModelSharedConstants.NAMESPACE_1,
- entitySetName = "Teams", container = ModelSharedConstants.CONTAINER_1)
+@EdmEntityType(name="Team", namespace = ModelSharedConstants.NAMESPACE_1)
+@EdmEntitySet(name = "Teams")
public class Team extends RefBase {
@EdmProperty(type = EdmSimpleTypeKind.Boolean)
private Boolean isScrumTeam;
- @EdmNavigationProperty(name = "ne_Teams", relationship="TeamEmployees",
- from = @NavigationEnd(role = "r_Team", type = "Team"),
- to = @NavigationEnd(role = "r_Employees", type = "Employee", multiplicity = EdmMultiplicity.MANY))
+ @EdmNavigationProperty(name = "ne_Teams", association="TeamEmployees",
+ from = @NavigationEnd(role = "r_Team", entitySet = Team.class),
+ to = @NavigationEnd(role = "r_Employees", entitySet = Employee.class, multiplicity = EdmMultiplicity.MANY))
private List<Employee> employees = new ArrayList<Employee>();
public Team() {
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c6791509/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Building.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Building.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Building.java
index 66adb24..488c462 100644
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Building.java
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Building.java
@@ -21,6 +21,7 @@ package org.apache.olingo.odata2.ref.annotation.model;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
@@ -32,8 +33,8 @@ import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
/**
*
*/
-@EdmEntityType(name="Building", namespace=ModelSharedConstants.NAMESPACE_1,
- entitySetName = "Buildings", container="Container1")
+@EdmEntityType(name="Building", namespace=ModelSharedConstants.NAMESPACE_1)
+@EdmEntitySet(name = "Buildings")
public class Building {
@EdmKey
@EdmProperty(type = EdmSimpleTypeKind.Int32)
@@ -41,8 +42,8 @@ public class Building {
@EdmProperty
private String name;
private byte[] image;
- @EdmNavigationProperty(name="nb_rooms", relationship="BuildingRooms",
- to = @NavigationEnd(role = "r_Room", type="Room", multiplicity = EdmMultiplicity.MANY))
+ @EdmNavigationProperty(name="nb_rooms", association="BuildingRooms",
+ to = @NavigationEnd(role = "r_Room", entitySet=Room.class, multiplicity = EdmMultiplicity.MANY))
private List<Room> rooms = new ArrayList<Room>();
public String getId() {
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c6791509/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/City.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/City.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/City.java
index 40e030f..a4d5a56 100644
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/City.java
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/City.java
@@ -18,13 +18,13 @@
******************************************************************************/
package org.apache.olingo.odata2.ref.annotation.model;
-import org.apache.olingo.odata2.api.annotation.edm.EdmComplexEntity;
+import org.apache.olingo.odata2.api.annotation.edm.EdmComplexType;
import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
/**
*
*/
-@EdmComplexEntity(name="c_City", namespace = ModelSharedConstants.NAMESPACE_1)
+@EdmComplexType(name="c_City", namespace = ModelSharedConstants.NAMESPACE_1)
public class City {
@EdmProperty
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c6791509/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Employee.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Employee.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Employee.java
index 5092067..e946a5a 100644
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Employee.java
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Employee.java
@@ -20,6 +20,7 @@ package org.apache.olingo.odata2.ref.annotation.model;
import java.text.DateFormat;
import java.util.Calendar;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
@@ -31,8 +32,8 @@ import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
/**
*
*/
-@EdmEntityType(name="Employee", namespace=ModelSharedConstants.NAMESPACE_1,
- entitySetName = "Employees", container=ModelSharedConstants.CONTAINER_1)
+@EdmEntityType(name="Employee", namespace=ModelSharedConstants.NAMESPACE_1)
+@EdmEntitySet(name= "Employees")
public class Employee {
private static int counter = 1;
@EdmKey
@@ -42,13 +43,13 @@ public class Employee {
private String employeeName;
@EdmProperty
private int age;
- @EdmNavigationProperty(name="ne_Manager", relationship="ManagerEmployees",
- from = @NavigationEnd(role="r_Employees", multiplicity = EdmMultiplicity.MANY))//,
+ @EdmNavigationProperty(name="ne_Manager", association="ManagerEmployees",
+ from = @NavigationEnd(role="r_Employees", entitySet=Manager.class, multiplicity=EdmMultiplicity.MANY))//,
// to = @NavigationEnd(type = "Manager"))
private Manager manager;
- @EdmNavigationProperty(name = "ne_Team", relationship="TeamEmployees",
- from = @NavigationEnd(role = "r_Employees", type = "Employee", multiplicity = EdmMultiplicity.MANY),
- to = @NavigationEnd(role = "r_Team", type = "Team")
+ @EdmNavigationProperty(name = "ne_Team", association="TeamEmployees",
+ from = @NavigationEnd(role = "r_Employees", entitySet = Employee.class, multiplicity = EdmMultiplicity.MANY),
+ to = @NavigationEnd(role = "r_Team", entitySet = Team.class)
)
private Team team;
private Room room;
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c6791509/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Location.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Location.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Location.java
index 809accf..9b0785c 100644
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Location.java
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Location.java
@@ -18,13 +18,13 @@
******************************************************************************/
package org.apache.olingo.odata2.ref.annotation.model;
-import org.apache.olingo.odata2.api.annotation.edm.EdmComplexEntity;
+import org.apache.olingo.odata2.api.annotation.edm.EdmComplexType;
import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
/**
*
*/
-@EdmComplexEntity(name = "c_Location", namespace = ModelSharedConstants.NAMESPACE_1)
+@EdmComplexType(name = "c_Location", namespace = ModelSharedConstants.NAMESPACE_1)
public class Location {
@EdmProperty
private String country;
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c6791509/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Manager.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Manager.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Manager.java
index 135753b..0fcd152 100644
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Manager.java
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Manager.java
@@ -20,6 +20,7 @@ package org.apache.olingo.odata2.ref.annotation.model;
import java.util.ArrayList;
import java.util.List;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
import org.apache.olingo.odata2.api.annotation.edm.NavigationEnd;
@@ -27,12 +28,12 @@ import org.apache.olingo.odata2.api.annotation.edm.NavigationEnd;
/**
*
*/
-@EdmEntityType(name = "Manager", namespace = ModelSharedConstants.NAMESPACE_1,
- entitySetName = "Managers", container = ModelSharedConstants.CONTAINER_1)
+@EdmEntityType(name = "Manager", namespace = ModelSharedConstants.NAMESPACE_1)
+@EdmEntitySet(name = "Managers")
public class Manager extends Employee {
- @EdmNavigationProperty(name = "nm_Employees", relationship = "ManagerEmployees",
- to = @NavigationEnd(role = "r_Employees", type = "Employee"))
+ @EdmNavigationProperty(name = "nm_Employees", association = "ManagerEmployees",
+ to = @NavigationEnd(role = "r_Employees", entitySet = Employee.class))
private List<Employee> employees = new ArrayList<Employee>();
public List<Employee> getEmployees() {
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c6791509/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Photo.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Photo.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Photo.java
index 432baba..3623b2b 100644
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Photo.java
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Photo.java
@@ -19,6 +19,7 @@
package org.apache.olingo.odata2.ref.annotation.model;
import java.util.Arrays;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceContent;
@@ -30,8 +31,8 @@ import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
/**
*
*/
-@EdmEntityType(name = "Photo", namespace = ModelSharedConstants.NAMESPACE_1,
- entitySetName = "Photos", container = ModelSharedConstants.CONTAINER_1)
+@EdmEntityType(name = "Photo", namespace = ModelSharedConstants.NAMESPACE_1)
+@EdmEntitySet(name = "Photos")
public class Photo {
@EdmProperty
@EdmKey
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c6791509/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Room.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Room.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Room.java
index 56e7e19..3d61a63 100644
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Room.java
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Room.java
@@ -20,6 +20,7 @@ package org.apache.olingo.odata2.ref.annotation.model;
import java.util.ArrayList;
import java.util.List;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
@@ -29,20 +30,20 @@ import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
/**
*
*/
-@EdmEntityType(name = "Room", namespace = ModelSharedConstants.NAMESPACE_1,
- entitySetName = "Rooms", container = ModelSharedConstants.CONTAINER_1)
+@EdmEntityType(name = "Room", namespace = ModelSharedConstants.NAMESPACE_1)
+@EdmEntitySet(name = "Rooms")
public class Room extends RefBase {
@EdmProperty
private Integer seats;
@EdmProperty
private Integer version;
- @EdmNavigationProperty(name="nr_Building", relationship="BuildingRooms",
- from = @NavigationEnd(role="r_Room", multiplicity = EdmMultiplicity.MANY))
+ @EdmNavigationProperty(name="nr_Building", association="BuildingRooms",
+ from = @NavigationEnd(role="r_Room", entitySet = Building.class, multiplicity = EdmMultiplicity.MANY))
private Building building;
- @EdmNavigationProperty(name="nr_Employees", relationship="RoomEmployees",
- from = @NavigationEnd(role = "r_Room", type = "Room", multiplicity = EdmMultiplicity.ONE),
- to = @NavigationEnd(role = "r_Employees", type = "Employee", multiplicity = EdmMultiplicity.MANY))
+ @EdmNavigationProperty(name="nr_Employees", association="RoomEmployees",
+ from = @NavigationEnd(role = "r_Room", entitySet = Room.class, multiplicity = EdmMultiplicity.ONE),
+ to = @NavigationEnd(role = "r_Employees", entitySet = Employee.class, multiplicity = EdmMultiplicity.MANY))
private List<Employee> employees = new ArrayList<Employee>();
public void setSeats(final int seats) {
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c6791509/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Team.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Team.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Team.java
index 6936517..1b04c32 100644
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Team.java
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Team.java
@@ -20,6 +20,7 @@ package org.apache.olingo.odata2.ref.annotation.model;
import java.util.ArrayList;
import java.util.List;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet;
import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
@@ -30,14 +31,14 @@ import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
/**
*
*/
-@EdmEntityType(name="Team", namespace = ModelSharedConstants.NAMESPACE_1,
- entitySetName = "Teams", container = ModelSharedConstants.CONTAINER_1)
+@EdmEntityType(name="Team", namespace = ModelSharedConstants.NAMESPACE_1)
+@EdmEntitySet(name = "Teams")
public class Team extends RefBase {
@EdmProperty(type = EdmSimpleTypeKind.Boolean)
private Boolean isScrumTeam;
- @EdmNavigationProperty(name = "nt_Employees", relationship="TeamEmployees",
+ @EdmNavigationProperty(name = "nt_Employees", association="TeamEmployees",
// from = @NavigationEnd(role = "r_Team", type = "Team"),
- to = @NavigationEnd(role = "r_Employees", type = "Employee", multiplicity = EdmMultiplicity.MANY)
+ to = @NavigationEnd(role = "r_Employees", entitySet = Employee.class, multiplicity = EdmMultiplicity.MANY)
)
private List<Employee> employees = new ArrayList<Employee>();
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c6791509/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmComplexEntity.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmComplexEntity.java b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmComplexEntity.java
deleted file mode 100644
index adec2d7..0000000
--- a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmComplexEntity.java
+++ /dev/null
@@ -1,31 +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.api.annotation.edm;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-@Retention(RetentionPolicy.RUNTIME)
-@Target(ElementType.TYPE)
-public @interface EdmComplexEntity {
- String name() default "";
- String namespace();
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c6791509/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmComplexType.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmComplexType.java b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmComplexType.java
new file mode 100644
index 0000000..b6b52f3
--- /dev/null
+++ b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmComplexType.java
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * 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.api.annotation.edm;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.TYPE)
+public @interface EdmComplexType {
+ String name() default "";
+ String namespace();
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c6791509/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmEntitySet.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmEntitySet.java b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmEntitySet.java
new file mode 100644
index 0000000..4a7fa6e
--- /dev/null
+++ b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmEntitySet.java
@@ -0,0 +1,31 @@
+/*******************************************************************************
+ * 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.api.annotation.edm;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.TYPE)
+public @interface EdmEntitySet {
+ String name() default "";
+// String container() default "";
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c6791509/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmEntityType.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmEntityType.java b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmEntityType.java
index ed5d802..67a363d 100644
--- a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmEntityType.java
+++ b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmEntityType.java
@@ -28,7 +28,4 @@ import java.lang.annotation.Target;
public @interface EdmEntityType {
String name() default "";
String namespace();
- /* If set this entity is exposed as entity set with given name. If not set theire will be no entity set generated. */
- String entitySetName() default "";
- String container() default "";
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c6791509/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmFacets.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmFacets.java b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmFacets.java
index 4ea2bd5..98edf8c 100644
--- a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmFacets.java
+++ b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmFacets.java
@@ -26,8 +26,8 @@ import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.ANNOTATION_TYPE)
public @interface EdmFacets {
- int maxLength() default 0;
+ int maxLength() default -1;
int scale() default -1;
- int precision() default 0;
+ int precision() default -1;
boolean nullable() default false;
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c6791509/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmFunctionImport.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmFunctionImport.java b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmFunctionImport.java
new file mode 100644
index 0000000..dd85784
--- /dev/null
+++ b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmFunctionImport.java
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * 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.api.annotation.edm;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import org.apache.olingo.odata2.api.annotation.edmx.HttpMethod;
+import org.apache.olingo.odata2.api.annotation.edmx.HttpMethod.Name;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.METHOD)
+public @interface EdmFunctionImport {
+
+ enum Type {
+ SIMPLE, ENTITY, COMPLEX
+ }
+
+ @interface ReturnType {
+ Type type();
+ boolean isCollection() default false;
+ }
+
+ String name() default "";
+
+ String entitySet() default "";
+
+ ReturnType returnType();
+
+ HttpMethod httpMethod() default @HttpMethod(name = Name.GET);
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c6791509/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmFunctionImportParameter.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmFunctionImportParameter.java b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmFunctionImportParameter.java
new file mode 100644
index 0000000..d5b2e80
--- /dev/null
+++ b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmFunctionImportParameter.java
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * 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.api.annotation.edm;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.PARAMETER)
+public @interface EdmFunctionImportParameter {
+ String name();
+ EdmSimpleTypeKind type() default EdmSimpleTypeKind.Null;
+ Facets facets() default @Facets;
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c6791509/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmNavigationProperty.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmNavigationProperty.java b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmNavigationProperty.java
index cf898df..544471b 100644
--- a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmNavigationProperty.java
+++ b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmNavigationProperty.java
@@ -28,8 +28,8 @@ import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
@Target(ElementType.FIELD)
public @interface EdmNavigationProperty {
String name();
- String relationship();
-
+ String association() default ""; // if not set -> will be generated
+
//
NavigationEnd from() default @NavigationEnd;
NavigationEnd to() default @NavigationEnd;
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c6791509/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmProperty.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmProperty.java b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmProperty.java
index 66c5282..14911ce 100644
--- a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmProperty.java
+++ b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmProperty.java
@@ -29,8 +29,5 @@ import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
public @interface EdmProperty {
EdmSimpleTypeKind type() default EdmSimpleTypeKind.Null;
String name() default "";
- /* only for complex property */
- String namespace() default "";
EdmFacets facets() default @EdmFacets;
-
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/c6791509/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/NavigationEnd.java
----------------------------------------------------------------------
diff --git a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/NavigationEnd.java b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/NavigationEnd.java
index 2ce5ef1..6846dba 100644
--- a/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/NavigationEnd.java
+++ b/odata2-lib/odata-annotation/src/main/java/org/apache/olingo/odata2/api/annotation/edm/NavigationEnd.java
@@ -28,7 +28,8 @@ import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
@Target(ElementType.FIELD)
public @interface NavigationEnd {
String role() default "";
- String type() default "";
+ // because entityset is mandatory for some cases set it as default to 'Object.class'
+ Class<?> entitySet() default Object.class;
EdmMultiplicity multiplicity() default EdmMultiplicity.ONE;
}
[28/52] git commit: Fix for related null values
Posted by mi...@apache.org.
Fix for related null values
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/f97d37f4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/f97d37f4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/f97d37f4
Branch: refs/heads/master
Commit: f97d37f442c9ef9ef575775129cc7986a767e620
Parents: d440793
Author: Michael Bolz <mi...@apache.org>
Authored: Wed Nov 20 06:10:11 2013 +0100
Committer: Michael Bolz <mi...@apache.org>
Committed: Wed Nov 20 06:10:11 2013 +0100
----------------------------------------------------------------------
.../annotation/data/AnnotationInMemoryDs.java | 17 +++++------------
.../annotation/data/AnnotationValueAccess.java | 14 ++++++++++++--
.../annotation/processor/ListsProcessor.java | 20 +++++++++++++-------
3 files changed, 30 insertions(+), 21 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/f97d37f4/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationInMemoryDs.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationInMemoryDs.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationInMemoryDs.java
index a8f4cb9..6414264 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationInMemoryDs.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationInMemoryDs.java
@@ -138,13 +138,13 @@ public class AnnotationInMemoryDs implements ListsDataSource {
}
}
- if(navigationInfo.getToMultiplicity() == EdmMultiplicity.ONE) {
- if(resultData.isEmpty()) {
- return null;
- }
+ if(resultData.isEmpty()) {
+ return null;
+ } else if(navigationInfo.getToMultiplicity() == EdmMultiplicity.ONE) {
return resultData.get(0);
+ } else {
+ return resultData;
}
- return resultData;
} else {
throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
}
@@ -264,13 +264,6 @@ public class AnnotationInMemoryDs implements ListsDataSource {
}
}
- private Field extractSourceField(DataStore sourceStore, DataStore targetStore) {
- Class sourceDataTypeClass = sourceStore.getDataTypeClass();
- Class targetDataTypeClass = targetStore.getDataTypeClass();
-
- return ANNOTATION_HELPER.getCommonNavigationFieldFromTarget(sourceDataTypeClass, targetDataTypeClass);
- }
-
private AnnotationHelper.AnnotatedNavInfo extractNavigationInfo(DataStore sourceStore, DataStore targetStore) {
Class sourceDataTypeClass = sourceStore.getDataTypeClass();
Class targetDataTypeClass = targetStore.getDataTypeClass();
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/f97d37f4/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationValueAccess.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationValueAccess.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationValueAccess.java
index 6c65bf8..ceea74d 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationValueAccess.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationValueAccess.java
@@ -23,8 +23,11 @@ import org.apache.olingo.odata2.api.data.ValueAccess;
import org.apache.olingo.odata2.api.edm.EdmMapping;
import org.apache.olingo.odata2.api.edm.EdmProperty;
import org.apache.olingo.odata2.api.exception.ODataException;
+import org.apache.olingo.odata2.api.exception.ODataHttpException;
+import org.apache.olingo.odata2.api.exception.ODataNotFoundException;
import org.apache.olingo.odata2.api.exception.ODataNotImplementedException;
import org.apache.olingo.odata2.core.annotation.edm.AnnotationHelper;
+import org.apache.olingo.odata2.core.exception.ODataRuntimeException;
/**
*
@@ -40,11 +43,18 @@ public class AnnotationValueAccess implements ValueAccess {
*/
@Override
public <T> Object getPropertyValue(final T data, final EdmProperty property) throws ODataException {
+ if(data == null) {
+ if(property.getFacets() == null || property.getFacets().isNullable()) {
+ return null;
+ }
+ throw new ODataRuntimeException("Invalid value for data '" + data + "' and property '" + property + "'.");
+ }
+
if(data instanceof Collection) {
Collection c = (Collection) data;
for (Object object : c) {
- if(annotationHelper.isEdmAnnotated(data)) {
- return annotationHelper.getValueForProperty(data, property.getName());
+ if(annotationHelper.isEdmAnnotated(object)) {
+ return annotationHelper.getValueForProperty(object, property.getName());
}
}
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/f97d37f4/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/ListsProcessor.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/ListsProcessor.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/ListsProcessor.java
index 26c85df..f659383 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/ListsProcessor.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/ListsProcessor.java
@@ -1000,14 +1000,20 @@ public class ListsProcessor extends ODataSingleProcessor {
} catch (final ODataNotFoundException e) {
relatedData = null;
}
- result.setEntryData(getStructuralTypeValueMap(relatedData, entityType));
+
+ if(relatedData == null) {
+ result.setEntryData(new HashMap<String, Object>());
+ return result;
+ } else {
+ result.setEntryData(getStructuralTypeValueMap(relatedData, entityType));
- EntityProviderWriteProperties inlineProperties =
- EntityProviderWriteProperties.serviceRoot(getContext().getPathInfo().getServiceRoot()).callbacks(
- getCallbacks(relatedData, entityType)).expandSelectTree(context.getCurrentExpandSelectTreeNode())
- .build();
- result.setInlineProperties(inlineProperties);
- return result;
+ EntityProviderWriteProperties inlineProperties =
+ EntityProviderWriteProperties.serviceRoot(getContext().getPathInfo().getServiceRoot()).callbacks(
+ getCallbacks(relatedData, entityType)).expandSelectTree(context.getCurrentExpandSelectTreeNode())
+ .build();
+ result.setInlineProperties(inlineProperties);
+ return result;
+ }
} catch (final ODataException e) {
throw new ODataApplicationException(e.getLocalizedMessage(), Locale.ROOT, e);
}
[11/52] git commit: Merge commit
'cf64375f62449d8813b539ed7e919df6e2bc6c35' into PocEdmAnnotationsExtension
Posted by mi...@apache.org.
Merge commit 'cf64375f62449d8813b539ed7e919df6e2bc6c35' into PocEdmAnnotationsExtension
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/bd54d262
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/bd54d262
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/bd54d262
Branch: refs/heads/master
Commit: bd54d262a7f6d90a9766dcd8c57e8811e5f21721
Parents: 4e6734d cf64375
Author: Michael Bolz <mi...@apache.org>
Authored: Mon Nov 11 13:50:56 2013 +0100
Committer: Michael Bolz <mi...@apache.org>
Committed: Mon Nov 11 13:50:56 2013 +0100
----------------------------------------------------------------------
.../jpa/src/main/assembly/jpa-assembly.xml | 1 +
odata2-dist/jpa/src/main/resources/LICENSE | 392 -----------------
odata2-dist/jpa/src/main/resources/NOTICE | 5 +
.../lib/src/main/assembly/lib-assembly.xml | 3 +-
odata2-dist/lib/src/main/resources/LICENSE | 392 -----------------
odata2-dist/lib/src/main/resources/NOTICE | 5 +
.../ref/src/main/assembly/ref-assembly.xml | 1 +
odata2-dist/ref/src/main/resources/LICENSE | 389 -----------------
odata2-dist/ref/src/main/resources/NOTICE | 5 +
.../odata2/api/processor/ODataContext.java | 2 +
.../olingo/odata2/core/ODataRequestHandler.java | 42 +-
.../olingo/odata2/core/commons/XmlHelper.java | 64 +++
.../odata2/core/edm/provider/EdmxProvider.java | 21 +-
.../core/ep/consumer/XmlEntityConsumer.java | 67 +--
.../core/ep/consumer/XmlMetadataConsumer.java | 3 +-
.../core/ep/util/XmlMetadataConstants.java | 3 +-
.../odata2/core/rest/ODataSubLocator.java | 8 +
.../olingo/odata2/core/rest/RestUtil.java | 36 +-
.../core/ODataRequestHandlerValidationTest.java | 434 ++++++++-----------
.../odata2/core/commons/XmlHelperTest.java | 98 +++++
.../odata2/core/ep/ProviderFacadeImplTest.java | 2 +-
.../core/ep/consumer/XmlEntityConsumerTest.java | 20 +-
.../ep/consumer/XmlMetadataConsumerTest.java | 39 ++
.../odata-core/src/test/resources/xxe.xml | 19 +
.../olingo/odata2/fit/basic/ContextTest.java | 15 +
.../fit/basic/RequestContentTypeTest.java | 4 +-
.../fit/basic/issues/Service1Factory.java | 76 ++++
.../fit/basic/issues/Service2Factory.java | 76 ++++
.../basic/issues/TestCxfCacheUriInfoIssue.java | 118 +++++
.../basic/issues/TestCxfCacheUriInfoIssue2.java | 75 ++++
.../odata2/fit/basic/issues/TestIssue105.java | 82 ----
.../olingo/odata2/fit/ref/AbstractRefTest.java | 4 +-
.../odata2/fit/ref/EntryJsonReadOnlyTest.java | 2 +-
.../odata2/fit/ref/FunctionImportJsonTest.java | 2 +-
.../olingo/odata2/fit/ref/MiscChangeTest.java | 28 +-
.../odata2/fit/ref/PropertyXmlChangeTest.java | 9 +-
.../AbstractContentNegotiationTest.java | 9 +-
.../BasicContentNegotiationTest.java | 5 +-
.../ContentNegotiationPostRequestTest.java | 2 +-
.../olingo/odata2/ref/model/DataContainer.java | 12 +-
.../apache/olingo/odata2/ref/model/Photo.java | 2 +-
.../ref/processor/BeanPropertyAccess.java | 185 ++++++++
.../odata2/ref/processor/ListsProcessor.java | 212 ++-------
.../ref/processor/ScenarioServiceFactory.java | 4 +-
.../odata2/ref/processor/ValueAccess.java | 69 +++
.../odata-ref/src/main/resources/Employee_1.png | Bin 0 -> 8429 bytes
.../odata-ref/src/main/resources/Employee_2.png | Bin 0 -> 12212 bytes
.../odata-ref/src/main/resources/Employee_3.png | Bin 0 -> 11655 bytes
.../odata-ref/src/main/resources/Employee_4.png | Bin 0 -> 9354 bytes
.../odata-ref/src/main/resources/Employee_5.png | Bin 0 -> 17205 bytes
.../odata-ref/src/main/resources/Employee_6.png | Bin 0 -> 12644 bytes
.../src/main/resources/female_6_BaySu.jpg | Bin 2418 -> 0 bytes
.../src/main/resources/male_1_WinterW.jpg | Bin 2723 -> 0 bytes
.../src/main/resources/male_2_FallF.jpg | Bin 2515 -> 0 bytes
.../src/main/resources/male_3_SmithJo.jpg | Bin 2659 -> 0 bytes
.../src/main/resources/male_4_BurkeP.jpg | Bin 2741 -> 0 bytes
.../src/main/resources/male_5_FieldJ.jpg | Bin 2256 -> 0 bytes
.../olingo/odata2/ref/model/EmployeeTest.java | 2 +-
.../olingo/odata2/ref/read/EntitySetTest.java | 3 +-
.../olingo/odata2/ref/read/EntityTest.java | 3 +-
.../olingo/odata2/testutil/fit/BaseTest.java | 5 +-
.../testutil/fit/FitStaticServiceFactory.java | 8 +
.../odata2/testutil/server/TestServer.java | 57 ++-
.../src/main/resources/META-INF/LICENSE | 392 -----------------
odata2-processor-jpa/jpa-api/pom.xml | 2 +-
.../processor/api/jpa/ODataJPAContext.java | 28 ++
.../api/jpa/ODataJPAServiceFactory.java | 29 ++
.../processor/api/jpa/access/JPAFunction.java | 2 +-
.../processor/api/jpa/access/JPAProcessor.java | 12 +-
.../jpa/exception/ODataJPAErrorCallback.java | 45 ++
.../processor/api/jpa/model/JPAEdmBaseView.java | 11 +
odata2-processor-jpa/jpa-core/pom.xml | 2 +-
.../core/jpa/ODataExpressionParser.java | 4 +-
.../processor/core/jpa/ODataJPAContextImpl.java | 11 +
.../core/jpa/access/data/JPAEntityParser.java | 2 +-
.../jpa/access/model/JPAEdmNameBuilder.java | 40 +-
.../core/jpa/model/JPAEdmAssociation.java | 2 +-
.../core/jpa/model/JPAEdmBaseViewImpl.java | 8 +
.../core/jpa/model/JPAEdmFunctionImport.java | 2 +-
.../jpa/model/JPAEdmNavigationProperty.java | 2 +-
.../core/jpa/model/JPAEdmProperty.java | 4 +-
.../jpa/access/data/JPAEntityParserTest.java | 4 +-
.../jpa/access/model/JPAEdmNameBuilderTest.java | 87 +++-
...PQLJoinSelectSingleStatementBuilderTest.java | 2 +-
.../jpa/jpql/JPQLJoinStatementBuilderTest.java | 7 +-
.../core/jpa/mock/ODataJPAContextMock.java | 1 +
.../core/jpa/mock/data/EdmMockUtilV2.java | 18 +-
.../core/jpa/model/JPAEdmTestModelView.java | 6 +
odata2-processor-jpa/jpa-ref/pom.xml | 2 +-
odata2-processor-jpa/jpa-web/pom.xml | 2 +-
.../jpa/processor/ref/util/DataGenerator.java | 11 +-
.../ref/web/JPAReferenceServiceFactory.java | 12 +
.../jpa-web/src/main/resources/META-INF/LICENSE | 392 -----------------
.../src/main/resources/serviceConfig.properties | 19 +
.../jpa-web/src/main/webapp/index.jsp | 275 +++++++++++-
odata2-processor-jpa/pom.xml | 2 +-
odata2-sample/cars-service-archetype/pom.xml | 79 ++++
.../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 | 27 ++
pom.xml | 120 +++--
110 files changed, 2972 insertions(+), 2737 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/bd54d262/pom.xml
----------------------------------------------------------------------
diff --cc pom.xml
index 3a35a67,cd71d5a..a195e82
--- a/pom.xml
+++ b/pom.xml
@@@ -75,8 -75,8 +75,9 @@@
<modules>
<module>odata2-lib</module>
<module>odata2-processor-jpa</module>
+ <module>odata2-edm-annotation</module>
<module>odata2-dist</module>
+ <module>odata2-sample</module>
</modules>
<build>
[27/52] git commit: Minor refactorings for duplicate codings
Posted by mi...@apache.org.
Minor refactorings for duplicate codings
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/d4407934
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/d4407934
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/d4407934
Branch: refs/heads/master
Commit: d44079345b5a182d1897a91f365a8866d4507f39
Parents: 014bb97
Author: Michael Bolz <mi...@apache.org>
Authored: Tue Nov 19 08:45:54 2013 +0100
Committer: Michael Bolz <mi...@apache.org>
Committed: Tue Nov 19 08:45:54 2013 +0100
----------------------------------------------------------------------
.../annotation/data/AnnotationInMemoryDs.java | 14 +-
.../annotation/edm/AnnotationEdmProvider.java | 49 +------
.../core/annotation/edm/AnnotationHelper.java | 145 +++++++++++++++++--
3 files changed, 150 insertions(+), 58 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d4407934/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationInMemoryDs.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationInMemoryDs.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationInMemoryDs.java
index 3b79e27..a8f4cb9 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationInMemoryDs.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationInMemoryDs.java
@@ -115,7 +115,9 @@ public class AnnotationInMemoryDs implements ListsDataSource {
String targetName = targetEntitySet.getEntityType().getName();
DataStore targetStore = dataStores.get(targetName);
- Field sourceFieldAtTarget = extractSourceField(sourceStore, targetStore);
+ AnnotationHelper.AnnotatedNavInfo navigationInfo = extractNavigationInfo(sourceStore, targetStore);
+
+ Field sourceFieldAtTarget = navigationInfo.getToField();
if (sourceFieldAtTarget == null) {
throw new ODataRuntimeException("Missing source field for related data.");
}
@@ -136,8 +138,7 @@ public class AnnotationInMemoryDs implements ListsDataSource {
}
}
- EdmNavigationProperty navProperty = sourceFieldAtTarget.getAnnotation(EdmNavigationProperty.class);
- if(navProperty.from().multiplicity() == EdmMultiplicity.ONE) {
+ if(navigationInfo.getToMultiplicity() == EdmMultiplicity.ONE) {
if(resultData.isEmpty()) {
return null;
}
@@ -269,4 +270,11 @@ public class AnnotationInMemoryDs implements ListsDataSource {
return ANNOTATION_HELPER.getCommonNavigationFieldFromTarget(sourceDataTypeClass, targetDataTypeClass);
}
+
+ private AnnotationHelper.AnnotatedNavInfo extractNavigationInfo(DataStore sourceStore, DataStore targetStore) {
+ Class sourceDataTypeClass = sourceStore.getDataTypeClass();
+ Class targetDataTypeClass = targetStore.getDataTypeClass();
+
+ return ANNOTATION_HELPER.getCommonNavigationInfo(sourceDataTypeClass, targetDataTypeClass);
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d4407934/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java
index dc253d8..8f9a2f4 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java
@@ -495,40 +495,19 @@ public class AnnotationEdmProvider extends EdmProvider {
navProp.setName(entityName);
//
NavigationEnd from = enp.from();
- String fromRole = from.role();
- if (fromRole.isEmpty()) {
- fromRole = getCanonicalRole(from, field.getDeclaringClass());
- }
+ String fromRole = ANNOTATION_HELPER.extractRoleName(from, field.getDeclaringClass());
navProp.setFromRole(fromRole);
NavigationEnd to = enp.to();
- String toRole = to.role();
- if (toRole.isEmpty()) {
- toRole = getCanonicalRole(to, field.getType());
- }
+ String toRole = ANNOTATION_HELPER.extractRoleName(to, field.getType());
navProp.setToRole(toRole);
- String relationshipName = enp.association();
- if(relationshipName.isEmpty()) {
- if(fromRole.compareTo(toRole) > 0) {
- relationshipName = toRole + "-" + fromRole;
- } else {
- relationshipName = fromRole + "-" + toRole;
- }
- }
+ String relationshipName = ANNOTATION_HELPER.extractRelationshipName(enp, fromRole, toRole);
navProp.setRelationship(new FullQualifiedName(namespace, relationshipName));
return navProp;
}
- private String getCanonicalRole(NavigationEnd navEnd, Class<?> fallbackClass) {
- String toRole = ANNOTATION_HELPER.extractEntityTypeName(navEnd.entitySet());
- if(toRole == null) {
- toRole = ANNOTATION_HELPER.extractEntityTypeName(fallbackClass);
- }
- return "r_" + toRole;
- }
-
private EdmSimpleTypeKind getEdmSimpleType(Class<?> type) {
if (type == String.class) {
return EdmSimpleTypeKind.String;
@@ -576,10 +555,7 @@ public class AnnotationEdmProvider extends EdmProvider {
NavigationEnd from = navigation.from();
AssociationEnd fromEnd = new AssociationEnd();
fromEnd.setRole(navProperty.getFromRole());
- String typeName = extractEntitTypeName(from);
- if (typeName.isEmpty()) {
- typeName = ANNOTATION_HELPER.extractEntityTypeName(field.getDeclaringClass());
- }
+ String typeName = ANNOTATION_HELPER.extractEntitTypeName(from, field.getDeclaringClass());
fromEnd.setType(new FullQualifiedName(namespace, typeName));
fromEnd.setMultiplicity(from.multiplicity());
association.setEnd1(fromEnd);
@@ -587,10 +563,7 @@ public class AnnotationEdmProvider extends EdmProvider {
NavigationEnd to = navigation.to();
AssociationEnd toEnd = new AssociationEnd();
toEnd.setRole(navProperty.getToRole());
- String toTypeName = extractEntitTypeName(to);
- if (toTypeName.isEmpty()) {
- toTypeName = ANNOTATION_HELPER.extractEntityTypeName(field.getType());
- }
+ String toTypeName = ANNOTATION_HELPER.extractEntitTypeName(to, field.getType());
toEnd.setType(new FullQualifiedName(namespace, toTypeName));
EdmMultiplicity toMultiplicity = to.multiplicity();
@@ -616,18 +589,6 @@ public class AnnotationEdmProvider extends EdmProvider {
private boolean isAnnotatedEntity(Class<?> clazz) {
return ANNOTATION_HELPER.isEdmTypeAnnotated(clazz);
}
-
- private String extractEntitTypeName(NavigationEnd navEnd) {
- Class<?> entityTypeClass = navEnd.entitySet();
- if(entityTypeClass == Object.class) {
- return "";
- }
- EdmEntityType type = entityTypeClass.getAnnotation(EdmEntityType.class);
- if(type == null) {
- return "";
- }
- return type.name();
- }
}
static class SchemaBuilder {
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/d4407934/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java
index fbc0c7c..dfa461a 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java
@@ -17,7 +17,6 @@ package org.apache.olingo.odata2.core.annotation.edm;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
@@ -30,7 +29,9 @@ import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
+import org.apache.olingo.odata2.api.annotation.edm.NavigationEnd;
import org.apache.olingo.odata2.api.edm.EdmLiteralKind;
+import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
import org.apache.olingo.odata2.api.edm.EdmSimpleTypeException;
import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
import org.apache.olingo.odata2.api.edm.FullQualifiedName;
@@ -79,6 +80,21 @@ public class AnnotationHelper {
}
}
+ public String extractEntitTypeName(NavigationEnd navEnd, Class<?> fallbackClass) {
+ Class<?> entityTypeClass = navEnd.entitySet();
+ if (entityTypeClass == Object.class) {
+ return extractEntityTypeName(fallbackClass);
+ }
+ EdmEntityType type = entityTypeClass.getAnnotation(EdmEntityType.class);
+ if (type == null) {
+ return null;
+ }
+ if(type.name().isEmpty()) {
+ return extractEntityTypeName(fallbackClass);
+ }
+ return type.name();
+ }
+
/**
* Returns <code>NULL</code> if given class is not annotated. If annotated the set entity type name is returned and if
* no name is set the default name is generated from the simple class name.
@@ -105,13 +121,13 @@ public class AnnotationHelper {
}
/**
- *
- *
+ *
+ *
* @param <T> must be EdmEntityType or EdmComplexType annotation
* @param annotatedClass
* @param typeAnnotation
- * @return null if annotatedClass is not annotated or
- * name set via annotation or generated via {@link #getCanonicalName(java.lang.Class)}
+ * @return null if annotatedClass is not annotated or name set via annotation or generated via
+ * {@link #getCanonicalName(java.lang.Class)}
*/
private <T extends Annotation> String extractTypeName(Class<?> annotatedClass, Class<T> typeAnnotation) {
if (annotatedClass == Object.class) {
@@ -121,12 +137,12 @@ public class AnnotationHelper {
if (type == null) {
return null;
}
-
+
String name;
- if(typeAnnotation == EdmEntityType.class) {
- name = ((EdmEntityType)type).name();
- } else if(typeAnnotation == EdmComplexType.class) {
- name = ((EdmComplexType)type).name();
+ if (typeAnnotation == EdmEntityType.class) {
+ name = ((EdmEntityType) type).name();
+ } else if (typeAnnotation == EdmComplexType.class) {
+ name = ((EdmComplexType) type).name();
} else {
return null;
}
@@ -136,7 +152,7 @@ public class AnnotationHelper {
}
return name;
}
-
+
/**
* Get the set property name from an EdmProperty or EdmNavigationProperty annotation.
*
@@ -164,6 +180,41 @@ public class AnnotationHelper {
return propertyName;
}
+ public String extractRoleName(NavigationEnd navigationEnd, Class<?> fallbackClass) {
+ String role = navigationEnd.role();
+ if (role.isEmpty()) {
+ role = getCanonicalRole(navigationEnd, fallbackClass);
+ }
+ return role;
+ }
+
+ public String getCanonicalRole(NavigationEnd navEnd, Class<?> fallbackClass) {
+ String toRole = extractEntityTypeName(navEnd.entitySet());
+ if (toRole == null) {
+ toRole = extractEntityTypeName(fallbackClass);
+ }
+ return "r_" + toRole;
+ }
+
+ public String extractRelationshipName(EdmNavigationProperty enp, Field field) {
+ String fromRole = extractRoleName(enp.from(), field.getDeclaringClass());
+ String toRole = extractRoleName(enp.to(), field.getType());
+
+ return extractRelationshipName(enp, fromRole, toRole);
+ }
+
+ public String extractRelationshipName(EdmNavigationProperty enp, String fromRole, String toRole) {
+ String relationshipName = enp.association();
+ if(relationshipName.isEmpty()) {
+ if(fromRole.compareTo(toRole) > 0) {
+ relationshipName = toRole + "-" + fromRole;
+ } else {
+ relationshipName = fromRole + "-" + toRole;
+ }
+ }
+ return relationshipName;
+ }
+
public static final class ODataAnnotationException extends ODataException {
public ODataAnnotationException(String message) {
@@ -187,6 +238,78 @@ public class AnnotationHelper {
return instance;
}
+ public static class AnnotatedNavInfo {
+
+ private final Field fromField;
+ private final Field toField;
+ private final EdmNavigationProperty fromNavigation;
+ private final EdmNavigationProperty toNavigation;
+
+ public AnnotatedNavInfo(Field fromField, Field toField, EdmNavigationProperty fromNavigation,
+ EdmNavigationProperty toNavigation) {
+ this.fromField = fromField;
+ this.toField = toField;
+ this.fromNavigation = fromNavigation;
+ this.toNavigation = toNavigation;
+ }
+
+ public Field getFromField() {
+ return fromField;
+ }
+
+ public Field getToField() {
+ return toField;
+ }
+
+ public EdmMultiplicity getFromMultiplicity() {
+ EdmMultiplicity from = fromNavigation.from().multiplicity();
+ EdmMultiplicity to = toNavigation.to().multiplicity();
+
+ if (from.equals(to)) {
+ return from;
+ } else {
+ if (EdmMultiplicity.MANY == from || EdmMultiplicity.MANY == to) {
+ return EdmMultiplicity.MANY;
+ } else {
+ return EdmMultiplicity.ONE;
+ }
+ }
+ }
+
+ public EdmMultiplicity getToMultiplicity() {
+ EdmMultiplicity from = fromNavigation.to().multiplicity();
+ EdmMultiplicity to = toNavigation.from().multiplicity();
+
+ if (from.equals(to)) {
+ return from;
+ } else {
+ if (EdmMultiplicity.MANY == from || EdmMultiplicity.MANY == to) {
+ return EdmMultiplicity.MANY;
+ } else {
+ return EdmMultiplicity.ONE;
+ }
+ }
+ }
+ }
+
+ public AnnotatedNavInfo getCommonNavigationInfo(Class<?> sourceClass, Class<?> targetClass) {
+ List<Field> sourceFields = getAnnotatedFields(sourceClass, EdmNavigationProperty.class);
+ List<Field> targetFields = getAnnotatedFields(targetClass, EdmNavigationProperty.class);
+
+ for (Field targetField : targetFields) {
+ for (Field sourceField : sourceFields) {
+ EdmNavigationProperty sourceNav = sourceField.getAnnotation(EdmNavigationProperty.class);
+ EdmNavigationProperty targetNav = targetField.getAnnotation(EdmNavigationProperty.class);
+ String sourceAssociation = extractRelationshipName(sourceNav, sourceField);
+ String targetAssociation = extractRelationshipName(targetNav, targetField);
+ if (sourceAssociation.equals(targetAssociation)) {
+ return new AnnotatedNavInfo(sourceField, targetField, sourceNav, targetNav);
+ }
+ }
+ }
+ return null;
+ }
+
public Field getCommonNavigationFieldFromTarget(Class<?> sourceClass, Class<?> targetClass) {
List<Field> sourceFields = getAnnotatedFields(sourceClass, EdmNavigationProperty.class);
List<Field> targetFields = getAnnotatedFields(targetClass, EdmNavigationProperty.class);
[39/52] git commit: Fixed handling for already set keys
Posted by mi...@apache.org.
Fixed handling for already set keys
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/e7a17fe9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/e7a17fe9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/e7a17fe9
Branch: refs/heads/master
Commit: e7a17fe9a19afabebf8fc6e8595eff70260771b1
Parents: d108298
Author: Michael Bolz <mi...@apache.org>
Authored: Wed Dec 4 15:11:56 2013 +0100
Committer: Michael Bolz <mi...@apache.org>
Committed: Wed Dec 4 15:11:56 2013 +0100
----------------------------------------------------------------------
.../annotation/data/AnnotationInMemoryDs.java | 10 ++-
.../odata2/core/annotation/data/DataStore.java | 40 +++++++----
.../annotation/processor/ListsProcessor.java | 6 +-
.../data/AnnotationsInMemoryDsTest.java | 76 ++++++++++++++++----
4 files changed, 100 insertions(+), 32 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/e7a17fe9/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationInMemoryDs.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationInMemoryDs.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationInMemoryDs.java
index 3389140..7c41945 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationInMemoryDs.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/AnnotationInMemoryDs.java
@@ -42,8 +42,14 @@ public class AnnotationInMemoryDs implements ListsDataSource {
private static final AnnotationHelper ANNOTATION_HELPER = new AnnotationHelper();
private final Map<String, DataStore<Object>> dataStores = new HashMap<String, DataStore<Object>>();
+ private final boolean persistInMemory;
public AnnotationInMemoryDs(String packageToScan) {
+ this(packageToScan, true);
+ }
+
+ public AnnotationInMemoryDs(String packageToScan, boolean persistInMemory) {
+ this.persistInMemory = persistInMemory;
List<Class<?>> foundClasses = ClassHelper.loadClasses(packageToScan, new ClassHelper.ClassValidator() {
@Override
public boolean isClassValid(Class<?> c) {
@@ -58,7 +64,7 @@ public class AnnotationInMemoryDs implements ListsDataSource {
private void init(List<Class<?>> foundClasses) {
for (Class<?> clz : foundClasses) {
- DataStore<Object> dhs = (DataStore<Object>) DataStore.createInMemory(clz);
+ DataStore<Object> dhs = (DataStore<Object>) getDataStore(clz);
org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet entitySet =
clz.getAnnotation(org.apache.olingo.odata2.api.annotation.edm.EdmEntitySet.class);
dataStores.put(entitySet.name(), dhs);
@@ -66,7 +72,7 @@ public class AnnotationInMemoryDs implements ListsDataSource {
}
public <T> DataStore<T> getDataStore(Class<T> clazz) {
- return DataStore.createInMemory(clazz);
+ return DataStore.createInMemory(clazz, persistInMemory);
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/e7a17fe9/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/DataStore.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/DataStore.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/DataStore.java
index 4e43db4..834e33a 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/DataStore.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/data/DataStore.java
@@ -47,9 +47,9 @@ public class DataStore<T> {
private static final Map<Class<?>, DataStore<?>> c2ds = new HashMap<Class<?>, DataStore<?>>();
@SuppressWarnings("unchecked")
- static DataStore<?> getInstance(Class<?> clz) {
+ static DataStore<?> getInstance(Class<?> clz, boolean createNewInstance) {
DataStore<?> ds = c2ds.get(clz);
- if (ds == null) {
+ if (createNewInstance || ds == null) {
ds = new DataStore<Object>((Class<Object>) clz);
c2ds.put(clz, ds);
}
@@ -59,11 +59,16 @@ public class DataStore<T> {
@SuppressWarnings("unchecked")
public static <T> DataStore<T> createInMemory(Class<T> clazz) {
- return (DataStore<T>) InMemoryDataStore.getInstance(clazz);
+ return (DataStore<T>) InMemoryDataStore.getInstance(clazz, true);
+ }
+
+ @SuppressWarnings("unchecked")
+ public static <T> DataStore<T> createInMemory(Class<T> clazz, boolean keepExisting) {
+ return (DataStore<T>) InMemoryDataStore.getInstance(clazz, !keepExisting);
}
private DataStore(List<T> wrapStore, Class<T> clz) {
- dataStore = wrapStore;
+ dataStore = Collections.synchronizedList(wrapStore);
dataTypeClass = clz;
}
@@ -104,26 +109,33 @@ public class DataStore<T> {
}
public T create(T object) throws DataStoreException {
- if (read(object) != null || getKeys(object).contains(null)) {
- createKeys(object);
+ synchronized (dataStore) {
+ if (read(object) != null || getKeys(object).contains(null)) {
+ createKeys(object);
+ return this.create(object);
+ }
+ dataStore.add(object);
}
- dataStore.add(object);
return object;
}
public T update(T object) {
- T stored = read(object);
- dataStore.remove(stored);
- dataStore.add(object);
+ synchronized (dataStore) {
+ T stored = read(object);
+ dataStore.remove(stored);
+ dataStore.add(object);
+ }
return object;
}
public T delete(T object) {
- T stored = read(object);
- if (stored != null) {
- dataStore.remove(stored);
+ synchronized (dataStore) {
+ T stored = read(object);
+ if (stored != null) {
+ dataStore.remove(stored);
+ }
+ return stored;
}
- return stored;
}
private List<Object> getKeys(T object) {
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/e7a17fe9/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/ListsProcessor.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/ListsProcessor.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/ListsProcessor.java
index b4a2c6f..16e1eab 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/ListsProcessor.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/ListsProcessor.java
@@ -1578,8 +1578,12 @@ public class ListsProcessor extends ODataSingleProcessor {
for (final String propertyName : type.getPropertyNames()) {
final EdmProperty property = (EdmProperty) type.getProperty(propertyName);
if (type instanceof EdmEntityType && ((EdmEntityType) type).getKeyProperties().contains(property)) {
- continue;
+ Object v = valueAccess.getPropertyValue(data, property);
+ if(v != null) {
+ continue;
+ }
}
+
if (!merge || valueMap != null && valueMap.containsKey(propertyName)) {
final Object value = valueMap == null ? null : valueMap.get(propertyName);
if (property.isSimple()) {
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/e7a17fe9/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/data/AnnotationsInMemoryDsTest.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/data/AnnotationsInMemoryDsTest.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/data/AnnotationsInMemoryDsTest.java
index 02881f0..b132a0b 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/data/AnnotationsInMemoryDsTest.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/data/AnnotationsInMemoryDsTest.java
@@ -24,6 +24,7 @@ import org.apache.olingo.odata2.api.edm.FullQualifiedName;
import org.apache.olingo.odata2.api.edm.provider.EntitySet;
import org.apache.olingo.odata2.api.exception.ODataException;
import org.apache.olingo.odata2.core.annotation.edm.AnnotationEdmProvider;
+import org.apache.olingo.odata2.core.annotation.edm.AnnotationHelper;
import org.apache.olingo.odata2.core.annotation.model.Building;
import org.apache.olingo.odata2.core.annotation.model.ModelSharedConstants;
import org.apache.olingo.odata2.core.annotation.model.Photo;
@@ -41,7 +42,7 @@ public class AnnotationsInMemoryDsTest {
private static final String DEFAULT_CONTAINER = ModelSharedConstants.CONTAINER_1;
public AnnotationsInMemoryDsTest() {
- datasource = new AnnotationInMemoryDs(Building.class.getPackage().getName());
+ datasource = new AnnotationInMemoryDs(Building.class.getPackage().getName(), false);
edmProvider = new AnnotationEdmProvider(Building.class.getPackage().getName());
}
@@ -58,8 +59,57 @@ public class AnnotationsInMemoryDsTest {
Building read = (Building) datasource.readData(edmEntitySet, keys);
Assert.assertEquals("Common Building", read.getName());
+ Assert.assertEquals("1", read.getId());
}
+
+ @Test
+ public void createSimpleEntityWithOwnKey() throws Exception {
+ EdmEntitySet edmEntitySet = createMockedEdmEntitySet("Buildings");
+
+ Building building = new Building();
+ building.setName("Common Building");
+ AnnotationHelper ah = new AnnotationHelper();
+ ah.setValueForProperty(building, "Id", "42");
+ datasource.createData(edmEntitySet, building);
+
+ Map<String, Object> keys = new HashMap<String, Object>();
+ keys.put("Id", "42");
+
+ Building read = (Building) datasource.readData(edmEntitySet, keys);
+ Assert.assertEquals("Common Building", read.getName());
+ Assert.assertEquals("42", read.getId());
+ }
+
+ @Test
+ public void createSimpleEntityWithDuplicateKey() throws Exception {
+ EdmEntitySet edmEntitySet = createMockedEdmEntitySet("Buildings");
+ AnnotationHelper ah = new AnnotationHelper();
+
+ Building building = new Building();
+ building.setName("Common Building");
+ ah.setValueForProperty(building, "Id", "42");
+ datasource.createData(edmEntitySet, building);
+ //
+ Building buildingDuplicate = new Building();
+ buildingDuplicate.setName("Duplicate Building");
+ ah.setValueForProperty(buildingDuplicate, "Id", "42");
+ datasource.createData(edmEntitySet, buildingDuplicate);
+
+ Map<String, Object> keys42 = new HashMap<String, Object>();
+ keys42.put("Id", "42");
+ Building read42 = (Building) datasource.readData(edmEntitySet, keys42);
+ Assert.assertEquals("Common Building", read42.getName());
+ Assert.assertEquals("42", read42.getId());
+
+ Map<String, Object> keys = new HashMap<String, Object>();
+ keys.put("Id", "1");
+ Building read = (Building) datasource.readData(edmEntitySet, keys);
+ Assert.assertEquals("Duplicate Building", read.getName());
+ Assert.assertEquals("1", read.getId());
+}
+
+
@Test
public void createEntityTwoKeys() throws Exception {
EdmEntitySet edmEntitySet = createMockedEdmEntitySet("Photos");
@@ -97,34 +147,30 @@ public class AnnotationsInMemoryDsTest {
datasource.createData(edmEntitySet, photo);
Map<String, Object> keys = new HashMap<String, Object>();
- keys.put("Name", "1");
- keys.put("ImageFormat", "2");
+ keys.put("Name", "BigPicture");
+ keys.put("ImageFormat", "PNG");
Photo read = (Photo) datasource.readData(edmEntitySet, keys);
- Assert.assertEquals("1", read.getName());
- Assert.assertEquals("2", read.getType());
+ Assert.assertEquals("BigPicture", read.getName());
+ Assert.assertEquals("PNG", read.getType());
Assert.assertEquals("image/png", read.getImageType());
Assert.assertEquals("https://localhost/image.png", read.getImageUri());
// update
Photo updatedPhoto = new Photo();
- // updatedPhoto.setName(nameKeyValue);
- // updatedPhoto.setType(typeKeyValue);
- updatedPhoto.setName("1");
- updatedPhoto.setType("2");
+ updatedPhoto.setName(nameKeyValue);
+ updatedPhoto.setType(typeKeyValue);
updatedPhoto.setImageUri("https://localhost/image.jpg");
updatedPhoto.setImageType("image/jpg");
datasource.updateData(edmEntitySet, updatedPhoto);
Map<String, Object> updatedKeys = new HashMap<String, Object>();
- // updatedKeys.put("Name", nameKeyValue);
- // updatedKeys.put("ImageFormat", typeKeyValue);
- updatedKeys.put("Name", "1");
- updatedKeys.put("ImageFormat", "2");
+ updatedKeys.put("Name", nameKeyValue);
+ updatedKeys.put("ImageFormat", typeKeyValue);
Photo readUpdated = (Photo) datasource.readData(edmEntitySet, updatedKeys);
- Assert.assertEquals("1", readUpdated.getName());
- Assert.assertEquals("2", readUpdated.getType());
+ Assert.assertEquals("BigPicture", readUpdated.getName());
+ Assert.assertEquals("PNG", readUpdated.getType());
Assert.assertEquals("image/jpg", readUpdated.getImageType());
Assert.assertEquals("https://localhost/image.jpg", readUpdated.getImageUri());
}
[32/52] git commit: Merge branch 'master' into
PocEdmAnnotationsExtension
Posted by mi...@apache.org.
Merge branch 'master' into PocEdmAnnotationsExtension
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/52693996
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/52693996
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/52693996
Branch: refs/heads/master
Commit: 526939969864e7340a29addf8832a8f0da00ec70
Parents: aeca3df d4df5cc
Author: Michael Bolz <mi...@apache.org>
Authored: Fri Nov 29 14:49:59 2013 +0100
Committer: Michael Bolz <mi...@apache.org>
Committed: Fri Nov 29 14:49:59 2013 +0100
----------------------------------------------------------------------
.../core/jpa/ODataJPAResponseBuilder.java | 7 ++---
.../core/jpa/access/data/JPAExpandCallBack.java | 28 +++++++++++---------
.../jpa-web/src/main/webapp/index.jsp | 16 +++++++++++
3 files changed, 36 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
[09/52] git commit: Added @EdmMediaResource annotations
Posted by mi...@apache.org.
Added @EdmMediaResource annotations
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/5af55593
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/5af55593
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/5af55593
Branch: refs/heads/master
Commit: 5af555934e1715827cc6db377bd634ab1aa96e28
Parents: f614199
Author: Michael Bolz <mi...@sap.com>
Authored: Tue Oct 15 09:38:41 2013 +0200
Committer: Michael Bolz <mi...@sap.com>
Committed: Tue Oct 15 21:58:34 2013 +0200
----------------------------------------------------------------------
.../annotation/edm/EdmMediaResourceContent.java | 29 +++++
.../edm/EdmMediaResourceMimeType.java | 29 +++++
.../annotation/edm/EdmMediaResourceSource.java | 29 +++++
.../annotation/edm/AnnotationEdmProvider.java | 10 +-
.../core/annotation/edm/AnnotationHelper.java | 40 ++++++
.../odata2/core/annotation/edm/ClassHelper.java | 2 +
.../processor/AnnotationProcessor.java | 27 ++++
.../processor/json/EdmAnnotationSerializer.java | 114 ++++++++++++-----
.../annotation/processor/json/JsonWriter.java | 125 ++++++-------------
.../odata2/ref/annotation/model/Photo.java | 91 +++++++-------
.../ref/annotation/model/ResourceHelper.java | 47 +++++++
.../odata2/ref/annotation/model/ds/PhotoDs.java | 63 ++++++++++
.../processor/ScenarioServiceFactory.java | 15 ++-
13 files changed, 452 insertions(+), 169 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/5af55593/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmMediaResourceContent.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmMediaResourceContent.java b/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmMediaResourceContent.java
new file mode 100644
index 0000000..80e9cd8
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmMediaResourceContent.java
@@ -0,0 +1,29 @@
+/*******************************************************************************
+ * 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.api.annotation.edm;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.FIELD)
+public @interface EdmMediaResourceContent {
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/5af55593/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmMediaResourceMimeType.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmMediaResourceMimeType.java b/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmMediaResourceMimeType.java
new file mode 100644
index 0000000..d255ff4
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmMediaResourceMimeType.java
@@ -0,0 +1,29 @@
+/*******************************************************************************
+ * 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.api.annotation.edm;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.FIELD)
+public @interface EdmMediaResourceMimeType {
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/5af55593/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmMediaResourceSource.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmMediaResourceSource.java b/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmMediaResourceSource.java
new file mode 100644
index 0000000..78e72b5
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-api/src/main/java/org/apache/olingo/odata2/api/annotation/edm/EdmMediaResourceSource.java
@@ -0,0 +1,29 @@
+/*******************************************************************************
+ * 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.api.annotation.edm;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.FIELD)
+public @interface EdmMediaResourceSource {
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/5af55593/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java
index 8bd80ad..d4ef369 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java
@@ -29,10 +29,10 @@ import java.util.Map;
import org.apache.olingo.odata2.api.annotation.edm.EdmComplexEntity;
import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
+import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceContent;
import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
import org.apache.olingo.odata2.api.annotation.edm.NavigationEnd;
-import org.apache.olingo.odata2.api.edm.EdmEntitySet;
import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
import org.apache.olingo.odata2.api.edm.FullQualifiedName;
@@ -316,6 +316,7 @@ public class AnnotationEdmProvider extends EdmProvider {
final private String namespace;
final private String name;
private boolean isAbstract = false;
+ private boolean isMediaResource = false;
private FullQualifiedName baseEntityType = null;
private final List<PropertyRef> keyProperties = new ArrayList<PropertyRef>();
private final List<Property> properties = new ArrayList<Property>();
@@ -359,6 +360,10 @@ public class AnnotationEdmProvider extends EdmProvider {
Association association = createAssociation(field, navProperty);
associations.add(association);
}
+ EdmMediaResourceContent emrc = field.getAnnotation(EdmMediaResourceContent.class);
+ if(emrc != null) {
+ isMediaResource = true;
+ }
}
return this;
@@ -406,6 +411,7 @@ public class AnnotationEdmProvider extends EdmProvider {
}
return entityType.setName(name)
.setAbstract(isAbstract)
+ .setHasStream(isMediaResource)
.setProperties(properties);
}
@@ -502,6 +508,8 @@ public class AnnotationEdmProvider extends EdmProvider {
return EdmSimpleTypeKind.Int32;
} else if (type == Integer.class) {
return EdmSimpleTypeKind.Int32;
+ } else if (type == Byte[].class || type == byte[].class) {
+ return EdmSimpleTypeKind.Binary;
} else {
throw new UnsupportedOperationException("Not supported type '" + type
+ "' yet."); //To change body of generated methods, choose Tools | Templates.
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/5af55593/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java
index 184685e..e30e382 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java
@@ -18,16 +18,56 @@
******************************************************************************/
package org.apache.olingo.odata2.core.annotation.edm;
+import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.util.Locale;
import org.apache.olingo.odata2.api.annotation.edm.EdmComplexEntity;
import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
+import org.apache.olingo.odata2.core.exception.ODataRuntimeException;
/**
*
*/
public class AnnotationHelper {
+ public Object getValueForField(Object result, Class<? extends Annotation> annotation) {
+ if(result == null) {
+ return null;
+ }
+ return getValueForField(result, result.getClass(), annotation, true);
+ }
+
+ private Object getValueForField(Object result, Class<?> resultClass,
+ Class<? extends Annotation> annotation, boolean inherited) {
+ if(result == null) {
+ return null;
+ }
+
+ Field[] fields = resultClass.getDeclaredFields();
+ for (Field field : fields) {
+ if(field.getAnnotation(annotation) != null) {
+ try {
+ boolean access = field.isAccessible();
+ field.setAccessible(true);
+ Object value = field.get(result);
+ field.setAccessible(access);
+ return value;
+ } catch (IllegalArgumentException ex) { // should never happen
+ throw new ODataRuntimeException(ex);
+ } catch (IllegalAccessException ex) { // should never happen
+ throw new ODataRuntimeException(ex);
+ }
+ }
+ }
+
+ Class<?> superClass = result.getClass().getSuperclass();
+ if(inherited && superClass != Object.class) {
+ return getValueForField(result, superClass, annotation, true);
+ }
+
+ return null;
+ }
+
public boolean isEdmAnnotated(Object object) {
if(object == null) {
return false;
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/5af55593/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/ClassHelper.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/ClassHelper.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/ClassHelper.java
index 2094591..2a4c706 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/ClassHelper.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/ClassHelper.java
@@ -75,6 +75,8 @@ public class ClassHelper {
annotatedClasses.add(c);
}
} catch (ClassNotFoundException ex) {
+ throw new IllegalArgumentException("Exception during class loading of class '" + fqn +
+ "' with message '" + ex.getMessage() + "'.");
}
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/5af55593/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/AnnotationProcessor.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/AnnotationProcessor.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/AnnotationProcessor.java
index faf129c..d06bd3f 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/AnnotationProcessor.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/AnnotationProcessor.java
@@ -29,6 +29,8 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceContent;
+import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceMimeType;
import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
import org.apache.olingo.odata2.api.commons.HttpStatusCodes;
import org.apache.olingo.odata2.api.exception.ODataException;
@@ -47,6 +49,7 @@ import org.apache.olingo.odata2.api.annotation.edm.ds.EntityRead;
import org.apache.olingo.odata2.api.annotation.edm.ds.EntitySetRead;
import org.apache.olingo.odata2.api.annotation.edm.ds.EntityUpdate;
import org.apache.olingo.odata2.api.processor.ODataContext;
+import org.apache.olingo.odata2.api.uri.info.GetMediaResourceUriInfo;
import org.apache.olingo.odata2.core.exception.ODataRuntimeException;
import org.apache.olingo.odata2.core.annotation.edm.AnnotationHelper;
import org.apache.olingo.odata2.core.annotation.edm.ClassHelper;
@@ -149,6 +152,30 @@ public class AnnotationProcessor extends ODataSingleProcessor {
return ODataResponse.status(HttpStatusCodes.NOT_FOUND).build();
}
+ @Override
+ public ODataResponse readEntityMedia(GetMediaResourceUriInfo uriInfo, String contentType) throws ODataException {
+ final String name = uriInfo.getTargetType().getName();
+
+ List<KeyPredicate> keys = uriInfo.getKeyPredicates();
+ Object result = readEntity(name, keys);
+ if (result != null) {
+ Object content = new AnnotationHelper().getValueForField(result, EdmMediaResourceContent.class);
+ Object mimeType = new AnnotationHelper().getValueForField(result, EdmMediaResourceMimeType.class);
+ return ODataResponse.status(HttpStatusCodes.OK).entity(content).contentHeader(String.valueOf(mimeType)).build();
+ }
+
+ return ODataResponse.status(HttpStatusCodes.NOT_FOUND).build();
+ }
+
+ private Object readEntity(String entityName, List<KeyPredicate> keys) {
+ DataSourceHolder holder = dataSources.get(entityName);
+ if (holder != null) {
+ return holder.readEntity(keys);
+ }
+ return null;
+ }
+
+
private ODataResponse createODataResponse(Object result, HttpStatusCodes statusCode) throws ODataException {
// StringBuilder resultAsString = new StringBuilder("{\"d\":");
// if (result != null) {
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/5af55593/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/json/EdmAnnotationSerializer.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/json/EdmAnnotationSerializer.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/json/EdmAnnotationSerializer.java
index 01ccf2c..10b8945 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/json/EdmAnnotationSerializer.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/json/EdmAnnotationSerializer.java
@@ -1,21 +1,17 @@
-/*******************************************************************************
- * 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
- *
+/**
+ * *****************************************************************************
+ * 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.
- ******************************************************************************/
+ *
+ * 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.core.annotation.processor.json;
import java.io.ByteArrayInputStream;
@@ -29,11 +25,18 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
+import org.apache.olingo.odata2.api.edm.EdmLiteralKind;
+import org.apache.olingo.odata2.api.edm.EdmSimpleType;
+import org.apache.olingo.odata2.api.edm.EdmSimpleTypeException;
+import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
import org.apache.olingo.odata2.core.annotation.edm.AnnotationHelper;
import org.apache.olingo.odata2.core.exception.ODataRuntimeException;
@@ -66,7 +69,7 @@ public class EdmAnnotationSerializer {
}
}
- private String handleEdmAnnotations(Object entity)
+ private String handleEdmAnnotations(Object entity)
throws IllegalArgumentException, IllegalAccessException, IOException {
//
Writer writer = new StringWriter();
@@ -80,10 +83,10 @@ public class EdmAnnotationSerializer {
}
private void writeObject(Object entity, JsonWriter json) throws IllegalAccessException {
- if(entity.getClass().isArray()) {
+ if (entity.getClass().isArray()) {
List<Object> entities = Arrays.asList(entity);
writeCollection(entities, json);
- } else if(Collection.class.isAssignableFrom(entity.getClass())) {
+ } else if (Collection.class.isAssignableFrom(entity.getClass())) {
Collection<Object> entities = (Collection<Object>) entity;
writeCollection(entities, json);
} else {
@@ -97,7 +100,7 @@ public class EdmAnnotationSerializer {
json.startArray();
boolean writeSeperator = false;
for (Object object : entities) {
- if(writeSeperator) {
+ if (writeSeperator) {
json.writeSeparator();
} else {
writeSeperator = true;
@@ -107,7 +110,7 @@ public class EdmAnnotationSerializer {
json.endArray();
json.endObject();
}
-
+
private void writeSingleObject(Object entity, JsonWriter json) throws IllegalAccessException {
List<Field> fields = getAllFields(entity.getClass());
json.startObject();
@@ -120,14 +123,14 @@ public class EdmAnnotationSerializer {
json.endObject();
}
- private boolean writeEdmNavigationProperty(Object entity, JsonWriter json, Field field)
+ private boolean writeEdmNavigationProperty(Object entity, JsonWriter json, Field field)
throws IllegalArgumentException, IllegalAccessException {
EdmNavigationProperty navProperty = field.getAnnotation(EdmNavigationProperty.class);
EdmEntityType entityType = entity.getClass().getAnnotation(EdmEntityType.class);
if (navProperty != null) {
field.setAccessible(true);
Object keyValue = extractEdmKey(entity);
- json.writeProperty("uri", baseUri + entityType.entitySetName() + "('" + keyValue.toString() + "')"
+ json.writeStringProperty("uri", baseUri + entityType.entitySetName() + "('" + keyValue.toString() + "')"
+ "/" + navProperty.relationship());
return true;
}
@@ -140,18 +143,63 @@ public class EdmAnnotationSerializer {
field.setAccessible(true);
Object fieldValue = field.get(entity);
String name = getName(property, field);
- Class<?> defaultType = getType(property);
- json.writeProperty(name, fieldValue, defaultType);
+ EdmSimpleTypeKind defaultType = getDefaultSimpleTypeKind(field, property);
+ try {
+ String value = defaultType.getEdmSimpleTypeInstance().valueToString(fieldValue, EdmLiteralKind.JSON, null);
+ write(defaultType, name, value, json);
+ } catch (EdmSimpleTypeException e) {
+ throw new IllegalArgumentException("Illegal argument for valueToString for EdmSimpleType = '"
+ + property.type() + "' with message = '" + e.getMessage() + "'.");
+ }
return true;
}
return false;
}
+ public void write(EdmSimpleTypeKind kind, String name, String value, JsonWriter jsonStreamWriter) {
+ switch (kind) {
+ case String:
+ jsonStreamWriter.writeStringProperty(name, value);
+ break;
+ case Boolean:
+ case Byte:
+ case SByte:
+ case Int16:
+ case Int32:
+ jsonStreamWriter.writeRawProperty(name, value);
+ break;
+ case DateTime:
+ case DateTimeOffset:
+ // Although JSON escaping is (and should be) done in the JSON
+ // serializer, we backslash-escape the forward slash here explicitly
+ // because it is not required to escape it in JSON but in OData.
+ jsonStreamWriter.writeRawStringProperty(name, value == null ? null : value.replace("/", "\\/"));
+ break;
+ default:
+ jsonStreamWriter.writeRawStringProperty(name, value);
+ break;
+ }
+ }
+
+ private EdmSimpleTypeKind getDefaultSimpleTypeKind(Field field, EdmProperty property) {
+ final EdmSimpleTypeKind type = property.type();
+ if (type == EdmSimpleTypeKind.Null) {
+ Class<?> fieldType = field.getType();
+ if (fieldType == String.class) {
+ return EdmSimpleTypeKind.String;
+ } else if (fieldType == Long.class) {
+ return EdmSimpleTypeKind.Int64;
+ } else if (fieldType == Integer.class) {
+ return EdmSimpleTypeKind.Int32;
+ }
+ }
+ return type;
+ }
+
private Class<?> getType(EdmProperty property) {
Class<?> defaultType = property.type().getEdmSimpleTypeInstance().getDefaultType();
return defaultType;
}
-
private Object extractEdmKey(Object value) throws IllegalArgumentException, IllegalAccessException {
Field idField = getFieldWithAnnotation(value.getClass(), EdmKey.class);
@@ -192,13 +240,13 @@ public class EdmAnnotationSerializer {
}
private boolean isConsumable(Object entity) {
- if(entity == null) {
+ if (entity == null) {
return false;
- } else if(ANNOTATION_HELPER.isEdmAnnotated(entity)) {
+ } else if (ANNOTATION_HELPER.isEdmAnnotated(entity)) {
return true;
- } else if(entity.getClass().isArray() || entity.getClass().isAssignableFrom(Collection.class)) {
+ } else if (entity.getClass().isArray() || entity.getClass().isAssignableFrom(Collection.class)) {
return true;
- } else if(Collection.class.isAssignableFrom(entity.getClass())) {
+ } else if (Collection.class.isAssignableFrom(entity.getClass())) {
return true;
}
return false;
@@ -206,9 +254,9 @@ public class EdmAnnotationSerializer {
private String getName(EdmProperty property, Field field) {
String name = property.name();
- if(name.isEmpty()) {
+ if (name.isEmpty()) {
name = ANNOTATION_HELPER.getCanonicalName(field);
}
return name;
}
-}
\ No newline at end of file
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/5af55593/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/json/JsonWriter.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/json/JsonWriter.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/json/JsonWriter.java
index 1c1cc21..b972fed 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/json/JsonWriter.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/processor/json/JsonWriter.java
@@ -1,21 +1,17 @@
-/*******************************************************************************
- * 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
- *
+/**
+ * *****************************************************************************
+ * 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.
- ******************************************************************************/
+ *
+ * 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.core.annotation.processor.json;
import java.io.IOException;
@@ -97,78 +93,47 @@ public class JsonWriter {
}
}
- public void writeString(String value) {
+ public void writeRawString(String value) {
try {
- writer.write("\"" + encode(value) + "\"");
+ writer.write("\"" + value + "\"");
} catch (IOException e) {
throw new ODataRuntimeException(e.getMessage(), e);
}
}
- public void writeNull() {
+ public void writeString(String value) {
try {
- writer.write("null");
+ writer.write("\"" + encode(value) + "\"");
} catch (IOException e) {
throw new ODataRuntimeException(e.getMessage(), e);
}
}
- public void writeNumber(int value) {
+ public void writeNull() {
try {
- writer.write(Integer.toString(value));
+ writer.write("null");
} catch (IOException e) {
throw new ODataRuntimeException(e.getMessage(), e);
}
}
- public void writeNumber(float value) {
- try {
- String fvalue = Float.toString(value);
- while (fvalue.contains(".") && fvalue.endsWith("0")) {
- fvalue = fvalue.substring(0, fvalue.length() - 1);
- }
- if (fvalue.endsWith(".")) {
- fvalue = fvalue.substring(0, fvalue.length() - 1);
- }
- writer.write(fvalue);
- } catch (IOException e) {
- throw new ODataRuntimeException(e.getMessage(), e);
+ public void writeStringProperty(String name, String value) {
+ if (value == null) {
+ writeProperty(name, value, false);
+ } else {
+ writeProperty(name, encode(value), false);
}
}
- public void writeNumber(double value) {
- try {
- String fvalue = Double.toString(value);
- while (fvalue.contains(".") && fvalue.endsWith("0")) {
- fvalue = fvalue.substring(0, fvalue.length() - 1);
- }
- if (fvalue.endsWith(".")) {
- fvalue = fvalue.substring(0, fvalue.length() - 1);
- }
- writer.write(fvalue);
- } catch (IOException e) {
- throw new ODataRuntimeException(e.getMessage(), e);
- }
+ public void writeRawStringProperty(String name, String value) {
+ writeProperty(name, value, false);
}
- public void writeBoolean(boolean value) {
- try {
- writer.write(value ? "true" : "false");
- } catch (IOException e) {
- throw new ODataRuntimeException(e.getMessage(), e);
- }
+ public void writeRawProperty(String name, String value) {
+ writeProperty(name, value, true);
}
- public void writeProperty(String name, Object value) {
- if(value == null) {
- writeProperty(name, value, null);
- } else {
- writeProperty(name, value, value.getClass());
- }
- }
-
-
- void writeProperty(String name, Object value, Class<?> defaultType) {
+ private void writeProperty(String name, String value, boolean raw) {
if (firstProperty) {
firstProperty = false;
} else {
@@ -181,10 +146,10 @@ public class JsonWriter {
writeNull();
} else {
try {
- if(defaultType == null) {
- writeValue(value);
+ if (raw) {
+ writeRaw(value);
} else {
- writeValueAs(value, defaultType);
+ writeString(value);
}
} catch (Exception e) {
writeString("exception for property with name '" + name
@@ -192,10 +157,10 @@ public class JsonWriter {
+ "' and toString '" + value.toString() + "'.");
}
}
+
}
-
- public void writeRaw(String value) {
+ private void writeRaw(String value) {
try {
writer.write(value);
} catch (IOException e) {
@@ -228,29 +193,11 @@ public class JsonWriter {
return sb.toString();
}
- void start() {
+ public void start() {
writeRaw("{\n\"d\":");
}
- void finish() {
+ public void finish() {
writeRaw("\n}");
}
-
- private void writeValueAs(Object value, Class<?> clazz) {
- if(clazz.isAssignableFrom(String.class)) {
- writeString(String.valueOf(value));
- } else if(clazz.isAssignableFrom(Float.class)) {
- writeNumber((Float) value);
- } else if(clazz.isAssignableFrom(Double.class)) {
- writeNumber((Double) value);
- } else if(clazz.isAssignableFrom(Integer.class)) {
- writeNumber((Integer) value);
- } else {
- writeString(value.toString());
- }
- }
-
- private void writeValue(Object value) {
- writeValueAs(value, value.getClass());
- }
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/5af55593/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Photo.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Photo.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Photo.java
index fd74c30..7fab9bc 100644
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Photo.java
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Photo.java
@@ -19,33 +19,42 @@
package org.apache.olingo.odata2.ref.annotation.model;
import java.util.Arrays;
+import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
+import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceContent;
+import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceMimeType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmMediaResourceSource;
+import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
+import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
/**
*
*/
+@EdmEntityType(name = "Photo", namespace = ModelSharedConstants.NAMESPACE_1,
+ entitySetName = "Photos", container = ModelSharedConstants.CONTAINER_1)
public class Photo {
private static final String RESOURCE = "/male_1_WinterW.jpg";
- private static byte[] defaultImage = ResourceHelper.loadAsByte(RESOURCE);
- private int id;
+ @EdmProperty
+ @EdmKey
private String name;
- private String type = "image/jpeg";
+ @EdmProperty
+ private String type;
+ @EdmProperty
+ @EdmMediaResourceMimeType
+ private String mimeType;
+ @EdmProperty
+ @EdmMediaResourceSource
private String imageUrl = "http://localhost" + RESOURCE;
- private byte[] image = defaultImage;
- private String imageType = type;
- private byte[] binaryData;
- private String content;
+ @EdmProperty(type = EdmSimpleTypeKind.Binary)
+ @EdmMediaResourceContent
+ private byte[] image = ResourceHelper.generateImage();
- public Photo(final int id, final String name, final String type) {
- this.id = id;
+ public Photo(final String name, final String type) {
this.name = name;
this.type = type;
}
- public int getId() {
- return id;
- }
-
public String getName() {
return name;
}
@@ -79,53 +88,45 @@ public class Photo {
}
public String getImageType() {
- return imageType;
+ return mimeType;
}
public void setImageType(final String imageType) {
- this.imageType = imageType;
- }
-
- public byte[] getBinaryData() {
- if (binaryData == null) {
- return null;
- } else {
- return binaryData.clone();
- }
- }
-
- public void setBinaryData(final byte[] binaryData) {
- this.binaryData = binaryData;
- }
-
- public void setContent(final String content) {
- this.content = content;
- }
-
- public String getContent() {
- return content;
+ this.mimeType = imageType;
}
@Override
public int hashCode() {
- return id;
+ int hash = 5;
+ hash = 83 * hash + (this.name != null ? this.name.hashCode() : 0);
+ hash = 83 * hash + (this.type != null ? this.type.hashCode() : 0);
+ return hash;
}
@Override
- public boolean equals(final Object obj) {
- return this == obj
- || obj != null && getClass() == obj.getClass() && id == ((Photo) obj).id;
+ public boolean equals(Object obj) {
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ final Photo other = (Photo) obj;
+ if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) {
+ return false;
+ }
+ if ((this.type == null) ? (other.type != null) : !this.type.equals(other.type)) {
+ return false;
+ }
+ return true;
}
-
+
@Override
public String toString() {
- return "{\"Id\":" + id + ","
- + "\"Name\":\"" + name + "\","
+ return "{\"Name\":\"" + name + "\","
+ "\"Type\":\"" + type + "\","
+ "\"ImageUrl\":\"" + imageUrl + "\","
+ "\"Image\":\"" + Arrays.toString(image) + "\","
- + "\"ImageType\":\"" + imageType + "\","
- + "\"Content:\"" + content + "\","
- + "\"BinaryData\":\"" + Arrays.toString(binaryData) + "\"}";
+ + "\"MimeType\":\"" + mimeType + "\"";
}
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/5af55593/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ResourceHelper.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ResourceHelper.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ResourceHelper.java
index 97ace81..07ee5b4 100644
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ResourceHelper.java
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ResourceHelper.java
@@ -18,11 +18,16 @@
******************************************************************************/
package org.apache.olingo.odata2.ref.annotation.model;
+import java.awt.image.BufferedImage;
+import java.awt.image.WritableRaster;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.nio.ByteBuffer;
import java.util.logging.Level;
import java.util.logging.Logger;
+import javax.imageio.ImageIO;
+import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
/**
*
@@ -57,4 +62,46 @@ class ResourceHelper {
}
}
}
+
+ static byte[] generateImage() {
+ try {
+ // ByteArrayOutputStream outStream = new ByteArrayOutputStream();
+// String format = "PNG";
+// int width = 200;
+// int height = 200;
+// int imageType = BufferedImage.TYPE_BYTE_BINARY;
+// BufferedImage image = new BufferedImage(width, height, imageType);
+// ImageIO.write(image, format, outStream);
+// return null;
+
+ return test();
+ } catch (IOException ex) {
+ return new byte[0];
+ }
+ }
+
+ private static byte[] test() throws IOException {
+ int width = 400; // Dimensions of the image
+ int height = 400;
+ // Let's create a BufferedImage for a binary image.
+ BufferedImage im = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_BINARY);
+ // We need its raster to set the pixels' values.
+ WritableRaster raster = im.getRaster();
+ // Put the pixels on the raster. Note that only values 0 and 1 are used for the pixels.
+ // You could even use other values: in this type of image, even values are black and odd
+ // values are white.
+ for (int h = 0; h < height; h++) {
+ for (int w = 0; w < width; w++) {
+ if (((h / 50) + (w / 50)) % 2 == 0) {
+ raster.setSample(w, h, 0, 0); // checkerboard pattern.
+ } else {
+ raster.setSample(w, h, 0, 1);
+ }
+ }
+ }
+ // Store the image using the PNG format.
+ ByteArrayOutputStream out = new ByteArrayOutputStream(1024*10);
+ ImageIO.write(im, "PNG", out);
+ return out.toByteArray();
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/5af55593/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ds/PhotoDs.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ds/PhotoDs.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ds/PhotoDs.java
new file mode 100644
index 0000000..660f59c
--- /dev/null
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/ds/PhotoDs.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2013 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * 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.ref.annotation.model.ds;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.olingo.odata2.api.annotation.edm.ds.EntityCreate;
+import org.apache.olingo.odata2.api.annotation.edm.ds.EntityDataSource;
+import org.apache.olingo.odata2.api.annotation.edm.ds.EntityRead;
+import org.apache.olingo.odata2.api.annotation.edm.ds.EntitySetRead;
+import org.apache.olingo.odata2.api.annotation.edm.ds.EntityUpdate;
+import org.apache.olingo.odata2.ref.annotation.model.Photo;
+
+/**
+ *
+ */
+@EntityDataSource(entityType = Photo.class)
+public class PhotoDs {
+ private static final Map<String, Photo> photoDb = new HashMap<String, Photo>();
+
+ private String createPhotoId(Photo p) {
+ if(p == null) {
+ return null;
+ }
+ return p.getName() + "-" + p.getType();
+ }
+
+ @EntityCreate
+ @EntityUpdate
+ public Photo storePhoto(Photo photo) {
+ Photo p = new Photo(photo.getName(), photo.getType());
+ p.setImageUri(photo.getImageUri());
+ p.setImageType(photo.getImageType());
+
+ photoDb.put(createPhotoId(p), p);
+
+ return p;
+ }
+
+ @EntityRead
+ public Photo loadPhoto(String name) {
+ return photoDb.get(createPhotoId(new Photo(name, "PNG")));
+ }
+
+ @EntitySetRead
+ public Collection<Photo> loadAllPhotos() {
+ return photoDb.values();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/5af55593/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/processor/ScenarioServiceFactory.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/processor/ScenarioServiceFactory.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/processor/ScenarioServiceFactory.java
index 7ff3ee4..d04f6f4 100644
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/processor/ScenarioServiceFactory.java
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/processor/ScenarioServiceFactory.java
@@ -27,8 +27,10 @@ import org.apache.olingo.odata2.api.processor.ODataContext;
import org.apache.olingo.odata2.core.annotation.edm.AnnotationEdmProvider;
import org.apache.olingo.odata2.core.annotation.processor.AnnotationProcessor;
import org.apache.olingo.odata2.ref.annotation.model.Building;
+import org.apache.olingo.odata2.ref.annotation.model.Photo;
import org.apache.olingo.odata2.ref.annotation.model.Team;
import org.apache.olingo.odata2.ref.annotation.model.ds.BuildingDs;
+import org.apache.olingo.odata2.ref.annotation.model.ds.PhotoDs;
import org.apache.olingo.odata2.ref.annotation.model.ds.TeamDs;
/**
@@ -58,7 +60,6 @@ public class ScenarioServiceFactory extends ODataServiceFactory {
? new ScenarioDebugCallback() : super.getCallback(callbackInterface));
}
-
private final class ScenarioDebugCallback implements ODataDebugCallback {
@Override
@@ -80,6 +81,11 @@ public class ScenarioServiceFactory extends ODataServiceFactory {
buildingsDs.createOrUpdate(createBuilding("Red Building"));
buildingsDs.createOrUpdate(createBuilding("Green Building"));
buildingsDs.createOrUpdate(createBuilding("Blue Building"));
+
+ PhotoDs photoDs = new PhotoDs();
+ photoDs.storePhoto(createPhoto("Small picture"));
+ photoDs.storePhoto(createPhoto("Medium picture"));
+ photoDs.storePhoto(createPhoto("Big picture"));
}
private Team createTeam(String teamName, boolean isScrumTeam) {
@@ -94,4 +100,11 @@ public class ScenarioServiceFactory extends ODataServiceFactory {
b.setName(buildingName);
return b;
}
+
+ private Photo createPhoto(String name) {
+ Photo p = new Photo(name, "PNG");
+ p.setImageType("image/png");
+ p.setImageUri("http://localhost/image/" + name);
+ return p;
+ }
}
[22/52] git commit: Fixes for annotation conventions
Posted by mi...@apache.org.
Fixes for annotation conventions
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/a8ff9e21
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/a8ff9e21
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/a8ff9e21
Branch: refs/heads/master
Commit: a8ff9e2119a1c316b5a302929ad218b037647eae
Parents: c679150
Author: Michael Bolz <mi...@apache.org>
Authored: Thu Nov 14 14:34:33 2013 +0100
Committer: Michael Bolz <mi...@apache.org>
Committed: Thu Nov 14 14:34:33 2013 +0100
----------------------------------------------------------------------
.../annotation/edm/AnnotationEdmProvider.java | 75 ++++++++++++++------
.../edm/AnnotationEdmProviderTest.java | 28 ++++++--
.../odata2/core/annotation/model/Employee.java | 3 +
.../odata2/core/annotation/model/Room.java | 4 +-
.../odata2/core/annotation/model/Team.java | 5 +-
5 files changed, 80 insertions(+), 35 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/a8ff9e21/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java
index 4ce8563..b7aa89b 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java
@@ -79,8 +79,6 @@ public class AnnotationEdmProvider extends EdmProvider {
public AnnotationEdmProvider(Collection<Class<?>> annotatedClasses) {
-// this.annotatedClasses = new ArrayList<Class<?>>(annotatedClasses);
-// this.annotatedClasses.addAll(annotatedClasses);
this.annotatedClasses = new ArrayList<Class<?>>(annotatedClasses.size());
for (Class<?> aClass : annotatedClasses) {
if (ANNOTATION_HELPER.isEdmAnnotated(aClass)) {
@@ -274,7 +272,7 @@ public class AnnotationEdmProvider extends EdmProvider {
private void handleEntityContainer(Class<?> aClass) {
EdmEntityType entityType = aClass.getAnnotation(EdmEntityType.class);
if (entityType != null) {
- String containerName = getContainerName(entityType);
+ String containerName = getCanonicalContainerName(entityType);
ContainerBuilder builder = containerName2ContainerBuilder.get(containerName);
if (builder == null) {
builder = ContainerBuilder.init(entityType.namespace(), containerName);
@@ -322,7 +320,7 @@ public class AnnotationEdmProvider extends EdmProvider {
}
}
- private String getContainerName(EdmEntityType entity) {
+ private String getCanonicalContainerName(EdmEntityType entity) {
return DEFAULT_CONTAINER_NAME;
}
@@ -499,27 +497,40 @@ public class AnnotationEdmProvider extends EdmProvider {
entityName = getCanonicalName(field);
}
navProp.setName(entityName);
- navProp.setRelationship(new FullQualifiedName(namespace, enp.association()));
//
NavigationEnd from = enp.from();
String fromRole = from.role();
if (fromRole.isEmpty()) {
- fromRole = getCanonicalRole(field.getDeclaringClass());
+ fromRole = getCanonicalRole(from, field.getDeclaringClass());
}
navProp.setFromRole(fromRole);
NavigationEnd to = enp.to();
String toRole = to.role();
if (toRole.isEmpty()) {
- toRole = getCanonicalRole(field.getType());
+ toRole = getCanonicalRole(to, field.getType());
}
navProp.setToRole(toRole);
+ String relationshipName = enp.association();
+ if(relationshipName.isEmpty()) {
+ if(fromRole.compareTo(toRole) > 0) {
+ relationshipName = toRole + "-" + fromRole;
+ } else {
+ relationshipName = fromRole + "-" + toRole;
+ }
+ }
+ navProp.setRelationship(new FullQualifiedName(namespace, relationshipName));
+
return navProp;
}
- private String getCanonicalRole(Class<?> clazz) {
- return "r_" + clazz.getSimpleName();
+ private String getCanonicalRole(NavigationEnd navEnd, Class<?> fallbackClass) {
+ String toRole = extractEntitTypeName(navEnd.entitySet());
+ if(toRole == null) {
+ toRole = extractEntitTypeName(fallbackClass);
+ }
+ return "r_" + toRole;
}
private EdmSimpleTypeKind getEdmSimpleType(Class<?> type) {
@@ -532,8 +543,7 @@ public class AnnotationEdmProvider extends EdmProvider {
} else if (type == Byte[].class || type == byte[].class) {
return EdmSimpleTypeKind.Binary;
} else {
- throw new UnsupportedOperationException("Not supported type '" + type
- + "' yet."); //To change body of generated methods, choose Tools | Templates.
+ throw new UnsupportedOperationException("Not yet supported type '" + type + "'.");
}
}
@@ -565,7 +575,6 @@ public class AnnotationEdmProvider extends EdmProvider {
private Association createAssociation(Field field, NavigationProperty navProperty) {
Association association = new Association();
- association.setName(navProperty.getRelationship().getName());
EdmNavigationProperty navigation = field.getAnnotation(EdmNavigationProperty.class);
NavigationEnd from = navigation.from();
@@ -573,9 +582,7 @@ public class AnnotationEdmProvider extends EdmProvider {
fromEnd.setRole(navProperty.getFromRole());
String typeName = extractEntitTypeName(from);
if (typeName.isEmpty()) {
- Class<?> fromClass = field.getDeclaringClass();
- EdmEntityType entityType = fromClass.getAnnotation(EdmEntityType.class);
- typeName = entityType.name();
+ typeName = extractEntitTypeName(field.getDeclaringClass());
}
fromEnd.setType(new FullQualifiedName(namespace, typeName));
fromEnd.setMultiplicity(from.multiplicity());
@@ -584,16 +591,11 @@ public class AnnotationEdmProvider extends EdmProvider {
NavigationEnd to = navigation.to();
AssociationEnd toEnd = new AssociationEnd();
toEnd.setRole(navProperty.getToRole());
- final FullQualifiedName toFqn;
String toTypeName = extractEntitTypeName(to);
if (toTypeName.isEmpty()) {
- Class<?> toClass = field.getType();
- EdmEntityType entityType = toClass.getAnnotation(EdmEntityType.class);
- toFqn = new FullQualifiedName(namespace, entityType.name());
- } else {
- toFqn = new FullQualifiedName(namespace, toTypeName);
+ toTypeName = extractEntitTypeName(field.getType());
}
- toEnd.setType(toFqn);
+ toEnd.setType(new FullQualifiedName(namespace, toTypeName));
EdmMultiplicity toMultiplicity = to.multiplicity();
Class<?> toClass = field.getType();
@@ -604,15 +606,20 @@ public class AnnotationEdmProvider extends EdmProvider {
} else {
toEnd.setMultiplicity(toMultiplicity);
}
-
association.setEnd2(toEnd);
+ String associationName = navProperty.getRelationship().getName();
+ association.setName(associationName);
return association;
}
private String getCanonicalName(Field field) {
return ANNOTATION_HELPER.getCanonicalName(field);
}
+
+ private String getCanonicalName(Class<?> clazz) {
+ return ANNOTATION_HELPER.getCanonicalName(clazz);
+ }
private boolean isAnnotatedEntity(Class<?> clazz) {
boolean isComplexEntity = clazz.getAnnotation(EdmComplexType.class) != null;
@@ -631,6 +638,28 @@ public class AnnotationEdmProvider extends EdmProvider {
}
return type.name();
}
+
+ /**
+ * Returns <code>NULL</code> if given class is not annotated.
+ * If annotated the set entity type name is returned and if no name is set the
+ * default name is generated from the simple class name.
+ *
+ * @param annotatedClass
+ * @return
+ */
+ private String extractEntitTypeName(Class<?> annotatedClass) {
+ if(annotatedClass == Object.class) {
+ return null;
+ }
+ EdmEntityType type = annotatedClass.getAnnotation(EdmEntityType.class);
+ if(type == null) {
+ return null;
+ }
+ if(type.name().isEmpty()) {
+ return getCanonicalName(annotatedClass);
+ }
+ return type.name();
+ }
}
static class SchemaBuilder {
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/a8ff9e21/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProviderTest.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProviderTest.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProviderTest.java
index c6a9219..4a875a2 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProviderTest.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProviderTest.java
@@ -86,7 +86,7 @@ public class AnnotationEdmProviderTest {
assertEquals(1, employeeKeys.size());
assertEquals("EmployeeId", employeeKeys.get(0).getName());
assertEquals(4, employee.getProperties().size());
- assertEquals(1, employee.getNavigationProperties().size());
+ assertEquals(3, employee.getNavigationProperties().size());
List<Schema> schemas = localAep.getSchemas();
assertEquals(1, schemas.size());
@@ -167,7 +167,7 @@ public class AnnotationEdmProviderTest {
if(name.equals("RoomEmployees")) {
validateAssociation(association,
"r_Room", EdmMultiplicity.ONE, defaultFqn("Room"),
- "r_Employees", EdmMultiplicity.MANY, defaultFqn("Employee"));
+ "r_Employee", EdmMultiplicity.MANY, defaultFqn("Employee"));
} else if(name.equals("BuildingRooms")) {
validateAssociation(association,
"r_Building", EdmMultiplicity.ONE, defaultFqn("Building"),
@@ -176,10 +176,10 @@ public class AnnotationEdmProviderTest {
validateAssociation(association,
"r_Manager", EdmMultiplicity.ONE, defaultFqn("Manager"),
"r_Employees", EdmMultiplicity.MANY, defaultFqn("Employee"));
- } else if(name.equals("TeamEmployees")) {
+ } else if(name.equals("r_Employee-r_Team")) {
validateAssociation(association,
"r_Team", EdmMultiplicity.ONE, defaultFqn("Team"),
- "r_Employees", EdmMultiplicity.MANY, defaultFqn("Employee"));
+ "r_Employee", EdmMultiplicity.MANY, defaultFqn("Employee"));
} else {
fail("Got unknown association to validate with name '" + name + "'.");
}
@@ -227,8 +227,20 @@ public class AnnotationEdmProviderTest {
assertEquals(1, employeeKeys.size());
assertEquals("EmployeeId", employeeKeys.get(0).getName());
assertEquals(4, employee.getProperties().size());
- assertEquals(1, employee.getNavigationProperties().size());
- }
+ assertEquals(3, employee.getNavigationProperties().size());
+
+ for (NavigationProperty navigationProperty : employee.getNavigationProperties()) {
+ if (navigationProperty.getName().equals("ne_Manager")) {
+ validateNavProperty(navigationProperty, "ManagerEmployees", "r_Employees", "r_Manager");
+ } else if (navigationProperty.getName().equals("ne_Team")) {
+ validateNavProperty(navigationProperty, "r_Employee-r_Team", "r_Employee", "r_Team");
+ } else if (navigationProperty.getName().equals("ne_Room")) {
+ validateNavProperty(navigationProperty, "RoomEmployees", "r_Employee", "r_Room");
+ } else {
+ fail("Got unexpected navigation property with name '" + navigationProperty.getName() + "'.");
+ }
+ }
+}
@Test
public void entityTypeTeam() throws Exception {
@@ -240,6 +252,8 @@ public class AnnotationEdmProviderTest {
assertEquals(1, team.getProperties().size());
assertEquals(1, team.getNavigationProperties().size());
+ NavigationProperty navigationProperty= team.getNavigationProperties().get(0);
+ validateNavProperty(navigationProperty, "r_Employee-r_Team", "r_Team", "r_Employee");
}
@Test
@@ -293,7 +307,7 @@ public class AnnotationEdmProviderTest {
for (NavigationProperty navigationProperty : navigationProperties) {
if(navigationProperty.getName().equals("nr_Employees")) {
- validateNavProperty(navigationProperty, "RoomEmployees", "r_Room", "r_Employees");
+ validateNavProperty(navigationProperty, "RoomEmployees", "r_Room", "r_Employee");
} else if(navigationProperty.getName().equals("nr_Building")) {
validateNavProperty(navigationProperty, "BuildingRooms", "r_Room", "r_Building");
} else {
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/a8ff9e21/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Employee.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Employee.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Employee.java
index 6eda19c..a384689 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Employee.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Employee.java
@@ -48,7 +48,10 @@ public class Employee {
from = @NavigationEnd(role="r_Employees", entitySet=Employee.class, multiplicity=EdmMultiplicity.MANY))//,
// to = @NavigationEnd(type = "Manager"))
private Manager manager;
+ @EdmNavigationProperty(name = "ne_Team")
private Team team;
+ @EdmNavigationProperty(name = "ne_Room", association = "RoomEmployees",
+ from = @NavigationEnd(multiplicity = EdmMultiplicity.MANY))
private Room room;
private String imageType;
private byte[] image;
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/a8ff9e21/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Room.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Room.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Room.java
index 2f6be68..14319ef 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Room.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Room.java
@@ -40,8 +40,8 @@ public class Room extends RefBase {
from = @NavigationEnd(role = "r_Room", multiplicity = EdmMultiplicity.MANY))
private Building building;
@EdmNavigationProperty(name = "nr_Employees", association = "RoomEmployees",
- from = @NavigationEnd(role = "r_Room", entitySet = Room.class, multiplicity = EdmMultiplicity.ONE),
- to = @NavigationEnd(role = "r_Employees", entitySet = Employee.class, multiplicity = EdmMultiplicity.MANY))
+// from = @NavigationEnd(role = "r_Room", entitySet = Room.class, multiplicity = EdmMultiplicity.ONE),
+ to = @NavigationEnd(entitySet = Employee.class, multiplicity = EdmMultiplicity.MANY))
private List<Employee> employees = new ArrayList<Employee>();
public Room(final int id, final String name) {
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/a8ff9e21/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Team.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Team.java b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Team.java
index 2d37be4..e24c28b 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Team.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/test/java/org/apache/olingo/odata2/core/annotation/model/Team.java
@@ -37,9 +37,8 @@ import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
public class Team extends RefBase {
@EdmProperty(type = EdmSimpleTypeKind.Boolean)
private Boolean isScrumTeam;
- @EdmNavigationProperty(name = "ne_Teams", association="TeamEmployees",
- from = @NavigationEnd(role = "r_Team", entitySet = Team.class),
- to = @NavigationEnd(role = "r_Employees", entitySet = Employee.class, multiplicity = EdmMultiplicity.MANY))
+ @EdmNavigationProperty(name = "ne_Teams",
+ to = @NavigationEnd(entitySet = Employee.class, multiplicity = EdmMultiplicity.MANY))
private List<Employee> employees = new ArrayList<Employee>();
public Team() {
[18/52] git commit: Implementation for navigation (readRelated)
Posted by mi...@apache.org.
Implementation for navigation (readRelated)
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/454e178e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/454e178e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/454e178e
Branch: refs/heads/master
Commit: 454e178ed8cef5f47df3047cb12c4c461c6a3200
Parents: 20d6f02
Author: Michael Bolz <mi...@apache.org>
Authored: Tue Nov 12 10:35:19 2013 +0100
Committer: Michael Bolz <mi...@apache.org>
Committed: Tue Nov 12 14:06:26 2013 +0100
----------------------------------------------------------------------
.../annotation/ds/AnnotationInMemoryDs.java | 126 ++++++++----
.../annotation/ds/AnnotationValueAccess.java | 9 +
.../annotation/edm/AnnotationEdmProvider.java | 15 +-
.../core/annotation/edm/AnnotationHelper.java | 203 ++++++++++++++-----
.../odata2/ref/annotation/model/Building.java | 4 +
.../odata2/ref/annotation/model/Employee.java | 13 +-
.../odata2/ref/annotation/model/RefBase.java | 32 ++-
.../odata2/ref/annotation/model/Room.java | 2 +-
.../odata2/ref/annotation/model/Team.java | 11 +-
.../processor/AnnotationPocServiceFactory.java | 28 ++-
10 files changed, 320 insertions(+), 123 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/454e178e/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/ds/AnnotationInMemoryDs.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/ds/AnnotationInMemoryDs.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/ds/AnnotationInMemoryDs.java
index bdf5d77..999b2ab 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/ds/AnnotationInMemoryDs.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/ds/AnnotationInMemoryDs.java
@@ -1,41 +1,43 @@
-/*******************************************************************************
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
+/**
+ * *****************************************************************************
+ * 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.
- ******************************************************************************/
+ *
+ * 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.core.annotation.ds;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
+import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
import org.apache.olingo.odata2.api.data.ListsDataSource;
import org.apache.olingo.odata2.api.edm.EdmEntitySet;
import org.apache.olingo.odata2.api.edm.EdmException;
import org.apache.olingo.odata2.api.edm.EdmFunctionImport;
+import org.apache.olingo.odata2.api.edm.EdmMultiplicity;
import org.apache.olingo.odata2.api.exception.ODataApplicationException;
import org.apache.olingo.odata2.api.exception.ODataNotFoundException;
import org.apache.olingo.odata2.api.exception.ODataNotImplementedException;
import org.apache.olingo.odata2.core.annotation.edm.AnnotationHelper;
import org.apache.olingo.odata2.core.annotation.edm.ClassHelper;
+import org.apache.olingo.odata2.core.exception.ODataRuntimeException;
public class AnnotationInMemoryDs implements ListsDataSource {
@@ -62,7 +64,7 @@ public class AnnotationInMemoryDs implements ListsDataSource {
dataStores.put(entityType.name(), dhs);
}
}
-
+
public <T> DataStore<T> getDataStore(Class<T> clazz) {
return DataStore.createInMemory(clazz);
}
@@ -82,25 +84,24 @@ public class AnnotationInMemoryDs implements ListsDataSource {
}
@Override
- public Object readData(EdmEntitySet entitySet, Map<String, Object> keys)
- throws ODataNotFoundException, EdmException, ODataApplicationException {
+ public Object readData(EdmEntitySet entitySet, Map<String, Object> keys)
+ throws ODataNotFoundException, EdmException, ODataApplicationException {
final String name = entitySet.getEntityType().getName();
DataStore<Object> store = dataStores.get(name);
if (store != null) {
- Object keyInstance = store.createInstance();
- setKeyFields(keyInstance, keys.values().toArray());
+ Object keyInstance = store.createInstance();
+ ANNOTATION_HELPER.setKeyFields(keyInstance, keys.values().toArray());
- Object result = store.read(keyInstance);
- if (result != null) {
- return result;
- }
+ Object result = store.read(keyInstance);
+ if (result != null) {
+ return result;
+ }
}
throw new ODataNotFoundException(ODataNotFoundException.ENTITY);
}
-
@Override
public Object readData(EdmFunctionImport function, Map<String, Object> parameters, Map<String, Object> keys)
throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException {
@@ -111,14 +112,46 @@ public class AnnotationInMemoryDs implements ListsDataSource {
public Object readRelatedData(EdmEntitySet sourceEntitySet, Object sourceData, EdmEntitySet targetEntitySet,
Map<String, Object> targetKeys)
throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException {
- final Object data;
+
if (targetKeys.isEmpty()) {
- data = this.readData(targetEntitySet);
+ String sourceName = sourceEntitySet.getEntityType().getName();
+ DataStore sourceStore = dataStores.get(sourceName);
+
+ String targetName = targetEntitySet.getEntityType().getName();
+ DataStore targetStore = dataStores.get(targetName);
+
+ Field sourceFieldAtTarget = extractSourceField(sourceStore, targetStore);
+ if (sourceFieldAtTarget == null) {
+ throw new ODataRuntimeException("Missing source field for related data.");
+ }
+
+ Collection targetData = targetStore.read();
+ List resultData = new ArrayList();
+ for (Object targetInstance : targetData) {
+ Object targetNavigationInstance = getValue(sourceFieldAtTarget, targetInstance);
+ if(targetNavigationInstance instanceof Collection) {
+ Collection c = (Collection) targetNavigationInstance;
+ for (Object object : c) {
+ if (ANNOTATION_HELPER.keyMatch(sourceData, object)) {
+ resultData.add(targetInstance);
+ }
+ }
+ } else if (ANNOTATION_HELPER.keyMatch(sourceData, targetNavigationInstance)) {
+ resultData.add(targetInstance);
+ }
+ }
+
+ EdmNavigationProperty navProperty = sourceFieldAtTarget.getAnnotation(EdmNavigationProperty.class);
+ if(navProperty.from().multiplicity() == EdmMultiplicity.ONE) {
+ if(resultData.isEmpty()) {
+ return null;
+ }
+ return resultData.get(0);
+ }
+ return resultData;
} else {
- data = this.readData(targetEntitySet, targetKeys);
+ throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
}
-
- return data;
}
@Override
@@ -168,18 +201,27 @@ public class AnnotationInMemoryDs implements ListsDataSource {
throws ODataNotImplementedException, ODataNotFoundException, EdmException, ODataApplicationException {
throw new ODataNotImplementedException(ODataNotImplementedException.COMMON);
}
-
- private <T> T setKeyFields(T instance, Object[] keyValues) {
- List<Field> fields = ANNOTATION_HELPER.getAnnotatedFields(instance, EdmKey.class);
- if (fields.size() != keyValues.length) {
- throw new IllegalStateException("Wrong amount of key properties. Expected read keys = "
- + fields + " given key predicates = " + Arrays.toString(keyValues));
+ private Object getValue(Field field, Object instance) {
+ try {
+ boolean access = field.isAccessible();
+ field.setAccessible(true);
+ Object value = field.get(instance);
+ field.setAccessible(access);
+ return value;
+ } catch (IllegalArgumentException e) {
+ throw new ODataRuntimeException("Error for getting value of field '"
+ + field + "' at instance '" + instance + "'.", e);
+ } catch (IllegalAccessException e) {
+ throw new ODataRuntimeException("Error for getting value of field '"
+ + field + "' at instance '" + instance + "'.", e);
}
-
- String propertyName = ANNOTATION_HELPER.getCanonicalName(fields.get(0));
- ANNOTATION_HELPER.setValueForProperty(instance, propertyName, keyValues[0]);
+ }
- return instance;
+ private Field extractSourceField(DataStore sourceStore, DataStore targetStore) {
+ Class sourceDataTypeClass = sourceStore.getDataTypeClass();
+ Class targetDataTypeClass = targetStore.getDataTypeClass();
+
+ return ANNOTATION_HELPER.getCommonNavigationFieldFromTarget(sourceDataTypeClass, targetDataTypeClass);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/454e178e/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/ds/AnnotationValueAccess.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/ds/AnnotationValueAccess.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/ds/AnnotationValueAccess.java
index 2c8ac96..5963131 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/ds/AnnotationValueAccess.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/ds/AnnotationValueAccess.java
@@ -18,6 +18,7 @@
******************************************************************************/
package org.apache.olingo.odata2.core.annotation.ds;
+import java.util.Collection;
import org.apache.olingo.odata2.api.data.ValueAccess;
import org.apache.olingo.odata2.api.edm.EdmMapping;
import org.apache.olingo.odata2.api.edm.EdmProperty;
@@ -39,6 +40,14 @@ public class AnnotationValueAccess implements ValueAccess {
*/
@Override
public <T> Object getPropertyValue(final T data, final EdmProperty property) throws ODataException {
+ if(data instanceof Collection) {
+ Collection c = (Collection) data;
+ for (Object object : c) {
+ if(annotationHelper.isEdmAnnotated(data)) {
+ return annotationHelper.getValueForProperty(data, property.getName());
+ }
+ }
+ }
if(annotationHelper.isEdmAnnotated(data)) {
return annotationHelper.getValueForProperty(data, property.getName());
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/454e178e/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java
index 03cec0b..6fb69b7 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationEdmProvider.java
@@ -457,17 +457,20 @@ public class AnnotationEdmProvider extends EdmProvider {
private Property createComplexProperty(EdmProperty ep, Field field, String defaultNamespace) {
ComplexProperty cp = new ComplexProperty();
+ // settings from property
String entityName = ep.name();
if (entityName.isEmpty()) {
entityName = getCanonicalName(field);
}
cp.setName(entityName);
- //
- String entityNamespace = ep.namespace();
- if (entityNamespace.isEmpty()) {
- entityNamespace = defaultNamespace;
- }
- cp.setType(new FullQualifiedName(entityNamespace, entityName));
+
+ // settings from related complex entity
+ EdmComplexEntity ece = field.getType().getAnnotation(EdmComplexEntity.class);
+ String complexEntityNamespace = ece.namespace();
+ if (complexEntityNamespace.isEmpty()) {
+ complexEntityNamespace = defaultNamespace;
+ }
+ cp.setType(new FullQualifiedName(complexEntityNamespace, ece.name()));
return cp;
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/454e178e/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java
index cc9cd6c..1e1d31b 100644
--- a/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java
+++ b/odata2-edm-annotation/edm-annotation-core/src/main/java/org/apache/olingo/odata2/core/annotation/edm/AnnotationHelper.java
@@ -1,56 +1,131 @@
-/*******************************************************************************
- * 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
- *
+/**
+ * *****************************************************************************
+ * 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.
- ******************************************************************************/
+ *
+ * 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.core.annotation.edm;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
+import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import org.apache.olingo.odata2.api.annotation.edm.EdmComplexEntity;
import org.apache.olingo.odata2.api.annotation.edm.EdmEntityType;
+import org.apache.olingo.odata2.api.annotation.edm.EdmKey;
+import org.apache.olingo.odata2.api.annotation.edm.EdmNavigationProperty;
import org.apache.olingo.odata2.api.annotation.edm.EdmProperty;
+import org.apache.olingo.odata2.api.edm.EdmLiteralKind;
+import org.apache.olingo.odata2.api.edm.EdmSimpleTypeException;
+import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
import org.apache.olingo.odata2.api.exception.ODataException;
+import org.apache.olingo.odata2.core.annotation.ds.DataStore;
import org.apache.olingo.odata2.core.exception.ODataRuntimeException;
/**
*
*/
public class AnnotationHelper {
-
+
+ public boolean keyMatch(Object firstInstance, Object secondInstance) {
+ if (firstInstance == null || secondInstance == null) {
+ return false;
+ } else if (firstInstance.getClass() != secondInstance.getClass()) {
+ return false;
+ }
+
+ Map<String, Object> firstKeyFields = getValueForAnnotatedFields(firstInstance, EdmKey.class);
+ Map<String, Object> secondKeyFields = getValueForAnnotatedFields(secondInstance, EdmKey.class);
+
+ if (firstKeyFields.size() != secondKeyFields.size()) {
+ return false;
+ } else {
+ Set<Map.Entry<String, Object>> entries = firstKeyFields.entrySet();
+ for (Map.Entry<String, Object> entry : entries) {
+ Object firstKey = entry.getValue();
+ Object secondKey = secondKeyFields.get(entry.getKey());
+ if (!isEqual(firstKey, secondKey)) {
+ return false;
+ }
+ }
+ return true;
+ }
+ }
+
+ private boolean isEqual(Object firstKey, Object secondKey) {
+ if (firstKey == null) {
+ if (secondKey == null) {
+ return true;
+ } else {
+ return secondKey.equals(firstKey);
+ }
+ } else {
+ return firstKey.equals(secondKey);
+ }
+ }
+
public static final class ODataAnnotationException extends ODataException {
+
public ODataAnnotationException(String message) {
super(message);
}
}
+ public <T> T setKeyFields(T instance, Object[] keyValues) {
+ List<Field> fields = getAnnotatedFields(instance, EdmKey.class);
+ if (fields.size() != keyValues.length) {
+ throw new IllegalStateException("Wrong amount of key properties. Expected read keys = "
+ + fields + " given key predicates = " + Arrays.toString(keyValues));
+ }
+
+ String propertyName = getCanonicalName(fields.get(0));
+ setValueForProperty(instance, propertyName, keyValues[0]);
+
+ return instance;
+ }
+
+
+ public Field getCommonNavigationFieldFromTarget(Class<?> sourceClass, Class<?> targetClass) {
+ List<Field> sourceFields = getAnnotatedFields(sourceClass, EdmNavigationProperty.class);
+ List<Field> targetFields = getAnnotatedFields(targetClass, EdmNavigationProperty.class);
+
+ for (Field targetField : targetFields) {
+ for (Field sourcField : sourceFields) {
+ EdmNavigationProperty sourceNav = sourcField.getAnnotation(EdmNavigationProperty.class);
+ EdmNavigationProperty targetNav = targetField.getAnnotation(EdmNavigationProperty.class);
+ if (sourceNav.relationship().equals(targetNav.relationship())) {
+ return targetField;
+ }
+ }
+ }
+ return null;
+ }
+
+
public Class<?> getFieldTypeForProperty(Object instance, String propertyName) throws ODataAnnotationException {
if (instance == null) {
return null;
}
-
+
Field field = getFieldForPropertyName(instance, propertyName, instance.getClass(), true);
- if(field == null) {
- throw new ODataAnnotationException("No field for property '" + propertyName
+ if (field == null) {
+ throw new ODataAnnotationException("No field for property '" + propertyName
+ "' found at class '" + instance.getClass() + "'.");
}
return field.getType();
@@ -60,10 +135,10 @@ public class AnnotationHelper {
if (instance == null) {
return null;
}
-
+
Field field = getFieldForPropertyName(instance, propertyName, instance.getClass(), true);
- if(field == null) {
- throw new ODataAnnotationException("No field for property '" + propertyName
+ if (field == null) {
+ throw new ODataAnnotationException("No field for property '" + propertyName
+ "' found at class '" + instance.getClass() + "'.");
}
return getFieldValue(instance, field);
@@ -72,7 +147,7 @@ public class AnnotationHelper {
public void setValueForProperty(Object instance, String propertyName, Object propertyValue) {
if (instance != null) {
Field field = getFieldForPropertyName(instance, propertyName, instance.getClass(), true);
- if(field != null) {
+ if (field != null) {
setFieldValue(instance, field, propertyValue);
}
}
@@ -103,10 +178,8 @@ public class AnnotationHelper {
//
// return null;
// }
-
-
- private Field getFieldForPropertyName(Object instance, String propertyName,
- Class<?> resultClass, boolean inherited) {
+ private Field getFieldForPropertyName(Object instance, String propertyName,
+ Class<?> resultClass, boolean inherited) {
if (instance == null) {
return null;
}
@@ -115,9 +188,9 @@ public class AnnotationHelper {
for (Field field : fields) {
EdmProperty property = field.getAnnotation(EdmProperty.class);
if (property != null) {
- if(property.name().isEmpty() && getCanonicalName(field).equals(propertyName)) {
+ if (property.name().isEmpty() && getCanonicalName(field).equals(propertyName)) {
return field;
- } else if(property.name().equals(propertyName)) {
+ } else if (property.name().equals(propertyName)) {
return field;
}
}
@@ -131,7 +204,6 @@ public class AnnotationHelper {
return null;
}
-
public Object getValueForField(Object instance, String fieldName, Class<? extends Annotation> annotation) {
if (instance == null) {
return null;
@@ -147,7 +219,7 @@ public class AnnotationHelper {
}
private Object getValueForField(Object instance, Class<?> resultClass,
- Class<? extends Annotation> annotation, boolean inherited) {
+ Class<? extends Annotation> annotation, boolean inherited) {
return getValueForField(instance, null, resultClass, annotation, inherited);
}
@@ -155,16 +227,16 @@ public class AnnotationHelper {
Class<? extends Annotation> annotation) {
return getValueForAnnotatedFields(instance, instance.getClass(), annotation, true);
}
-
+
private Map<String, Object> getValueForAnnotatedFields(Object instance, Class<?> resultClass,
- Class<? extends Annotation> annotation, boolean inherited) {
+ Class<? extends Annotation> annotation, boolean inherited) {
if (instance == null) {
return null;
}
Field[] fields = resultClass.getDeclaredFields();
Map<String, Object> fieldName2Value = new HashMap<String, Object>();
-
+
for (Field field : fields) {
if (field.getAnnotation(annotation) != null) {
Object value = getFieldValue(instance, field);
@@ -181,41 +253,48 @@ public class AnnotationHelper {
return fieldName2Value;
}
- public void setValuesToAnnotatedFields(Map<String, Object> fieldName2Value, Object instance,
+ public void setValuesToAnnotatedFields(Map<String, Object> fieldName2Value, Object instance,
Class<? extends Annotation> annotation) {
- List<Field> fields = getAnnotatedFields(instance, instance.getClass(), annotation, true);
-
+ List<Field> fields = getAnnotatedFields(instance, annotation);
+
// XXX: refactore
for (Field field : fields) {
final String canonicalName = getCanonicalName(field);
- if(fieldName2Value.containsKey(canonicalName)) {
+ if (fieldName2Value.containsKey(canonicalName)) {
Object value = fieldName2Value.get(canonicalName);
setFieldValue(instance, field, value);
}
}
}
-
+
public List<Field> getAnnotatedFields(Object instance, Class<? extends Annotation> annotation) {
- return getAnnotatedFields(instance, instance.getClass(), annotation, true);
- }
-
+ if(instance == null) {
+ return null;
+ }
+ return getAnnotatedFields(instance.getClass(), annotation, true);
+ }
+
+ public List<Field> getAnnotatedFields(Class<?> fieldClass, Class<? extends Annotation> annotation) {
+ return getAnnotatedFields(fieldClass, annotation, true);
+ }
+
/**
- *
+ *
* @param instance
* @param resultClass
* @param annotation
* @param inherited
- * @return
+ * @return
*/
- private List<Field> getAnnotatedFields(Object instance, Class<?> resultClass,
- Class<? extends Annotation> annotation, boolean inherited) {
- if (instance == null) {
+ private List<Field> getAnnotatedFields(Class<?> resultClass,
+ Class<? extends Annotation> annotation, boolean inherited) {
+ if (resultClass == null) {
return null;
}
Field[] fields = resultClass.getDeclaredFields();
List<Field> annotatedFields = new ArrayList<Field>();
-
+
for (Field field : fields) {
if (field.getAnnotation(annotation) != null) {
annotatedFields.add(field);
@@ -224,7 +303,7 @@ public class AnnotationHelper {
Class<?> superClass = resultClass.getSuperclass();
if (inherited && superClass != Object.class) {
- List<Field> tmp = getAnnotatedFields(instance, superClass, annotation, true);
+ List<Field> tmp = getAnnotatedFields(superClass, annotation, true);
annotatedFields.addAll(tmp);
}
@@ -232,7 +311,7 @@ public class AnnotationHelper {
}
private Object getValueForField(Object instance, String fieldName, Class<?> resultClass,
- Class<? extends Annotation> annotation, boolean inherited) {
+ Class<? extends Annotation> annotation, boolean inherited) {
if (instance == null) {
return null;
}
@@ -240,7 +319,7 @@ public class AnnotationHelper {
Field[] fields = resultClass.getDeclaredFields();
for (Field field : fields) {
if (field.getAnnotation(annotation) != null
- && (fieldName == null || field.getName().equals(fieldName))) {
+ && (fieldName == null || field.getName().equals(fieldName))) {
return getFieldValue(instance, field);
}
}
@@ -269,6 +348,11 @@ public class AnnotationHelper {
private void setFieldValue(Object instance, Field field, Object propertyValue) {
try {
+ if (propertyValue != null
+ && field.getType() != propertyValue.getClass()
+ && propertyValue.getClass() == String.class) {
+ propertyValue = convert(field, (String) propertyValue);
+ }
boolean access = field.isAccessible();
field.setAccessible(true);
field.set(instance, propertyValue);
@@ -280,7 +364,18 @@ public class AnnotationHelper {
}
}
-
+ public Object convert(Field field, String propertyValue) {
+ Class fieldClass = field.getType();
+ try {
+ EdmProperty property = field.getAnnotation(EdmProperty.class);
+ EdmSimpleTypeKind type = property.type();
+ return type.getEdmSimpleTypeInstance().valueOfString(propertyValue,
+ EdmLiteralKind.DEFAULT, null, fieldClass);
+ } catch (EdmSimpleTypeException ex) {
+ throw new ODataRuntimeException(ex);
+ }
+ }
+
public boolean isEdmAnnotated(Object object) {
if (object == null) {
return false;
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/454e178e/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Building.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Building.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Building.java
index 59a8eb8..66adb24 100644
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Building.java
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Building.java
@@ -69,6 +69,10 @@ public class Building {
}
}
+ public void addRoom(Room room) {
+ rooms.add(room);
+ }
+
public List<Room> getRooms() {
return rooms;
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/454e178e/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Employee.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Employee.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Employee.java
index 76c4474..5092067 100644
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Employee.java
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Employee.java
@@ -37,7 +37,7 @@ public class Employee {
private static int counter = 1;
@EdmKey
@EdmProperty(name="EmployeeId", type = EdmSimpleTypeKind.String)
- private int employeeId;
+ private String employeeId;
@EdmProperty(name="EmployeeName")
private String employeeName;
@EdmProperty
@@ -46,6 +46,10 @@ public class Employee {
from = @NavigationEnd(role="r_Employees", multiplicity = EdmMultiplicity.MANY))//,
// to = @NavigationEnd(type = "Manager"))
private Manager manager;
+ @EdmNavigationProperty(name = "ne_Team", relationship="TeamEmployees",
+ from = @NavigationEnd(role = "r_Employees", type = "Employee", multiplicity = EdmMultiplicity.MANY),
+ to = @NavigationEnd(role = "r_Team", type = "Team")
+ )
private Team team;
private Room room;
private String imageType;
@@ -56,7 +60,7 @@ public class Employee {
private Location location;
public String getId() {
- return Integer.toString(employeeId);
+ return employeeId;
}
public void setEmployeeName(final String employeeName) {
@@ -152,7 +156,10 @@ public class Employee {
@Override
public int hashCode() {
- return employeeId;
+ if(employeeId == null) {
+ return 0;
+ }
+ return employeeId.hashCode();
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/454e178e/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/RefBase.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/RefBase.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/RefBase.java
index fef6317..5f40d1e 100644
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/RefBase.java
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/RefBase.java
@@ -32,14 +32,14 @@ public abstract class RefBase {
protected String name;
@EdmProperty(name="Id", type = EdmSimpleTypeKind.String)
@EdmKey
- protected int id;
+ protected String id;
public String getName() {
return name;
}
public String getId() {
- return Integer.toString(id);
+ return id;
}
public void setName(String name) {
@@ -47,6 +47,32 @@ public abstract class RefBase {
}
public void setId(int id) {
- this.id = id;
+ this.id = String.valueOf(id);
+ }
+
+ @Override
+ public int hashCode() {
+ if(id == null) {
+ return -1;
+ }
+ return id.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ final RefBase other = (RefBase) obj;
+ if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) {
+ return false;
+ }
+ if ((this.id == null) ? (other.id != null) : !this.id.equals(other.id)) {
+ return false;
+ }
+ return true;
}
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/454e178e/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Room.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Room.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Room.java
index c2e68fa..56e7e19 100644
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Room.java
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Room.java
@@ -75,7 +75,7 @@ public class Room extends RefBase {
@Override
public int hashCode() {
- return id;
+ return super.hashCode();
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/454e178e/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Team.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Team.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Team.java
index d851428..6936517 100644
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Team.java
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/model/Team.java
@@ -35,9 +35,10 @@ import org.apache.olingo.odata2.api.edm.EdmSimpleTypeKind;
public class Team extends RefBase {
@EdmProperty(type = EdmSimpleTypeKind.Boolean)
private Boolean isScrumTeam;
- @EdmNavigationProperty(name = "ne_Teams", relationship="TeamEmployees",
- from = @NavigationEnd(role = "r_Team", type = "Team"),
- to = @NavigationEnd(role = "r_Employees", type = "Employee", multiplicity = EdmMultiplicity.MANY))
+ @EdmNavigationProperty(name = "nt_Employees", relationship="TeamEmployees",
+// from = @NavigationEnd(role = "r_Team", type = "Team"),
+ to = @NavigationEnd(role = "r_Employees", type = "Employee", multiplicity = EdmMultiplicity.MANY)
+ )
private List<Employee> employees = new ArrayList<Employee>();
public Boolean isScrumTeam() {
@@ -58,7 +59,7 @@ public class Team extends RefBase {
@Override
public int hashCode() {
- return id;
+ return super.hashCode();
}
@Override
@@ -71,4 +72,4 @@ public class Team extends RefBase {
public String toString() {
return "{\"Id\":\"" + id + "\",\"Name\":\"" + name + "\",\"IsScrumTeam\":" + isScrumTeam + "}";
}
-}
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/454e178e/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/processor/AnnotationPocServiceFactory.java
----------------------------------------------------------------------
diff --git a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/processor/AnnotationPocServiceFactory.java b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/processor/AnnotationPocServiceFactory.java
index 2617df0..eb1c252 100644
--- a/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/processor/AnnotationPocServiceFactory.java
+++ b/odata2-edm-annotation/edm-annotation-webref/src/main/java/org/apache/olingo/odata2/ref/annotation/processor/AnnotationPocServiceFactory.java
@@ -112,10 +112,14 @@ public class AnnotationPocServiceFactory extends ODataServiceFactory {
teamDs.create(createTeam("Team Zeta", true));
DataStore<Building> buildingsDs = dataSource.getDataStore(Building.class);
- buildingsDs.create(createBuilding("Red Building"));
- buildingsDs.create(createBuilding("Green Building"));
- buildingsDs.create(createBuilding("Blue Building"));
- buildingsDs.create(createBuilding("Yellow Building"));
+ Building redBuilding = createBuilding("Red Building");
+ buildingsDs.create(redBuilding);
+ Building greenBuilding = createBuilding("Green Building");
+ buildingsDs.create(greenBuilding);
+ Building blueBuilding = createBuilding("Blue Building");
+ buildingsDs.create(blueBuilding);
+ Building yellowBuilding = createBuilding("Yellow Building");
+ buildingsDs.create(yellowBuilding);
DataStore<Photo> photoDs = dataSource.getDataStore(Photo.class);
photoDs.create(createPhoto("Small picture"));
@@ -123,10 +127,12 @@ public class AnnotationPocServiceFactory extends ODataServiceFactory {
photoDs.create(createPhoto("Big picture"));
DataStore<Room> roomDs = dataSource.getDataStore(Room.class);
- roomDs.create(createRoom("Tiny room", 5, 1));
- roomDs.create(createRoom("Small room", 20, 1));
- roomDs.create(createRoom("Big room", 40, 1));
- roomDs.create(createRoom("Huge room", 120, 1));
+ roomDs.create(createRoom("Tiny red room", 5, 1, redBuilding));
+ roomDs.create(createRoom("Small red room", 20, 1, redBuilding));
+ roomDs.create(createRoom("Small green room", 20, 1, greenBuilding));
+ roomDs.create(createRoom("Big blue room", 40, 1, blueBuilding));
+ roomDs.create(createRoom("Huge blue room", 120, 1, blueBuilding));
+ roomDs.create(createRoom("Huge yellow room", 120, 1, yellowBuilding));
}
private Team createTeam(String teamName, boolean isScrumTeam) {
@@ -151,11 +157,15 @@ public class AnnotationPocServiceFactory extends ODataServiceFactory {
return p;
}
- private Room createRoom(String name, int seats, int version) {
+ private Room createRoom(String name, int seats, int version, Building building) {
Room r = new Room();
r.setName(name);
r.setSeats(seats);
r.setVersion(version);
+ r.setBuilding(building);
+
+ building.addRoom(r);
+
return r;
}
}