diff --git a/ext/client-proxy/pom.xml b/ext/client-proxy/pom.xml new file mode 100644 index 000000000..39e742b7d --- /dev/null +++ b/ext/client-proxy/pom.xml @@ -0,0 +1,76 @@ + + + + + 4.0.0 + + client-proxy + jar + ${project.artifactId} + Java client API for OData services: Proxy. + + + org.apache.olingo + olingo-ext + 0.1.0-SNAPSHOT + .. + + + + + + + + org.apache.olingo + olingo-client-core + ${project.version} + + + + org.apache.commons + commons-lang3 + + + commons-beanutils + commons-beanutils-core + + + commons-logging + commons-logging + runtime + + + org.slf4j + slf4j-api + + + commons-io + commons-io + + + + junit + junit + test + + + diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/AbstractContainer.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/AbstractContainer.java new file mode 100644 index 000000000..e062f021c --- /dev/null +++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/AbstractContainer.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.ext.proxy.api; + +import java.io.Serializable; + +/** + * Interface for container operations. + */ +public abstract interface AbstractContainer extends Serializable { + + /** + * Flushes all pending changes to the OData service. + */ + void flush(); +} diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/AbstractEntityCollection.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/AbstractEntityCollection.java new file mode 100644 index 000000000..3dc3719c1 --- /dev/null +++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/AbstractEntityCollection.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.ext.proxy.api; + +import java.io.Serializable; +import java.util.Collection; + +public abstract interface AbstractEntityCollection extends Collection, Serializable { +} diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/AbstractEntityKey.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/AbstractEntityKey.java new file mode 100644 index 000000000..8740d07be --- /dev/null +++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/AbstractEntityKey.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT 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.ext.proxy.api; + +import java.io.Serializable; +import org.apache.commons.lang3.builder.EqualsBuilder; +import org.apache.commons.lang3.builder.HashCodeBuilder; +import org.apache.commons.lang3.builder.ReflectionToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +public abstract class AbstractEntityKey implements Serializable { + + private static final long serialVersionUID = 1662634743346775238L; + + /** + * {@inheritDoc } + */ + @Override + public boolean equals(final Object obj) { + return EqualsBuilder.reflectionEquals(this, obj); + } + + /** + * {@inheritDoc } + */ + @Override + public int hashCode() { + return HashCodeBuilder.reflectionHashCode(this); + } + + /** + * {@inheritDoc } + */ + @Override + public String toString() { + return ReflectionToStringBuilder.toString(this, ToStringStyle.MULTI_LINE_STYLE); + } +} diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/AbstractEntitySet.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/AbstractEntitySet.java new file mode 100644 index 000000000..b4df7c9bf --- /dev/null +++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/AbstractEntitySet.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.ext.proxy.api; + +import java.io.Serializable; + +/** + * Interface for synchronous CRUD operations on an EntitySet. + */ +public abstract interface AbstractEntitySet< + T extends Serializable, KEY extends Serializable, EC extends AbstractEntityCollection> + extends Iterable, Serializable { + + /** + * Returns whether an entity with the given id exists. + * + * @param key must not be null + * @return true if an entity with the given id exists, false otherwise + * @throws IllegalArgumentException in case the given key is null + */ + Boolean exists(KEY key) throws IllegalArgumentException; + + /** + * Retrieves an entity by its key. + * + * @param key must not be null + * @return the entity with the given id or null if none found + * @throws IllegalArgumentException in case the given key is null + */ + T get(KEY key) throws IllegalArgumentException; + + /** + * Retrieves an entity by its key, considering polymorphism. + * + * @param key must not be null + * @param reference entity class to be returned + * @return the entity with the given id or null if none found + * @throws IllegalArgumentException in case the given key is null + */ + S get(KEY key, Class reference) throws IllegalArgumentException; + + /** + * Returns the number of entities available. + * + * @return the number of entities + */ + Long count(); + + /** + * Returns all instances. + * + * @return all entities + */ + EC getAll(); + + /** + * Returns all instances of the given subtype. + * + * @param reference entity collection class to be returned + * @return all entities of the given subtype + */ + > SEC getAll(Class reference); + + /** + * Deletes the entity with the given key. + * + * @param key must not be null + * @throws IllegalArgumentException in case the given key is null + */ + void delete(KEY key) throws IllegalArgumentException; + + /** + * Deletes the given entities in a batch. + * + * @param entities to be deleted + */ + void delete(Iterable entities); + + /** + * Create an instance of Query. + * + * @return the new query instance + */ + Query createQuery(); + + /** + * Create an instance of Query. + * + * @return the new query instance + */ + > Query createQuery(Class reference); +} diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/AbstractOpenType.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/AbstractOpenType.java new file mode 100644 index 000000000..4b200b457 --- /dev/null +++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/AbstractOpenType.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.ext.proxy.api; + +import java.io.Serializable; +import java.util.Collection; + +public abstract interface AbstractOpenType extends Serializable { + + void addAdditionalProperty(String name, Object value); + + Object getAdditionalProperty(String name); + + Collection getAdditionalPropertyNames(); +} diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/NoResultException.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/NoResultException.java new file mode 100644 index 000000000..da76bf06a --- /dev/null +++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/NoResultException.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT 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.ext.proxy.api; + +/** + * Thrown when Query.getSingleResult() or EntityQuery.getSingleResult() is executed on a query and + * there is no result to return. + * + * @see Query#getSingleResult() + * @see EntityQuery#getSingleResult() + */ +public class NoResultException extends RuntimeException { + + private static final long serialVersionUID = -6643642637364303053L; + + public NoResultException() { + super(); + } +} diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/NonUniqueResultException.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/NonUniqueResultException.java new file mode 100644 index 000000000..bb5737fe6 --- /dev/null +++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/NonUniqueResultException.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT 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.ext.proxy.api; + +/** + * Thrown when Query.getSingleResult() or EntityQuery.getSingleResult() is executed on a query and + * there is more than one result from the query. + * + * @see Query#getSingleResult() + * @see EntityQuery#getSingleResult() + */ +public class NonUniqueResultException extends RuntimeException { + + private static final long serialVersionUID = 4444551737338550185L; + + public NonUniqueResultException() { + super(); + } +} diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/OperationType.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/OperationType.java new file mode 100644 index 000000000..47c69a579 --- /dev/null +++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/OperationType.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT 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.ext.proxy.api; + +public enum OperationType { + + /** + * Function or action (not specified explicitly). + *
+ * OData V3 only. + */ + LEGACY, + /** + * Functions MUST NOT have observable side effects and MUST return a single instance or a collection of instances of + * any type. Functions MAY be composable. + */ + FUNCTION, + /** + * Actions MAY have observable side effects and MAY return a single instance or a collection of instances of any type. + * Actions cannot be composed with additional path segments. + */ + ACTION; + +} diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/Query.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/Query.java new file mode 100644 index 000000000..ec7b944ee --- /dev/null +++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/Query.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.ext.proxy.api; + +import java.io.Serializable; +import org.apache.olingo.client.api.uri.URIFilter; + +/** + * Interface used to control query execution. + * + * @param query result type + */ +public interface Query> extends Serializable { + + /** + * Sets the $filter expression for this query. Any of available operators and functions can be embodied here. + * + * @param filter the $filter expression for this query + * @return the same query instance + */ + Query setFilter(String filter); + + /** + * Sets the filter generating the $filter expression for this query. + * + * @param filter filter instance (to be obtained via ODataFilterFactory): note that build() method + * will be immediately invoked. + * @return the same query instance + */ + Query setFilter(URIFilter filter); + + /** + * The $filter expression for this query. + * + * @return the $filter expression for this query + */ + String getFilter(); + + /** + * Sets the $orderBy expression for this query via sort options. + * + * @param sort sort options + * @return the same query instance + */ + Query setOrderBy(Sort... sort); + + /** + * Sets the $orderBy expression for this query. + * + * @param select the $orderBy expression for this query + * @return the same query instance + */ + Query setOrderBy(String orderBy); + + /** + * The $orderBy expression for this query. + * + * @return the $orderBy expression for this query + */ + String getOrderBy(); + + /** + * Sets the maximum number of results to retrieve ($top). + * + * @param maxResults maximum number of results to retrieve + * @return the same query instance + * @throws IllegalArgumentException if the argument is negative + */ + Query setMaxResults(int maxResults) throws IllegalArgumentException; + + /** + * The maximum number of results the query object was set to retrieve ($top). Returns + * Integer.MAX_VALUE if setMaxResults was not applied to the query object. + * + * @return maximum number of results + */ + int getMaxResults(); + + /** + * Sets the position of the first result to retrieve ($skip). + * + * @param firstResult position of the first result, numbered from 0 + * @return the same query instance + * @throws IllegalArgumentException if the argument is negative + */ + Query setFirstResult(int firstResult) throws IllegalArgumentException; + + /** + * The position of the first result the query object was set to retrieve ($skip). + * + * Returns 0 if setFirstResult was not applied to the query object. + * + * @return position of the first result + */ + int getFirstResult(); + + /** + * Executes a $filter query that returns a single result. + * + * @return the result + * @throws NoResultException if there is no result + * @throws NonUniqueResultException if more than one result + */ + T getSingleResult() throws NoResultException, NonUniqueResultException; + + /** + * Executes a $filter query and return the query results as collection. + * + * @return an iterable view of the results + */ + EC getResult(); +} diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/Sort.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/Sort.java new file mode 100644 index 000000000..9e6f9242b --- /dev/null +++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/Sort.java @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT 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.ext.proxy.api; + +import java.util.Map; + +/** + * Sort option for queries. + */ +public class Sort implements Map.Entry { + + /** + * Enumeration for sort directions. + */ + public enum Direction { + + ASC, + DESC; + + @Override + public String toString() { + return name().toLowerCase(); + } + } + private final String key; + + private Direction value; + + public Sort(final String key, final Direction value) { + this.key = key; + this.value = value; + } + + @Override + public String getKey() { + return this.key; + } + + @Override + public Direction getValue() { + return this.value; + } + + @Override + public Direction setValue(final Direction value) { + this.value = value; + return this.value; + } +} diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/annotations/ComplexType.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/annotations/ComplexType.java new file mode 100644 index 000000000..ec41f523b --- /dev/null +++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/annotations/ComplexType.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT 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.ext.proxy.api.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Mark POJO as EDM complex type. + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +@Inherited +public @interface ComplexType { + + String name(); + + String baseType() default ""; + + boolean isAbstract() default false; + + boolean isOpenType() default false; +} diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/annotations/CompoundKey.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/annotations/CompoundKey.java new file mode 100644 index 000000000..217cc966c --- /dev/null +++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/annotations/CompoundKey.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.ext.proxy.api.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Identifies a compound key. + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface CompoundKey { +} diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/annotations/CompoundKeyElement.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/annotations/CompoundKeyElement.java new file mode 100644 index 000000000..5f45d0632 --- /dev/null +++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/annotations/CompoundKeyElement.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT 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.ext.proxy.api.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Mark multi key class field (property) as multi key element. + * + * @see Property + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) +public @interface CompoundKeyElement { + + String name(); + + int position(); +} diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/annotations/EntityContainer.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/annotations/EntityContainer.java new file mode 100644 index 000000000..e76cfc889 --- /dev/null +++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/annotations/EntityContainer.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.ext.proxy.api.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Mark POJO as EDM entity container. + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface EntityContainer { + + String name(); + + boolean isDefaultEntityContainer() default false; +} diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/annotations/EntitySet.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/annotations/EntitySet.java new file mode 100644 index 000000000..0a94df45d --- /dev/null +++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/annotations/EntitySet.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT 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.ext.proxy.api.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Give entity set a name. If interface extending EntitySet is not annotated with this, the effective name will be + * class' + * getSimpleName(). + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface EntitySet { + + String name(); + + boolean includeInServiceDocument() default true; +} diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/annotations/EntityType.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/annotations/EntityType.java new file mode 100644 index 000000000..a87509844 --- /dev/null +++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/annotations/EntityType.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.ext.proxy.api.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Mark POJO as EDM entity type. + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +@Inherited +public @interface EntityType { + + String name(); + + String baseType() default ""; + + boolean isAbstract() default false; + + boolean openType() default false; + + boolean hasStream() default false; +} diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/annotations/EnumType.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/annotations/EnumType.java new file mode 100644 index 000000000..51afe7940 --- /dev/null +++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/annotations/EnumType.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.olingo.ext.proxy.api.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind; + +/** + * Mark Java enum as EDM enum type. + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface EnumType { + + String name(); + + EdmPrimitiveTypeKind underlyingType() default EdmPrimitiveTypeKind.Int32; + + boolean isFlags() default false; +} diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/annotations/Key.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/annotations/Key.java new file mode 100644 index 000000000..7e10e876b --- /dev/null +++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/annotations/Key.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.ext.proxy.api.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Mark POJO field (property) as key. + * + * @see Property + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) +public @interface Key { +} diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/annotations/KeyClass.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/annotations/KeyClass.java new file mode 100644 index 000000000..5729ca515 --- /dev/null +++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/annotations/KeyClass.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.olingo.ext.proxy.api.annotations; + +import java.io.Serializable; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Specifies a composite primary key class that is mapped to multiple fields or properties of an EntityType. + *

The names of the fields or properties in the primary key class and the primary key fields or properties of the + * EntityType must correspond and their types must be the same.

+ * + * @see Key + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface KeyClass { + + Class value(); +} diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/annotations/KeyRef.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/annotations/KeyRef.java new file mode 100644 index 000000000..41f3b06d2 --- /dev/null +++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/annotations/KeyRef.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.ext.proxy.api.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Identifies a compound key. + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface KeyRef { + + Class value(); +} diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/annotations/Namespace.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/annotations/Namespace.java new file mode 100644 index 000000000..81f1a9520 --- /dev/null +++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/annotations/Namespace.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.ext.proxy.api.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Associate Java package with OData namespace. + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface Namespace { + + String value(); + + String alias() default ""; +} diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/annotations/NavigationProperty.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/annotations/NavigationProperty.java new file mode 100644 index 000000000..88379bc63 --- /dev/null +++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/annotations/NavigationProperty.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT 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.ext.proxy.api.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Bind POJO field to EDM navigation property. + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) +public @interface NavigationProperty { + + String name(); + + String type(); + + String targetSchema(); + + String targetContainer(); + + String targetEntitySet(); +} diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/annotations/Operation.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/annotations/Operation.java new file mode 100644 index 000000000..ad5a148c2 --- /dev/null +++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/annotations/Operation.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.ext.proxy.api.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import org.apache.olingo.ext.proxy.api.OperationType; + +/** + * Mark method as EDM function import. + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) +public @interface Operation { + + String name(); + + /** + * Operation type, function or action. + * + * @return operation type. + */ + OperationType type(); + + /** + * The action/function MAY/MUST specify a return type using the edm:ReturnType element. The return type must be a + * scalar, entity or complex type, or a collection of scalar, entity or complex types. + * + * @return operation return type. + */ + String returnType() default ""; + + /** + * A function element MAY specify a Boolean value for the IsComposable attribute. If no value is specified for the + * IsComposable attribute, the value defaults to false. + *
+ * Functions whose IsComposable attribute is true are considered composable. A composable function can be invoked with + * additional path segments or system query options appended to the path that identifies the composable function as + * appropriate for the type returned by the composable function. + * + * @return TRUE if is composable; FALSE otherwise. + */ + boolean isComposable() default false; +} diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/annotations/Parameter.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/annotations/Parameter.java new file mode 100644 index 000000000..2ecd79b64 --- /dev/null +++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/annotations/Parameter.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT 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.ext.proxy.api.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import org.apache.olingo.client.api.edm.xml.v3.FunctionImport; +import org.apache.olingo.client.api.edm.xml.v3.ParameterMode; + +/** + * Function import parameter information. + * + * @see FunctionImport + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.PARAMETER) +public @interface Parameter { + + String name(); + + String type(); + + boolean nullable() default true; + + ParameterMode mode() default ParameterMode.In; + + int maxLenght() default Integer.MAX_VALUE; + + int precision() default 0; + + int scale() default 0; +} diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/annotations/Property.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/annotations/Property.java new file mode 100644 index 000000000..86da39373 --- /dev/null +++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/annotations/Property.java @@ -0,0 +1,76 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT 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.ext.proxy.api.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import org.apache.olingo.client.api.edm.ConcurrencyMode; +import org.apache.olingo.client.api.edm.StoreGeneratedPattern; +import org.apache.olingo.commons.api.edm.constants.EdmContentKind; + +/** + * Bind POJO field to EDM property. + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) +public @interface Property { + + String name(); + + String type(); + + boolean nullable() default true; + + String defaultValue() default ""; + + int maxLenght() default Integer.MAX_VALUE; + + boolean fixedLenght() default false; + + int precision() default 0; + + int scale() default 0; + + boolean unicode() default true; + + String collation() default ""; + + String srid() default ""; + + ConcurrencyMode concurrencyMode() default ConcurrencyMode.None; + + String mimeType() default ""; + + /* -- Feed Customization annotations -- */ + String fcSourcePath() default ""; + + String fcTargetPath() default ""; + + EdmContentKind fcContentKind() default EdmContentKind.text; + + String fcNSPrefix() default ""; + + String fcNSURI() default ""; + + boolean fcKeepInContent() default false; + + StoreGeneratedPattern storeGeneratedPattern() default StoreGeneratedPattern.None; +} diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/annotations/ReferentialConstraint.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/annotations/ReferentialConstraint.java new file mode 100644 index 000000000..92ab4db5a --- /dev/null +++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/annotations/ReferentialConstraint.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT 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.ext.proxy.api.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Annotate navigation property with information about referential constraint. + * + * @see NavigationProperty + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +public @interface ReferentialConstraint { + + Class principalRole(); + + String[] principalPropertyRefs(); + + Class dependentRole(); + + String[] dependentPropertyRefs(); +} diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/annotations/RowType.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/annotations/RowType.java new file mode 100644 index 000000000..50334d19b --- /dev/null +++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/annotations/RowType.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.ext.proxy.api.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Mark inner class as EDM row type. + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface RowType { +} diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/annotations/Singleton.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/annotations/Singleton.java new file mode 100644 index 000000000..3f85c88ab --- /dev/null +++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/annotations/Singleton.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT 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.ext.proxy.api.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Give singleton a name. If interface extending Singleton is not annotated with this, the effective name will be class' + * getSimpleName(). + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface Singleton { + + String name(); +} diff --git a/ext/pojogen-maven-plugin/pom.xml b/ext/pojogen-maven-plugin/pom.xml new file mode 100644 index 000000000..2364dacc8 --- /dev/null +++ b/ext/pojogen-maven-plugin/pom.xml @@ -0,0 +1,129 @@ + + + + + 4.0.0 + + pojogen-maven-plugin + maven-plugin + ${project.artifactId} + Java client API for OData services: Maven plugin generating POJOs from metadata. + + + org.apache.olingo + olingo-ext + 0.1.0-SNAPSHOT + .. + + + + ${test.base.url} + ${project.parent.basedir} + + + + + org.apache.olingo + olingo-client-core + ${project.version} + + + + org.apache.velocity + velocity + + + org.apache.maven + maven-plugin-api + + + org.apache.maven.plugin-tools + maven-plugin-annotations + provided + + + + commons-logging + commons-logging + runtime + + + commons-io + commons-io + + + + junit + junit + test + + + + + + + org.apache.maven.plugins + maven-plugin-plugin + true + + odatajclient + true + + + + mojo-descriptor + + descriptor + + + + help-goal + + helpmojo + + + + + + + + + src/main/resources + true + + + .. + META-INF + + LICENSE + + + + + + + src/test/resources + true + + + + diff --git a/ext/pojogen-maven-plugin/src/it/actionOverloadingService/pom.xml b/ext/pojogen-maven-plugin/src/it/actionOverloadingService/pom.xml new file mode 100644 index 000000000..ba36e8124 --- /dev/null +++ b/ext/pojogen-maven-plugin/src/it/actionOverloadingService/pom.xml @@ -0,0 +1,92 @@ + + + + 4.0.0 + + org.apache.olingo.ext + odatajclient-maven-plugin + @project.version@ + + A simple IT verifying the basic use case. + + + UTF-8 + + + + + org.apache.velocity + velocity + @velocity.version@ + + + + org.apache.olingo.ext + odatajclient-proxy + @project.version@ + + + + + + + org.codehaus.mojo + build-helper-maven-plugin + 1.8 + + + process-sources + + add-source + + + + ${project.build.directory}/generated-sources + + + + + + + + @project.groupId@ + @project.artifactId@ + @project.version@ + + + + ${project.build.directory}/generated-sources + @serviceRootURL@/ActionOverloadingService.svc + org.apache.olingo.ext.proxy.actionoverloadingservice + + pojosV3 + generate-sources + + pojosV3 + + + + + + + diff --git a/ext/pojogen-maven-plugin/src/it/actionOverloadingService/verify.groovy b/ext/pojogen-maven-plugin/src/it/actionOverloadingService/verify.groovy new file mode 100644 index 000000000..a19cf4d31 --- /dev/null +++ b/ext/pojogen-maven-plugin/src/it/actionOverloadingService/verify.groovy @@ -0,0 +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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +File basepkg = new File( basedir, "target/generated-sources/ojc-plugin/com/msopentech/odatajclient/proxy" ); +assert basepkg.isDirectory() && basepkg.listFiles().length>0; diff --git a/ext/pojogen-maven-plugin/src/it/defaultService/pom.xml b/ext/pojogen-maven-plugin/src/it/defaultService/pom.xml new file mode 100644 index 000000000..c82709f90 --- /dev/null +++ b/ext/pojogen-maven-plugin/src/it/defaultService/pom.xml @@ -0,0 +1,92 @@ + + + + 4.0.0 + + org.apache.olingo.ext + odatajclient-maven-plugin + @project.version@ + + A simple IT verifying the basic use case. + + + UTF-8 + + + + + org.apache.velocity + velocity + @velocity.version@ + + + + org.apache.olingo.ext + odatajclient-proxy + @project.version@ + + + + + + + org.codehaus.mojo + build-helper-maven-plugin + 1.8 + + + process-sources + + add-source + + + + ${project.build.directory}/generated-sources + + + + + + + + @project.groupId@ + @project.artifactId@ + @project.version@ + + + + ${project.build.directory}/generated-sources + @serviceRootURL@/DefaultService.svc + org.apache.olingo.ext.proxy.defaultservice + + pojosV3 + generate-sources + + pojosV3 + + + + + + + diff --git a/ext/pojogen-maven-plugin/src/it/defaultService/verify.groovy b/ext/pojogen-maven-plugin/src/it/defaultService/verify.groovy new file mode 100644 index 000000000..a19cf4d31 --- /dev/null +++ b/ext/pojogen-maven-plugin/src/it/defaultService/verify.groovy @@ -0,0 +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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +File basepkg = new File( basedir, "target/generated-sources/ojc-plugin/com/msopentech/odatajclient/proxy" ); +assert basepkg.isDirectory() && basepkg.listFiles().length>0; diff --git a/ext/pojogen-maven-plugin/src/it/keyAsSegmentService/pom.xml b/ext/pojogen-maven-plugin/src/it/keyAsSegmentService/pom.xml new file mode 100644 index 000000000..174ee9185 --- /dev/null +++ b/ext/pojogen-maven-plugin/src/it/keyAsSegmentService/pom.xml @@ -0,0 +1,92 @@ + + + + 4.0.0 + + org.apache.olingo.ext + odatajclient-maven-plugin + @project.version@ + + A simple IT verifying the basic use case. + + + UTF-8 + + + + + org.apache.velocity + velocity + @velocity.version@ + + + + org.apache.olingo.ext + odatajclient-proxy + @project.version@ + + + + + + + org.codehaus.mojo + build-helper-maven-plugin + 1.8 + + + process-sources + + add-source + + + + ${project.build.directory}/generated-sources + + + + + + + + @project.groupId@ + @project.artifactId@ + @project.version@ + + + + ${project.build.directory}/generated-sources + @serviceRootURL@/KeyAsSegmentService.svc + org.apache.olingo.ext.proxy.keyassegmentservice + + pojosV3 + generate-sources + + pojosV3 + + + + + + + diff --git a/ext/pojogen-maven-plugin/src/it/keyAsSegmentService/verify.groovy b/ext/pojogen-maven-plugin/src/it/keyAsSegmentService/verify.groovy new file mode 100644 index 000000000..a19cf4d31 --- /dev/null +++ b/ext/pojogen-maven-plugin/src/it/keyAsSegmentService/verify.groovy @@ -0,0 +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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +File basepkg = new File( basedir, "target/generated-sources/ojc-plugin/com/msopentech/odatajclient/proxy" ); +assert basepkg.isDirectory() && basepkg.listFiles().length>0; diff --git a/ext/pojogen-maven-plugin/src/it/northwind/pom.xml b/ext/pojogen-maven-plugin/src/it/northwind/pom.xml new file mode 100644 index 000000000..862493adb --- /dev/null +++ b/ext/pojogen-maven-plugin/src/it/northwind/pom.xml @@ -0,0 +1,92 @@ + + + + 4.0.0 + + org.apache.olingo.ext + odatajclient-maven-plugin + @project.version@ + + A simple IT verifying the basic use case. + + + UTF-8 + + + + + org.apache.velocity + velocity + @velocity.version@ + + + + org.apache.olingo.ext + odatajclient-proxy + @project.version@ + + + + + + + org.codehaus.mojo + build-helper-maven-plugin + 1.8 + + + process-sources + + add-source + + + + ${project.build.directory}/generated-sources + + + + + + + + @project.groupId@ + @project.artifactId@ + @project.version@ + + + + ${project.build.directory}/generated-sources + http://services.odata.org/v3/(S(g00nkir0ssikgdmz3maw5l1x))/Northwind/Northwind.svc + org.apache.olingo.ext.proxy.northwind + + pojosV3 + generate-sources + + pojosV3 + + + + + + + diff --git a/ext/pojogen-maven-plugin/src/it/northwind/verify.groovy b/ext/pojogen-maven-plugin/src/it/northwind/verify.groovy new file mode 100644 index 000000000..a19cf4d31 --- /dev/null +++ b/ext/pojogen-maven-plugin/src/it/northwind/verify.groovy @@ -0,0 +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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +File basepkg = new File( basedir, "target/generated-sources/ojc-plugin/com/msopentech/odatajclient/proxy" ); +assert basepkg.isDirectory() && basepkg.listFiles().length>0; diff --git a/ext/pojogen-maven-plugin/src/it/odataWriterDefaultService/pom.xml b/ext/pojogen-maven-plugin/src/it/odataWriterDefaultService/pom.xml new file mode 100644 index 000000000..0f133b448 --- /dev/null +++ b/ext/pojogen-maven-plugin/src/it/odataWriterDefaultService/pom.xml @@ -0,0 +1,92 @@ + + + + 4.0.0 + + org.apache.olingo.ext + odatajclient-maven-plugin + @project.version@ + + A simple IT verifying the basic use case. + + + UTF-8 + + + + + org.apache.velocity + velocity + @velocity.version@ + + + + org.apache.olingo.ext + odatajclient-proxy + @project.version@ + + + + + + + org.codehaus.mojo + build-helper-maven-plugin + 1.8 + + + process-sources + + add-source + + + + ${project.build.directory}/generated-sources + + + + + + + + @project.groupId@ + @project.artifactId@ + @project.version@ + + + + ${project.build.directory}/generated-sources + @serviceRootURL@/ODataWriterDefaultService.svc + org.apache.olingo.ext.proxy.odatawriterdefaultservice + + pojosV3 + generate-sources + + pojosV3 + + + + + + + diff --git a/ext/pojogen-maven-plugin/src/it/odataWriterDefaultService/verify.groovy b/ext/pojogen-maven-plugin/src/it/odataWriterDefaultService/verify.groovy new file mode 100644 index 000000000..a19cf4d31 --- /dev/null +++ b/ext/pojogen-maven-plugin/src/it/odataWriterDefaultService/verify.groovy @@ -0,0 +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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +File basepkg = new File( basedir, "target/generated-sources/ojc-plugin/com/msopentech/odatajclient/proxy" ); +assert basepkg.isDirectory() && basepkg.listFiles().length>0; diff --git a/ext/pojogen-maven-plugin/src/it/openTypeService/pom.xml b/ext/pojogen-maven-plugin/src/it/openTypeService/pom.xml new file mode 100644 index 000000000..408c57ac5 --- /dev/null +++ b/ext/pojogen-maven-plugin/src/it/openTypeService/pom.xml @@ -0,0 +1,92 @@ + + + + 4.0.0 + + org.apache.olingo.ext + odatajclient-maven-plugin + @project.version@ + + A simple IT verifying the basic use case. + + + UTF-8 + + + + + org.apache.velocity + velocity + @velocity.version@ + + + + org.apache.olingo.ext + odatajclient-proxy + @project.version@ + + + + + + + org.codehaus.mojo + build-helper-maven-plugin + 1.8 + + + process-sources + + add-source + + + + ${project.build.directory}/generated-sources + + + + + + + + @project.groupId@ + @project.artifactId@ + @project.version@ + + + + ${project.build.directory}/generated-sources + @serviceRootURL@/OpenTypeService.svc + org.apache.olingo.ext.proxy.opentypeservice + + pojosV3 + generate-sources + + pojosV3 + + + + + + + diff --git a/ext/pojogen-maven-plugin/src/it/openTypeService/verify.groovy b/ext/pojogen-maven-plugin/src/it/openTypeService/verify.groovy new file mode 100644 index 000000000..a19cf4d31 --- /dev/null +++ b/ext/pojogen-maven-plugin/src/it/openTypeService/verify.groovy @@ -0,0 +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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +File basepkg = new File( basedir, "target/generated-sources/ojc-plugin/com/msopentech/odatajclient/proxy" ); +assert basepkg.isDirectory() && basepkg.listFiles().length>0; diff --git a/ext/pojogen-maven-plugin/src/it/primitiveKeysService/pom.xml b/ext/pojogen-maven-plugin/src/it/primitiveKeysService/pom.xml new file mode 100644 index 000000000..159670881 --- /dev/null +++ b/ext/pojogen-maven-plugin/src/it/primitiveKeysService/pom.xml @@ -0,0 +1,92 @@ + + + + 4.0.0 + + org.apache.olingo.ext + odatajclient-maven-plugin + @project.version@ + + A simple IT verifying the basic use case. + + + UTF-8 + + + + + org.apache.velocity + velocity + @velocity.version@ + + + + org.apache.olingo.ext + odatajclient-proxy + @project.version@ + + + + + + + org.codehaus.mojo + build-helper-maven-plugin + 1.8 + + + process-sources + + add-source + + + + ${project.build.directory}/generated-sources + + + + + + + + @project.groupId@ + @project.artifactId@ + @project.version@ + + + + ${project.build.directory}/generated-sources + @serviceRootURL@/PrimitiveKeys.svc + org.apache.olingo.ext.proxy.primitivekeysservice + + pojosV3 + generate-sources + + pojosV3 + + + + + + + diff --git a/ext/pojogen-maven-plugin/src/it/primitiveKeysService/verify.groovy b/ext/pojogen-maven-plugin/src/it/primitiveKeysService/verify.groovy new file mode 100644 index 000000000..a19cf4d31 --- /dev/null +++ b/ext/pojogen-maven-plugin/src/it/primitiveKeysService/verify.groovy @@ -0,0 +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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +File basepkg = new File( basedir, "target/generated-sources/ojc-plugin/com/msopentech/odatajclient/proxy" ); +assert basepkg.isDirectory() && basepkg.listFiles().length>0; diff --git a/ext/pojogen-maven-plugin/src/it/staticServiceV3/pom.xml b/ext/pojogen-maven-plugin/src/it/staticServiceV3/pom.xml new file mode 100644 index 000000000..43cb499ae --- /dev/null +++ b/ext/pojogen-maven-plugin/src/it/staticServiceV3/pom.xml @@ -0,0 +1,92 @@ + + + + 4.0.0 + + org.apache.olingo.ext + odatajclient-maven-plugin + @project.version@ + + A simple IT verifying the basic use case. + + + UTF-8 + + + + + org.apache.velocity + velocity + @velocity.version@ + + + + org.apache.olingo.ext + odatajclient-proxy + @project.version@ + + + + + + + org.codehaus.mojo + build-helper-maven-plugin + 1.8 + + + process-sources + + add-source + + + + ${project.build.directory}/generated-sources + + + + + + + + @project.groupId@ + @project.artifactId@ + @project.version@ + + + + ${project.build.directory}/generated-sources + http://localhost:9080/StaticService/V3/Static.svc + org.apache.olingo.ext.proxy.staticservice + + pojosV3 + generate-sources + + pojosV3 + + + + + + + diff --git a/ext/pojogen-maven-plugin/src/it/staticServiceV3/verify.groovy b/ext/pojogen-maven-plugin/src/it/staticServiceV3/verify.groovy new file mode 100644 index 000000000..a19cf4d31 --- /dev/null +++ b/ext/pojogen-maven-plugin/src/it/staticServiceV3/verify.groovy @@ -0,0 +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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +File basepkg = new File( basedir, "target/generated-sources/ojc-plugin/com/msopentech/odatajclient/proxy" ); +assert basepkg.isDirectory() && basepkg.listFiles().length>0; diff --git a/ext/pojogen-maven-plugin/src/it/staticServiceV4/pom.xml b/ext/pojogen-maven-plugin/src/it/staticServiceV4/pom.xml new file mode 100644 index 000000000..7c1e2084e --- /dev/null +++ b/ext/pojogen-maven-plugin/src/it/staticServiceV4/pom.xml @@ -0,0 +1,92 @@ + + + + 4.0.0 + + org.apache.olingo.ext + odatajclient-maven-plugin + @project.version@ + + A simple IT verifying the basic use case. + + + UTF-8 + + + + + org.apache.velocity + velocity + @velocity.version@ + + + + org.apache.olingo.ext + odatajclient-proxy + @project.version@ + + + + + + + org.codehaus.mojo + build-helper-maven-plugin + 1.8 + + + process-sources + + add-source + + + + ${project.build.directory}/generated-sources + + + + + + + + @project.groupId@ + @project.artifactId@ + @project.version@ + + + + ${project.build.directory}/generated-sources + http://localhost:9080/StaticService/V4/Static.svc + org.apache.olingo.ext.proxy.staticservice + + pojosV3 + generate-sources + + pojosV4 + + + + + + + diff --git a/ext/pojogen-maven-plugin/src/it/staticServiceV4/verify.groovy b/ext/pojogen-maven-plugin/src/it/staticServiceV4/verify.groovy new file mode 100644 index 000000000..a19cf4d31 --- /dev/null +++ b/ext/pojogen-maven-plugin/src/it/staticServiceV4/verify.groovy @@ -0,0 +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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +File basepkg = new File( basedir, "target/generated-sources/ojc-plugin/com/msopentech/odatajclient/proxy" ); +assert basepkg.isDirectory() && basepkg.listFiles().length>0; diff --git a/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/AbstractMetadataMojo.java b/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/AbstractMetadataMojo.java new file mode 100644 index 000000000..23477619e --- /dev/null +++ b/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/AbstractMetadataMojo.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.ext.pojogen; + +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugins.annotations.Parameter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Collections; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import org.apache.commons.io.IOUtils; +import org.apache.commons.lang.StringUtils; +import org.apache.velocity.Template; +import org.apache.velocity.VelocityContext; +import org.apache.velocity.app.Velocity; + +public abstract class AbstractMetadataMojo extends AbstractMojo { + + /** + * Generated files base root. + */ + @Parameter(property = "outputDirectory", required = true) + protected String outputDirectory; + + /** + * OData service root URL. + */ + @Parameter(property = "serviceRootURL", required = true) + protected String serviceRootURL; + + /** + * Base package. + */ + @Parameter(property = "basePackage", required = true) + protected String basePackage; + + protected final Set namespaces = new HashSet(); + + protected static String TOOL_DIR = "ojc-plugin"; + + protected AbstractUtility utility; + + protected abstract AbstractUtility getUtility(); + + protected abstract String getVersion(); + + protected File mkdir(final String path) { + final File dir = new File(outputDirectory + File.separator + TOOL_DIR + File.separator + path); + + if (dir.exists()) { + if (!dir.isDirectory()) { + throw new IllegalArgumentException("Invalid path '" + path + "': it is not a directory"); + } + } else { + dir.mkdirs(); + } + + return dir; + } + + protected File mkPkgDir(final String path) { + return mkdir(basePackage.replace('.', File.separatorChar) + File.separator + path); + } + + protected void writeFile(final String name, final File path, final VelocityContext ctx, final Template template, + final boolean append) throws MojoExecutionException { + + if (!path.exists()) { + throw new IllegalArgumentException("Invalid base path '" + path.getAbsolutePath() + "'"); + } + + FileWriter writer = null; + try { + final File toBeWritten = new File(path, name); + if (!append && toBeWritten.exists()) { + throw new IllegalStateException("File '" + toBeWritten.getAbsolutePath() + "' already exists"); + } + writer = new FileWriter(toBeWritten, append); + template.merge(ctx, writer); + } catch (IOException e) { + throw new MojoExecutionException("Error creating file '" + name + "'", e); + } finally { + IOUtils.closeQuietly(writer); + } + } + + protected VelocityContext newContext() { + + final VelocityContext ctx = new VelocityContext(); + + ctx.put("utility", getUtility()); + ctx.put("basePackage", basePackage); + ctx.put("schemaName", getUtility().getSchemaName()); + ctx.put("namespace", getUtility().getNamespace()); + ctx.put("namespaces", namespaces); + ctx.put("odataVersion", getVersion()); + + return ctx; + } + + protected void parseObj(final File base, final String pkg, final String name, final String out) + throws MojoExecutionException { + + parseObj(base, false, pkg, name, out, Collections.emptyMap()); + } + + protected void parseObj( + final File base, + final String pkg, + final String name, + final String out, + final Map objs) + throws MojoExecutionException { + + parseObj(base, false, pkg, name, out, objs); + } + + protected void parseObj( + final File base, + final boolean append, + final String pkg, + final String name, + final String out, + final Map objs) + throws MojoExecutionException { + + final VelocityContext ctx = newContext(); + ctx.put("package", pkg); + + if (objs != null) { + for (Map.Entry obj : objs.entrySet()) { + if (StringUtils.isNotBlank(obj.getKey()) && obj.getValue() != null) { + ctx.put(obj.getKey(), obj.getValue()); + } + } + } + + final Template template = Velocity.getTemplate(name + ".vm"); + writeFile(out, base, ctx, template, append); + } +} diff --git a/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/AbstractUtility.java b/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/AbstractUtility.java new file mode 100644 index 000000000..e52d2787f --- /dev/null +++ b/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/AbstractUtility.java @@ -0,0 +1,411 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT 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.ext.pojogen; + +import java.io.InputStream; +import java.sql.Timestamp; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang.StringUtils; +import org.apache.olingo.commons.api.edm.Edm; +import org.apache.olingo.commons.api.edm.EdmAction; +import org.apache.olingo.commons.api.edm.EdmEntitySet; +import org.apache.olingo.commons.api.edm.EdmEntityType; +import org.apache.olingo.commons.api.edm.EdmFunction; +import org.apache.olingo.commons.api.edm.EdmKeyPropertyRef; +import org.apache.olingo.commons.api.edm.EdmNavigationProperty; +import org.apache.olingo.commons.api.edm.EdmParameter; +import org.apache.olingo.commons.api.edm.EdmProperty; +import org.apache.olingo.commons.api.edm.EdmSchema; +import org.apache.olingo.commons.api.edm.EdmSingleton; +import org.apache.olingo.commons.api.edm.EdmStructuredType; +import org.apache.olingo.commons.api.edm.EdmType; +import org.apache.olingo.commons.api.edm.FullQualifiedName; +import org.apache.olingo.commons.core.edm.EdmTypeInfo; +import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory; + +public abstract class AbstractUtility { + + protected static final String FC_TARGET_PATH = "fcTargetPath"; + + protected static final String FC_SOURCE_PATH = "fcSourcePath"; + + protected static final String FC_KEEP_IN_CONTENT = "fcKeepInContent"; + + protected static final String FC_CONTENT_KIND = "fcContentKind"; + + protected static final String FC_NS_PREFIX = "fcNSPrefix"; + + protected static final String FC_NS_URI = "fcNSURI"; + + protected static final String TYPE_SUB_PKG = "types"; + + protected final String basePackage; + + protected final String schemaName; + + protected final String namespace; + + private final Edm metadata; + + private final EdmSchema schema; + + protected final Map> allEntityTypes = new HashMap>(); + + public AbstractUtility(final Edm metadata, final EdmSchema schema, final String basePackage) { + this.basePackage = basePackage; + this.schemaName = schema.getAlias(); + this.namespace = schema.getNamespace(); + this.metadata = metadata; + this.schema = schema; + + collectEntityTypes(); + } + + public EdmTypeInfo getEdmTypeInfo(final EdmType type) { + return new EdmTypeInfo.Builder().setEdm(metadata). + setTypeExpression(type.getFullQualifiedName().toString()).build(); + } + + public EdmTypeInfo getEdmTypeInfo(final String expression) { + return new EdmTypeInfo.Builder().setEdm(metadata).setTypeExpression(expression).build(); + } + + public EdmTypeInfo getEdmType(final EdmSingleton singleton) { + return getEdmTypeInfo(singleton.getEntityType().getFullQualifiedName().toString()); + } + + public Map getEntityKeyType(final EdmSingleton singleton) { + return getEntityKeyType(singleton.getEntityType()); + } + + protected Edm getMetadata() { + return metadata; + } + + protected EdmSchema getSchema() { + return schema; + } + + public String getNavigationType(final EdmNavigationProperty property) { + return property.getType().getFullQualifiedName().toString(); + } + + public NavPropertyBindingDetails getNavigationBindingDetails( + final EdmStructuredType sourceEntityType, final EdmNavigationProperty property) { + if (property.containsTarget()) { + return new NavPropertyContainsTarget(metadata, property.getType()); + } + + try { + return getNavigationBindings(sourceEntityType, property); + } catch (Exception e) { + // maybe source entity type without entity set ... + return getNavigationBindings(property.getType()); + } + } + + private NavPropertyBindingDetails getNavigationBindings(final EdmStructuredType type) { + if (type == null) { + throw new IllegalStateException("Invalid navigation property"); + } + + try { + return new NavPropertyBindingDetails(metadata, type); + } catch (IllegalStateException ignore) { + return getNavigationBindings(type.getBaseType()); + } + } + + private NavPropertyBindingDetails getNavigationBindings( + final EdmStructuredType sourceEntityType, final EdmNavigationProperty property) { + + if (sourceEntityType == null) { + throw new IllegalStateException("Invalid navigation property " + property.getName()); + } + + try { + return new NavPropertyBindingDetails(metadata, sourceEntityType, property); + } catch (IllegalStateException ignore) { + return getNavigationBindingDetails(sourceEntityType.getBaseType(), property); + } + } + + public EdmFunction getFunctionByName(final FullQualifiedName name) { + + final EdmSchema targetSchema = metadata.getSchema(name.getNamespace()); + + if (targetSchema != null) { + for (EdmFunction function : targetSchema.getFunctions()) { + if (function.getName().equals(name.getName())) { + return function; + } + } + } + + return null; + } + + public EdmAction getActionByName(final FullQualifiedName name) { + + final EdmSchema targetSchema = metadata.getSchema(name.getNamespace()); + + if (targetSchema != null) { + for (EdmAction action : targetSchema.getActions()) { + if (action.getName().equals(name.getName())) { + return action; + } + } + } + + return null; + } + + public List getFunctionsBoundTo(final String typeExpression, final boolean collection) { + + final List result = new ArrayList(); + + for (EdmSchema sch : getMetadata().getSchemas()) { + for (EdmFunction function : sch.getFunctions()) { + if (function.isBound()) { + final EdmParameter bound = function.getParameterNames().isEmpty() + ? null : function.getParameter(function.getParameterNames().get(0)); + + if (bound != null + && isSameType(typeExpression, bound.getType().getFullQualifiedName().toString(), false) + && ((bound.isCollection() && collection) || (!bound.isCollection() && !collection))) { + result.add(function); + } + } + } + } + + return result; + } + + public List getActionsBoundTo(final String typeExpression, final boolean collection) { + + final List result = new ArrayList(); + + for (EdmSchema sch : getMetadata().getSchemas()) { + for (EdmAction action : sch.getActions()) { + if (action.isBound()) { + final EdmParameter bound = action.getParameterNames().isEmpty() + ? null : action.getParameter(action.getParameterNames().get(0)); + + if (bound != null + && isSameType(typeExpression, bound.getType().getFullQualifiedName().toString(), false) + && ((bound.isCollection() && collection) || (!bound.isCollection() && !collection))) { + result.add(action); + } + } + } + } + + return result; + } + + private void collectEntityTypes() { + for (EdmSchema _schema : getMetadata().getSchemas()) { + allEntityTypes.put(_schema.getNamespace(), new ArrayList(_schema.getEntityTypes())); + if (StringUtils.isNotBlank(_schema.getAlias())) { + allEntityTypes.put(_schema.getAlias(), new ArrayList(_schema.getEntityTypes())); + } + } + } + + public String getJavaType(final EdmType type, final Boolean forceCollection) { + return getJavaType(type.getFullQualifiedName().toString(), forceCollection); + } + + public String getJavaType(final EdmType type) { + return getJavaType(type, false); + } + + public String getJavaType(final EdmEntityType entityType, final Boolean forceCollection) { + return getJavaType(entityType.getFullQualifiedName().toString(), forceCollection); + } + + public String getJavaType(final EdmEntityType entityType) { + return getJavaType(entityType, false); + } + + public String getJavaType(final String typeExpression) { + return getJavaType(typeExpression, false); + } + + public String getJavaType(final String typeExpression, final boolean forceCollection) { + final StringBuilder res = new StringBuilder(); + + final EdmTypeInfo edmType = getEdmTypeInfo(typeExpression); + + if ((forceCollection || edmType.isCollection()) && !edmType.isEntityType()) { + res.append("Collection<"); + } + + if ("Edm.Stream".equals(typeExpression)) { + res.append(InputStream.class.getName()); + } else if (edmType.isPrimitiveType()) { + final Class clazz = EdmPrimitiveTypeFactory.getInstance(edmType.getPrimitiveTypeKind()).getDefaultType(); + res.append((clazz.isAssignableFrom(Calendar.class) ? Timestamp.class : clazz).getSimpleName()); + } else if (edmType.isComplexType()) { + res.append(basePackage).append('.'). + append(edmType.getFullQualifiedName().getNamespace().toLowerCase()). // namespace + append('.').append(TYPE_SUB_PKG).append('.'). + append(capitalize(edmType.getComplexType().getName())); // ComplexType capitalized name + } else if (edmType.isEntityType()) { + res.append(basePackage).append('.'). + append(edmType.getFullQualifiedName().getNamespace().toLowerCase()). // namespace + append('.').append(TYPE_SUB_PKG).append('.'). + append(capitalize(edmType.getEntityType().getName())); // EntityType capitalized name + } else if (edmType.isEnumType()) { + res.append(basePackage).append('.'). + append(edmType.getFullQualifiedName().getNamespace().toLowerCase()). // namespace + append('.').append(TYPE_SUB_PKG).append('.'). + append(capitalize(edmType.getEnumType().getName())); + } else { + throw new IllegalArgumentException("Invalid type expression '" + typeExpression + "'"); + } + + if (forceCollection || edmType.isCollection()) { + if (edmType.isEntityType()) { + res.append("Collection"); + } else { + res.append(">"); + } + } + + return res.toString(); + } + + public EdmTypeInfo getEdmType(final EdmEntitySet entitySet) { + return getEdmTypeInfo(entitySet.getEntityType().getFullQualifiedName().toString()); + } + + public Map getEntityKeyType(final EdmEntitySet entitySet) { + return getEntityKeyType(getEdmType(entitySet).getEntityType()); + } + + public Map getEntityKeyType(final EdmEntityType entityType) { + EdmEntityType baseType = entityType; + while (CollectionUtils.isEmpty(baseType.getKeyPredicateNames()) && baseType.getBaseType() != null) { + baseType = getEdmTypeInfo(baseType.getBaseType().getFullQualifiedName().toString()).getEntityType(); + } + + final Map res = new HashMap(); + for (EdmKeyPropertyRef pref : baseType.getKeyPropertyRefs()) { + res.put(pref.getKeyPropertyName(), + getJavaType(pref.getProperty().getType().getFullQualifiedName().toString())); + } + + return res; + } + + public final String getNameInNamespace(final String name) { + return getSchema().getNamespace() + "." + name; + } + + public boolean isSameType( + final String entityTypeExpression, final String fullTypeExpression, final boolean collection) { + + final Set types = new HashSet(2); + + types.add((collection ? "Collection(" : StringUtils.EMPTY) + + getNameInNamespace(entityTypeExpression) + + (collection ? ")" : StringUtils.EMPTY)); + if (StringUtils.isNotBlank(getSchema().getAlias())) { + types.add((collection ? "Collection(" : StringUtils.EMPTY) + + getSchema().getAlias() + "." + entityTypeExpression + + (collection ? ")" : StringUtils.EMPTY)); + } + + return types.contains(fullTypeExpression); + } + + private void populateDescendants(final EdmTypeInfo base, final List descendants) { + for (Map.Entry> entry : allEntityTypes.entrySet()) { + for (EdmEntityType type : entry.getValue()) { + if (type.getBaseType() != null + && base.getFullQualifiedName().equals(type.getBaseType().getFullQualifiedName())) { + + final EdmTypeInfo entityTypeInfo = getEdmTypeInfo(type.getFullQualifiedName().toString()); + + descendants.add(entityTypeInfo.getFullQualifiedName().toString()); + populateDescendants(entityTypeInfo, descendants); + } + } + } + } + + public List getDescendantsOrSelf(final EdmTypeInfo entityType) { + final List descendants = new ArrayList(); + + descendants.add(entityType.getFullQualifiedName().toString()); + populateDescendants(entityType, descendants); + + return descendants; + } + + public String getBasePackage() { + return basePackage; + } + + public String getSchemaName() { + return schemaName; + } + + public String getNamespace() { + return namespace; + } + + public String capitalize(final String str) { + return StringUtils.capitalize(str); + } + + public String uncapitalize(final String str) { + return StringUtils.uncapitalize(str); + } + + public Map getFcProperties(final EdmProperty property) { + return Collections.emptyMap(); + } + + public final String getNameFromNS(final String ns) { + return getNameFromNS(ns, false); + } + + public final String getNameFromNS(final String ns, final boolean toLowerCase) { + String res = null; + + if (StringUtils.isNotBlank(ns)) { + final int lastpt = ns.lastIndexOf('.'); + res = ns.substring(lastpt < 0 ? 0 : lastpt + 1); + res = toLowerCase ? res.toLowerCase() : res; + } + + return res; + } +} diff --git a/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/NavPropertyBindingDetails.java b/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/NavPropertyBindingDetails.java new file mode 100644 index 000000000..27555bc1f --- /dev/null +++ b/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/NavPropertyBindingDetails.java @@ -0,0 +1,141 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT 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.ext.pojogen; + +import org.apache.olingo.client.api.v3.UnsupportedInV3Exception; +import org.apache.olingo.commons.api.edm.Edm; +import org.apache.olingo.commons.api.edm.EdmBindingTarget; +import org.apache.olingo.commons.api.edm.EdmEntityContainer; +import org.apache.olingo.commons.api.edm.EdmEntitySet; +import org.apache.olingo.commons.api.edm.EdmNavigationProperty; +import org.apache.olingo.commons.api.edm.EdmNavigationPropertyBinding; +import org.apache.olingo.commons.api.edm.EdmSchema; +import org.apache.olingo.commons.api.edm.EdmSingleton; +import org.apache.olingo.commons.api.edm.EdmStructuredType; + +public class NavPropertyBindingDetails { + + protected Edm edm; + + protected EdmSchema schema; + + protected EdmEntityContainer container; + + protected EdmBindingTarget entitySet; + + protected EdmStructuredType type; + + protected NavPropertyBindingDetails() { + } + + public NavPropertyBindingDetails(final Edm edm, final EdmStructuredType type) { + this.edm = edm; + this.type = type; + this.entitySet = getNavigationBindingDetails(type); + this.container = this.entitySet.getEntityContainer(); + this.schema = edm.getSchema(container.getNamespace()); + } + + public NavPropertyBindingDetails( + final Edm edm, final EdmStructuredType sourceType, final EdmNavigationProperty property) { + this.edm = edm; + this.entitySet = getNavigationBindingDetails(sourceType, property); + this.container = this.entitySet.getEntityContainer(); + this.schema = edm.getSchema(container.getNamespace()); + this.type = entitySet.getEntityType(); + } + + private EdmBindingTarget getNavigationBindingDetails(final EdmStructuredType type) { + for (EdmSchema sc : edm.getSchemas()) { + for (EdmEntityContainer c : sc.getEntityContainers()) { + for (EdmEntitySet es : c.getEntitySets()) { + if (es.getEntityType().getFullQualifiedName().equals(type.getFullQualifiedName())) { + return es; + } + } + + try { + for (EdmSingleton s : c.getSingletons()) { + if (s.getEntityType().getFullQualifiedName().equals(type.getFullQualifiedName())) { + return s; + } + } + } catch (UnsupportedInV3Exception ignore) { + // ignore + } + } + + } + + throw new IllegalStateException("EntitySet for '" + type.getName() + "' not found"); + } + + private EdmBindingTarget getNavigationBindingDetails( + final EdmStructuredType sourceType, final EdmNavigationProperty property) { + + for (EdmSchema sc : edm.getSchemas()) { + for (EdmEntityContainer c : sc.getEntityContainers()) { + for (EdmEntitySet es : c.getEntitySets()) { + if (es.getEntityType().getFullQualifiedName().equals(sourceType.getFullQualifiedName())) { + for (EdmNavigationPropertyBinding binding : es.getNavigationPropertyBindings()) { + if (binding.getPath().equals(property.getName()) + || binding.getPath().endsWith("/" + property.getName())) { + return es.getRelatedBindingTarget(binding.getPath()); + } + } + } + } + + try { + for (EdmSingleton s : c.getSingletons()) { + if (s.getEntityType().getFullQualifiedName().equals(sourceType.getFullQualifiedName())) { + for (EdmNavigationPropertyBinding binding : s.getNavigationPropertyBindings()) { + if (binding.getPath().equals(property.getName()) + || binding.getPath().endsWith("/" + property.getName())) { + return s.getRelatedBindingTarget(binding.getPath()); + } + } + } + } + } catch (UnsupportedInV3Exception ignore) { + // ignore + } + } + } + + throw new IllegalStateException( + "Navigation property '" + sourceType.getName() + "." + property.getName() + "' not valid"); + } + + public EdmSchema getSchema() { + return schema; + } + + public EdmEntityContainer getContainer() { + return container; + } + + public EdmBindingTarget getEntitySet() { + return entitySet; + } + + public EdmStructuredType getType() { + return type; + } +} diff --git a/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/NavPropertyContainsTarget.java b/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/NavPropertyContainsTarget.java new file mode 100644 index 000000000..54ce6fe0c --- /dev/null +++ b/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/NavPropertyContainsTarget.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.ext.pojogen; + +import org.apache.olingo.commons.api.edm.Edm; +import org.apache.olingo.commons.api.edm.EdmEntityType; + +public class NavPropertyContainsTarget extends NavPropertyBindingDetails { + + public NavPropertyContainsTarget(final Edm edm, final EdmEntityType type) { + super(); + this.edm = edm; + this.entitySet = null; + this.container = null; + this.type = type; + schema = edm.getSchema(type.getNamespace()); + } +} diff --git a/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/V3MetadataMojo.java b/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/V3MetadataMojo.java new file mode 100644 index 000000000..acd9f75e9 --- /dev/null +++ b/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/V3MetadataMojo.java @@ -0,0 +1,184 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT 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.ext.pojogen; + +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; +import java.io.File; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import org.apache.olingo.client.core.ODataClientFactory; +import org.apache.olingo.commons.api.edm.Edm; +import org.apache.olingo.commons.api.edm.EdmComplexType; +import org.apache.olingo.commons.api.edm.EdmEntityContainer; +import org.apache.olingo.commons.api.edm.EdmEntitySet; +import org.apache.olingo.commons.api.edm.EdmEntityType; +import org.apache.olingo.commons.api.edm.EdmEnumType; +import org.apache.olingo.commons.api.edm.EdmSchema; +import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion; +import org.apache.velocity.app.Velocity; +import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader; + +/** + * POJOs generator. + */ +@Mojo(name = "pojosV3", defaultPhase = LifecyclePhase.PROCESS_SOURCES) +public class V3MetadataMojo extends AbstractMetadataMojo { + + @Override + protected V3Utility getUtility() { + return (V3Utility) utility; + } + + @Override + protected String getVersion() { + return ODataServiceVersion.V30.name().toLowerCase(); + } + + @Override + public void execute() throws MojoExecutionException { + if (new File(outputDirectory + File.separator + TOOL_DIR).exists()) { + getLog().info("Nothing to do because " + TOOL_DIR + " directory already exists. Clean to update."); + return; + } + + try { + Velocity.addProperty(Velocity.RESOURCE_LOADER, "class"); + Velocity.addProperty("class.resource.loader.class", ClasspathResourceLoader.class.getName()); + + final Edm metadata = + ODataClientFactory.getV3().getRetrieveRequestFactory().getMetadataRequest(serviceRootURL).execute(). + getBody(); + + if (metadata == null) { + throw new IllegalStateException("Metadata not found"); + } + + for (EdmSchema schema : metadata.getSchemas()) { + namespaces.add(schema.getNamespace().toLowerCase()); + } + + final Set complexTypeNames = new HashSet(); + final File services = mkdir("META-INF/services"); + + for (EdmSchema schema : metadata.getSchemas()) { + utility = new V3Utility(metadata, schema, basePackage); + + // write package-info for the base package + final String schemaPath = utility.getNamespace().toLowerCase().replace('.', File.separatorChar); + final File base = mkPkgDir(schemaPath); + final String pkg = basePackage + "." + utility.getNamespace().toLowerCase(); + parseObj(base, pkg, "package-info", "package-info.java"); + + // write package-info for types package + final File typesBaseDir = mkPkgDir(schemaPath + "/types"); + final String typesPkg = pkg + ".types"; + parseObj(typesBaseDir, typesPkg, "package-info", "package-info.java"); + + final Map objs = new HashMap(); + + // write types into types package + for (EdmEnumType enumType : schema.getEnumTypes()) { + final String className = utility.capitalize(enumType.getName()); + objs.clear(); + objs.put("enumType", enumType); + parseObj(typesBaseDir, typesPkg, "enumType", className + ".java", objs); + } + + for (EdmComplexType complex : schema.getComplexTypes()) { + final String className = utility.capitalize(complex.getName()); + complexTypeNames.add(typesPkg + "." + className); + objs.clear(); + objs.put("complexType", complex); + parseObj(typesBaseDir, typesPkg, "complexType", className + ".java", objs); + } + + for (EdmEntityType entity : schema.getEntityTypes()) { + objs.clear(); + objs.put("entityType", entity); + + final Map keys; + + EdmEntityType baseType = null; + if (entity.getBaseType() == null) { + keys = getUtility().getEntityKeyType(entity); + } else { + baseType = entity.getBaseType(); + objs.put("baseType", getUtility().getJavaType(baseType.getFullQualifiedName().toString())); + while (baseType.getBaseType() != null) { + baseType = baseType.getBaseType(); + } + keys = getUtility().getEntityKeyType(baseType); + } + + if (keys.size() > 1) { + // create compound key class + final String keyClassName = utility.capitalize(baseType == null + ? entity.getName() + : baseType.getName()) + "Key"; + objs.put("keyRef", keyClassName); + + if (entity.getBaseType() == null) { + objs.put("keys", keys); + parseObj(typesBaseDir, typesPkg, "entityTypeKey", keyClassName + ".java", objs); + } + } + + parseObj(typesBaseDir, typesPkg, "entityType", + utility.capitalize(entity.getName()) + ".java", objs); + parseObj(typesBaseDir, typesPkg, "entityCollection", + utility.capitalize(entity.getName()) + "Collection.java", objs); + } + + // write container and top entity sets into the base package + for (EdmEntityContainer container : schema.getEntityContainers()) { + objs.clear(); + objs.put("container", container); + parseObj(base, pkg, "container", + utility.capitalize(container.getName()) + ".java", objs); + + for (EdmEntitySet entitySet : container.getEntitySets()) { + objs.clear(); + objs.put("entitySet", entitySet); + parseObj(base, pkg, "entitySet", + utility.capitalize(entitySet.getName()) + ".java", objs); + } + } + + parseObj(services, true, null, "services", "org.apache.olingo.ext.proxy.api.AbstractComplexType", + Collections.singletonMap("services", (Object) complexTypeNames)); + } + } catch (Exception t) { + final StringWriter stringWriter = new StringWriter(); + final PrintWriter printWriter = new PrintWriter(stringWriter); + t.printStackTrace(printWriter); + getLog().error(stringWriter.toString()); + + throw (t instanceof MojoExecutionException) + ? (MojoExecutionException) t + : new MojoExecutionException("While executin mojo", t); + } + } +} diff --git a/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/V3Utility.java b/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/V3Utility.java new file mode 100644 index 000000000..47c96e5a5 --- /dev/null +++ b/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/V3Utility.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.ext.pojogen; + +import org.apache.olingo.commons.api.edm.Edm; +import org.apache.olingo.commons.api.edm.EdmSchema; + +public class V3Utility extends AbstractUtility { + + public V3Utility(final Edm metadata, final EdmSchema schema, final String basePackage) { + super(metadata, schema, basePackage); + } +} diff --git a/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/V4MetadataMojo.java b/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/V4MetadataMojo.java new file mode 100644 index 000000000..042a5580b --- /dev/null +++ b/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/V4MetadataMojo.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.ext.pojogen; + +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; +import java.io.File; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; +import org.apache.olingo.client.core.ODataClientFactory; +import org.apache.olingo.commons.api.edm.Edm; +import org.apache.olingo.commons.api.edm.EdmComplexType; +import org.apache.olingo.commons.api.edm.EdmEntityContainer; +import org.apache.olingo.commons.api.edm.EdmEntitySet; +import org.apache.olingo.commons.api.edm.EdmEntityType; +import org.apache.olingo.commons.api.edm.EdmEnumType; +import org.apache.olingo.commons.api.edm.EdmSchema; +import org.apache.olingo.commons.api.edm.EdmSingleton; +import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion; +import org.apache.velocity.app.Velocity; +import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader; + +/** + * POJOs generator. + */ +@Mojo(name = "pojosV4", defaultPhase = LifecyclePhase.PROCESS_SOURCES) +public class V4MetadataMojo extends AbstractMetadataMojo { + + @Override + protected V4Utility getUtility() { + return (V4Utility) utility; + } + + @Override + protected String getVersion() { + return ODataServiceVersion.V40.name().toLowerCase(); + } + + @Override + public void execute() throws MojoExecutionException { + if (new File(outputDirectory + File.separator + TOOL_DIR).exists()) { + getLog().info("Nothing to do because " + TOOL_DIR + " directory already exists. Clean to update."); + return; + } + + try { + Velocity.addProperty(Velocity.RESOURCE_LOADER, "class"); + Velocity.addProperty("class.resource.loader.class", ClasspathResourceLoader.class.getName()); + + final Edm metadata = + ODataClientFactory.getV4().getRetrieveRequestFactory().getMetadataRequest(serviceRootURL).execute(). + getBody(); + + if (metadata == null) { + throw new IllegalStateException("Metadata not found"); + } + + for (EdmSchema schema : metadata.getSchemas()) { + namespaces.add(schema.getNamespace().toLowerCase()); + } + + final Set complexTypeNames = new HashSet(); + final File services = mkdir("META-INF/services"); + + for (EdmSchema schema : metadata.getSchemas()) { + utility = new V4Utility(metadata, schema, basePackage); + + // write package-info for the base package + final String schemaPath = utility.getNamespace().toLowerCase().replace('.', File.separatorChar); + final File base = mkPkgDir(schemaPath); + final String pkg = basePackage + "." + utility.getNamespace().toLowerCase(); + parseObj(base, pkg, "package-info", "package-info.java"); + + // write package-info for types package + final File typesBaseDir = mkPkgDir(schemaPath + "/types"); + final String typesPkg = pkg + ".types"; + parseObj(typesBaseDir, typesPkg, "package-info", "package-info.java"); + + final Map objs = new HashMap(); + + // write types into types package + for (EdmEnumType enumType : schema.getEnumTypes()) { + final String className = utility.capitalize(enumType.getName()); + objs.clear(); + objs.put("enumType", enumType); + parseObj(typesBaseDir, typesPkg, "enumType", className + ".java", objs); + } + + for (EdmComplexType complex : schema.getComplexTypes()) { + final String className = utility.capitalize(complex.getName()); + complexTypeNames.add(typesPkg + "." + className); + objs.clear(); + objs.put("complexType", complex); + parseObj(typesBaseDir, typesPkg, "complexType", className + ".java", objs); + } + + for (EdmEntityType entity : schema.getEntityTypes()) { + objs.clear(); + objs.put("entityType", entity); + + final Map keys; + + EdmEntityType baseType = null; + if (entity.getBaseType() == null) { + keys = getUtility().getEntityKeyType(entity); + } else { + baseType = entity.getBaseType(); + objs.put("baseType", getUtility().getJavaType(baseType.getFullQualifiedName().toString())); + while (baseType.getBaseType() != null) { + baseType = baseType.getBaseType(); + } + keys = getUtility().getEntityKeyType(baseType); + } + + if (keys.size() > 1) { + // create compound key class + final String keyClassName = utility.capitalize(baseType == null + ? entity.getName() + : baseType.getName()) + "Key"; + objs.put("keyRef", keyClassName); + + if (entity.getBaseType() == null) { + objs.put("keys", keys); + parseObj(typesBaseDir, typesPkg, "entityTypeKey", keyClassName + ".java", objs); + } + } + + parseObj(typesBaseDir, typesPkg, "entityType", + utility.capitalize(entity.getName()) + ".java", objs); + parseObj(typesBaseDir, typesPkg, "entityCollection", + utility.capitalize(entity.getName()) + "Collection.java", objs); + } + + // write container and top entity sets into the base package + for (EdmEntityContainer container : schema.getEntityContainers()) { + objs.clear(); + objs.put("container", container); + parseObj(base, pkg, "container", + utility.capitalize(container.getName()) + ".java", objs); + + for (EdmEntitySet entitySet : container.getEntitySets()) { + objs.clear(); + objs.put("entitySet", entitySet); + parseObj(base, pkg, "entitySet", + utility.capitalize(entitySet.getName()) + ".java", objs); + } + + for (EdmSingleton singleton : container.getSingletons()) { + objs.clear(); + objs.put("singleton", singleton); + parseObj(base, pkg, "singleton", + utility.capitalize(singleton.getName()) + ".java", objs); + } + } + + parseObj(services, true, null, "services", "org.apache.olingo.ext.proxy.api.AbstractComplexType", + Collections.singletonMap("services", (Object) complexTypeNames)); + } + } catch (Exception t) { + final StringWriter stringWriter = new StringWriter(); + final PrintWriter printWriter = new PrintWriter(stringWriter); + t.printStackTrace(printWriter); + getLog().error(stringWriter.toString()); + + throw (t instanceof MojoExecutionException) + ? (MojoExecutionException) t + : new MojoExecutionException("While executin mojo", t); + } + } +} diff --git a/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/V4Utility.java b/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/V4Utility.java new file mode 100644 index 000000000..874e41521 --- /dev/null +++ b/ext/pojogen-maven-plugin/src/main/java/org/apache/olingo/ext/pojogen/V4Utility.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.ext.pojogen; + +import org.apache.olingo.commons.api.edm.Edm; +import org.apache.olingo.commons.api.edm.EdmSchema; + +public class V4Utility extends AbstractUtility { + + public V4Utility(final Edm metadata, final EdmSchema schema, final String basePackage) { + super(metadata, schema, basePackage); + } +} diff --git a/ext/pojogen-maven-plugin/src/main/resources/complexType.vm b/ext/pojogen-maven-plugin/src/main/resources/complexType.vm new file mode 100644 index 000000000..683739cc9 --- /dev/null +++ b/ext/pojogen-maven-plugin/src/main/resources/complexType.vm @@ -0,0 +1,48 @@ +#* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *# +package ${package}; + +import org.apache.olingo.ext.proxy.api.annotations.Namespace; +import org.apache.olingo.ext.proxy.api.annotations.ComplexType; +import org.apache.olingo.ext.proxy.api.annotations.Property; +import org.apache.olingo.ext.proxy.api.annotations.NavigationProperty; +#foreach($ns in $namespaces) +import ${basePackage}.${ns}.*; +import ${basePackage}.${ns}.types.*; +#end + +// EdmSimpleType property imports +import org.apache.olingo.commons.api.edm.geo.Geospatial; +import org.apache.olingo.commons.api.edm.geo.GeospatialCollection; +import org.apache.olingo.commons.api.edm.geo.LineString; +import org.apache.olingo.commons.api.edm.geo.MultiLineString; +import org.apache.olingo.commons.api.edm.geo.MultiPoint; +import org.apache.olingo.commons.api.edm.geo.MultiPolygon; +import org.apache.olingo.commons.api.edm.geo.Point; +import org.apache.olingo.commons.api.edm.geo.Polygon; +import java.math.BigDecimal; +import java.net.URI; +import java.util.UUID; +import java.io.Serializable; +import java.util.Collection; +import java.sql.Timestamp; +import javax.xml.datatype.Duration; + +#parse( "${odataVersion}/complexType.vm" ) +} diff --git a/ext/pojogen-maven-plugin/src/main/resources/container.vm b/ext/pojogen-maven-plugin/src/main/resources/container.vm new file mode 100644 index 000000000..e37ba109c --- /dev/null +++ b/ext/pojogen-maven-plugin/src/main/resources/container.vm @@ -0,0 +1,107 @@ +#* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *# +#set( $clsSuffix = ".class" ) +package ${package}; + +import org.apache.olingo.client.api.http.HttpMethod; +import org.apache.olingo.ext.proxy.api.annotations.Namespace; +import org.apache.olingo.ext.proxy.api.annotations.EntityContainer; +import org.apache.olingo.ext.proxy.api.annotations.Operation; +import org.apache.olingo.ext.proxy.api.annotations.Parameter; +import org.apache.olingo.ext.proxy.api.AbstractContainer; +import org.apache.olingo.ext.proxy.api.OperationType; +#foreach($ns in $namespaces) +import ${basePackage}.${ns}.*; +import ${basePackage}.${ns}.types.*; +#end + +// EdmSimpleType property imports +import org.apache.olingo.commons.api.edm.geo.Geospatial; +import org.apache.olingo.commons.api.edm.geo.GeospatialCollection; +import org.apache.olingo.commons.api.edm.geo.LineString; +import org.apache.olingo.commons.api.edm.geo.MultiLineString; +import org.apache.olingo.commons.api.edm.geo.MultiPoint; +import org.apache.olingo.commons.api.edm.geo.MultiPolygon; +import org.apache.olingo.commons.api.edm.geo.Point; +import org.apache.olingo.commons.api.edm.geo.Polygon; +import java.math.BigDecimal; +import java.net.URI; +import java.util.UUID; +import java.io.Serializable; +import java.util.Collection; +import java.sql.Timestamp; +import javax.xml.datatype.Duration; + +@Namespace("$namespace") +@EntityContainer(name = "$container.Name", + isDefaultEntityContainer = $container.Default) +public interface $utility.capitalize($container.Name) extends AbstractContainer { + +#foreach($entitySet in $container.EntitySets) + $utility.capitalize($entitySet.Name) get$utility.capitalize($entitySet.Name)(); + +#end + +#parse( "${odataVersion}/container.vm" ) + + Operations operations(); + + public interface Operations { + #foreach($operation in $container.FunctionImports) + #foreach($function in $operation.UnboundFunctions) + @Operation(name = "$function.Name", + type = OperationType.FUNCTION, + isComposable = $function.Composable#if($function.ReturnType), + returnType = "#if( $function.ReturnType.Collection )Collection(#end$function.ReturnType.Type.FullQualifiedName.toString()#if( $function.ReturnType.Collection ))#end"#end) + #if($function.ReturnType)$utility.getJavaType($function.ReturnType.Type, $function.ReturnType.Collection)#{else}void#end $utility.uncapitalize($function.Name)( + #if($function.ParameterNames) + #set( $count = $function.ParameterNames.size() )#* + *##foreach($paramName in $function.ParameterNames)#* + *##set( $count = $count - 1 )#* + *##set( $param = $function.getParameter($paramName) )#* + *# @Parameter(name = "$param.Name", type = "#if( $param.Collection )Collection(#end$param.Type.FullQualifiedName.toString()#if( $param.Collection ))#end", nullable = $param.Nullable) $utility.getJavaType($param.Type, $param.Collection) $utility.uncapitalize($param.Name)#if( $count > 0 ), #end + + #end#* + *##end); + + #end + #end + + #foreach($operation in $container.ActionImports) + #set( $action = $operation.UnboundAction ) + #if($action) + @Operation(name = "$action.Name", + type = OperationType.ACTION#if($action.ReturnType), + returnType = "#if( $action.ReturnType.Collection )Collection(#end$action.ReturnType.Type.FullQualifiedName.toString()#if( $action.ReturnType.Collection ))#end"#end) + #if($action.ReturnType)$utility.getJavaType($action.ReturnType.Type, $action.ReturnType.Collection)#{else}void#end $utility.uncapitalize($action.Name)( + #if($action.ParameterNames) + #set( $count = $action.ParameterNames.size() )#* + *##foreach($paramName in $action.ParameterNames)#* + *##set( $count = $count - 1 )#* + *##set( $param = $action.getParameter($paramName) )#* + *# @Parameter(name = "$param.Name", type = "#if( $param.Collection )Collection(#end$param.Type.FullQualifiedName.toString()#if( $param.Collection ))#end", nullable = $param.Nullable) $utility.getJavaType($param.Type, $param.Collection) $utility.uncapitalize($param.Name)#if( $count > 0 ), #end + + #end#* + *##end); + #set( $action = false ) + + #end + #end + } +} diff --git a/ext/pojogen-maven-plugin/src/main/resources/entityCollection.vm b/ext/pojogen-maven-plugin/src/main/resources/entityCollection.vm new file mode 100644 index 000000000..4f7a6a6a5 --- /dev/null +++ b/ext/pojogen-maven-plugin/src/main/resources/entityCollection.vm @@ -0,0 +1,96 @@ +#* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *# +package ${package}; + +import org.apache.olingo.client.api.http.HttpMethod; +import org.apache.olingo.ext.proxy.api.AbstractEntityCollection; +import org.apache.olingo.ext.proxy.api.OperationType; +import org.apache.olingo.ext.proxy.api.annotations.Operation; +import org.apache.olingo.ext.proxy.api.annotations.Parameter; +#foreach($ns in $namespaces) +import ${basePackage}.${ns}.*; +import ${basePackage}.${ns}.types.*; +#end + +// EdmSimpleType property imports +import org.apache.olingo.commons.api.edm.geo.Geospatial; +import org.apache.olingo.commons.api.edm.geo.GeospatialCollection; +import org.apache.olingo.commons.api.edm.geo.LineString; +import org.apache.olingo.commons.api.edm.geo.MultiLineString; +import org.apache.olingo.commons.api.edm.geo.MultiPoint; +import org.apache.olingo.commons.api.edm.geo.MultiPolygon; +import org.apache.olingo.commons.api.edm.geo.Point; +import org.apache.olingo.commons.api.edm.geo.Polygon; +import java.math.BigDecimal; +import java.net.URI; +import java.util.UUID; +import java.io.Serializable; +import java.util.Collection; +import java.sql.Timestamp; +import javax.xml.datatype.Duration; + +public interface $utility.capitalize($entityType.Name)Collection extends AbstractEntityCollection<$utility.capitalize($entityType.Name)> { +#set( $functions = $utility.getFunctionsBoundTo($entityType.Name, false) ) +#set( $actions = $utility.getActionsBoundTo($entityType.Name, false) ) +#if( $functions.size() > 0 || $actions.size() > 0 ) + Operations operations(); + + public interface Operations { + + #foreach($operation in $functions) + @Operation(name = "$operation.Name", + type = OperationType.FUNCTION, + isComposable = $operation.Composable#if($operation.ReturnType), + returnType = "#if( $operation.ReturnType.Collection )Collection(#end$operation.ReturnType.Type.FullQualifiedName.toString()#if( $operation.ReturnType.Collection ))#end"#end) + #if($operation.ReturnType)$utility.getJavaType($operation.ReturnType.Type, $operation.ReturnType.Collection)#{else}void#end $utility.uncapitalize($operation.Name)( + #if($operation.ParameterNames) + #set( $count = $operation.ParameterNames.size() )#* + *##foreach($paramName in $operation.ParameterNames)#* + *##set( $count = $count - 1 )#* + *##set( $param = $operation.getParameter($paramName) )#* + *##if( !$entityType.FullQualifiedName.equals($param.Type.FullQualifiedName) )#* + *# @Parameter(name = "$param.Name", type = "#if( $param.Collection )Collection(#end$param.Type.FullQualifiedName.toString()#if( $param.Collection ))#end", nullable = $param.Nullable) $utility.getJavaType($param.Type, $param.Collection) $utility.uncapitalize($param.Name)#if( $count > 0 ), #end + + #end + #end#* + *##end); + + #end + + #foreach($operation in $actions) + @Operation(name = "$operation.Name", + type = OperationType.ACTION#if($operation.ReturnType), + returnType = "#if( $operation.ReturnType.Collection )Collection(#end$operation.ReturnType.Type.FullQualifiedName.toString()#if( $operation.ReturnType.Collection ))#end"#end) + #if($operation.ReturnType)$utility.getJavaType($operation.ReturnType.Type, $operation.ReturnType.Collection)#{else}void#end $utility.uncapitalize($operation.Name)( + #if($operation.ParameterNames) + #set( $count = $operation.ParameterNames.size() )#* + *##foreach($paramName in $operation.ParameterNames)#* + *##set( $count = $count - 1 )#* + *##set( $param = $operation.getParameter($paramName) )#* + *##if( !$entityType.FullQualifiedName.equals($param.Type.FullQualifiedName) )#* + *# @Parameter(name = "$param.Name", type = "#if( $param.Collection )Collection(#end$param.Type.FullQualifiedName.toString()#if( $param.Collection ))#end", nullable = $param.Nullable) $utility.getJavaType($param.Type, $param.Collection) $utility.uncapitalize($param.Name)#if( $count > 0 ), #end + + #end + #end#* + *##end); + + #end + } +#end +} diff --git a/ext/pojogen-maven-plugin/src/main/resources/entitySet.vm b/ext/pojogen-maven-plugin/src/main/resources/entitySet.vm new file mode 100644 index 000000000..49c8212f8 --- /dev/null +++ b/ext/pojogen-maven-plugin/src/main/resources/entitySet.vm @@ -0,0 +1,65 @@ +#* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *# +package ${package}; + +import org.apache.olingo.ext.proxy.api.AbstractEntitySet; +import org.apache.olingo.ext.proxy.api.annotations.EntitySet; +import org.apache.olingo.ext.proxy.api.annotations.CompoundKey; +import org.apache.olingo.ext.proxy.api.annotations.CompoundKeyElement; +#foreach($ns in $namespaces) +import ${basePackage}.${ns}.*; +import ${basePackage}.${ns}.types.*; +#end + +// EdmSimpleType property imports +import org.apache.olingo.commons.api.edm.geo.Geospatial; +import org.apache.olingo.commons.api.edm.geo.GeospatialCollection; +import org.apache.olingo.commons.api.edm.geo.LineString; +import org.apache.olingo.commons.api.edm.geo.MultiLineString; +import org.apache.olingo.commons.api.edm.geo.MultiPoint; +import org.apache.olingo.commons.api.edm.geo.MultiPolygon; +import org.apache.olingo.commons.api.edm.geo.Point; +import org.apache.olingo.commons.api.edm.geo.Polygon; +import java.math.BigDecimal; +import java.net.URI; +import java.util.UUID; +import java.io.Serializable; +import java.util.Collection; +import java.sql.Timestamp; +import javax.xml.datatype.Duration; + +#set( $keys = $utility.getEntityKeyType($entitySet) ) +#if( $keys.size() > 1 ) + #set( $type = $utility.getEdmType($entitySet).EntityType.Name + "Key" ) +#elseif( $keys.size() == 1 ) + #set( $type = $keys.values().iterator().next() ) +#else + #set( $type = "" ) +#end + +#parse( "${odataVersion}/entitySet.vm" ) +public interface $utility.capitalize($entitySet.Name) extends AbstractEntitySet<$utility.getJavaType($entitySet.EntityType), $type, $utility.getJavaType($entitySet.EntityType)Collection> { + +#foreach( $dos in $utility.getDescendantsOrSelf($utility.getEdmType($entitySet)) ) + #set( $djt = $utility.getJavaType($dos) ) + #set( $sIdx = $djt.lastIndexOf('.') + 1 ) + $djt new$djt.substring($sIdx)(); + ${djt}Collection new$djt.substring($sIdx)Collection(); +#end +} diff --git a/ext/pojogen-maven-plugin/src/main/resources/entityType.vm b/ext/pojogen-maven-plugin/src/main/resources/entityType.vm new file mode 100644 index 000000000..e831d93bb --- /dev/null +++ b/ext/pojogen-maven-plugin/src/main/resources/entityType.vm @@ -0,0 +1,169 @@ +#* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *# +#set( $clsSuffix = ".class" ) +package ${package}; + +import org.apache.olingo.client.api.http.HttpMethod; +import org.apache.olingo.ext.proxy.api.annotations.Namespace; +import org.apache.olingo.ext.proxy.api.annotations.EntityType; +import org.apache.olingo.ext.proxy.api.annotations.Key; +import org.apache.olingo.ext.proxy.api.annotations.KeyRef; +import org.apache.olingo.ext.proxy.api.annotations.NavigationProperty; +import org.apache.olingo.ext.proxy.api.annotations.Property; +import org.apache.olingo.ext.proxy.api.annotations.Operation; +import org.apache.olingo.ext.proxy.api.annotations.Parameter; +import org.apache.olingo.ext.proxy.api.AbstractOpenType; +import org.apache.olingo.ext.proxy.api.OperationType; +import org.apache.olingo.commons.api.edm.constants.EdmContentKind; +import org.apache.olingo.client.api.edm.ConcurrencyMode; +#foreach($ns in $namespaces) +import ${basePackage}.${ns}.*; +import ${basePackage}.${ns}.types.*; +#end + +// EdmSimpleType property imports +import org.apache.olingo.commons.api.edm.geo.Geospatial; +import org.apache.olingo.commons.api.edm.geo.GeospatialCollection; +import org.apache.olingo.commons.api.edm.geo.LineString; +import org.apache.olingo.commons.api.edm.geo.MultiLineString; +import org.apache.olingo.commons.api.edm.geo.MultiPoint; +import org.apache.olingo.commons.api.edm.geo.MultiPolygon; +import org.apache.olingo.commons.api.edm.geo.Point; +import org.apache.olingo.commons.api.edm.geo.Polygon; +import java.math.BigDecimal; +import java.net.URI; +import java.util.UUID; +import java.io.Serializable; +import java.util.Collection; +import java.sql.Timestamp; +import javax.xml.datatype.Duration; + +#if( $keyRef )@KeyRef(${keyRef}.class)#end + +@Namespace("$namespace") +@EntityType(name = "$entityType.Name", + openType = $entityType.isOpenType(), + hasStream = $entityType.hasStream(), + isAbstract = $entityType.Abstract#if($entityType.getBaseType()), + baseType = "$entityType.getBaseType().getFullQualifiedName().toString()"#end) +public interface $utility.capitalize($entityType.Name) extends #if( $entityType.getBaseType() )$utility.getJavaType($entityType.getBaseType())#{elseif}( $entityType.isOpenType() )AbstractOpenType#{else}Serializable#end { + +#set( $keys = [] ) +#foreach($key in $entityType.KeyPropertyRefs) + #if(!$keys.add($key.KeyPropertyName)) #stop #end +#end + +#foreach($propertyName in $entityType.PropertyNames) + #set($property = $entityType.getProperty($propertyName)) + #set($fcprops = $utility.getFcProperties($property) ) + #if($keys.contains($property.Name))@Key#end + + @Property(name = "$property.Name", + type = "$property.Type.FullQualifiedName.toString()", + nullable = $property.Nullable, + defaultValue = "#if($property.getDefaultValue())$property.getDefaultValue()#end", + maxLenght = #if($property.getMaxLength() && !$property.getMaxLength().equalsIgnoreCase("max"))$property.getMaxLength()#{else}Integer.MAX_VALUE#end, + fixedLenght = #if($property.isFixedLength())$property.isFixedLength()#{else}false#end, + precision = #if($property.getPrecision())$property.getPrecision()#{else}0#end, + scale = #if($property.getScale())$property.getScale()#{else}0#end, + unicode = #if($property.isUnicode())$property.isUnicode()#{else}false#end, + collation = "#if($property.getCollation())$property.getCollation()#end", + srid = "#if($property.getSRID())$property.getSRID()#end", + concurrencyMode = #if($property.getConcurrencyMode())ConcurrencyMode.$property.getConcurrencyMode()#{else}ConcurrencyMode.None#end, + fcSourcePath = "#if($fcprops.containsKey("fcSourcePath"))$fcprops.get("fcSourcePath")#end", + fcTargetPath = "#if($fcprops.containsKey("fcTargetPath"))$fcprops.get("fcTargetPath")#end", + fcContentKind = #if($fcprops.containsKey("fcContentKind"))EdmContentKind.$fcprops.get("fcContentKind")#{else}EdmContentKind.text#end, + fcNSPrefix = "#if($fcprops.containsKey("fcNSPrefix"))$fcprops.get("fcNSPrefix")#end", + fcNSURI = "#if($fcprops.containsKey("fcNSURI"))$fcprops.get("fcNSURI")#end", + fcKeepInContent = #if($fcprops.containsKey("fcKeepInContent"))$fcprops.get("fcKeepInContent")#{else}false#end) + $utility.getJavaType($property.Type) get$utility.capitalize($property.Name)(); + + void set$utility.capitalize($property.Name)(final $utility.getJavaType($property.Type) _$utility.uncapitalize($property.Name)); + +#end + +#foreach($propertyName in $entityType.NavigationPropertyNames) + #set($property = $entityType.getNavigationProperty($propertyName)) + #set( $type = $utility.getNavigationType($property) ) + #set( $binding = $utility.getNavigationBindingDetails($entityType, $property) ) + + @NavigationProperty(name = "$property.Name", + type = "$type", + targetSchema = "$binding.Schema.Namespace", + targetContainer = "#if($binding.Container)$binding.Container.Name#end", + targetEntitySet = "#if($binding.EntitySet)$binding.EntitySet.Name#end") + $utility.getJavaType($type, $property.Collection) get$utility.capitalize($property.Name)(); + + void set$utility.capitalize($property.Name)(final $utility.getJavaType($type, $property.Collection) _$utility.uncapitalize($property.Name)); + +#end + +#if($entityType.hasStream()) + void setStream(java.io.InputStream stream); + + java.io.InputStream getStream(); +#end + +#set( $functions = $utility.getFunctionsBoundTo($entityType.Name, false) ) +#set( $actions = $utility.getActionsBoundTo($entityType.Name, false) ) +#if( $functions.size() > 0 || $actions.size() > 0 ) + Operations operations(); + + public interface Operations { + #foreach($operation in $functions) + @Operation(name = "$operation.Name", + type = OperationType.FUNCTION, + isComposable = $operation.Composable#if($operation.ReturnType), + returnType = "#if( $operation.ReturnType.Collection )Collection(#end$operation.ReturnType.Type.FullQualifiedName.toString()#if( $operation.ReturnType.Collection ))#end"#end) + #if($operation.ReturnType)$utility.getJavaType($operation.ReturnType.Type, $operation.ReturnType.Collection)#{else}void#end $utility.uncapitalize($operation.Name)( + #if($operation.ParameterNames) + #set( $count = $operation.ParameterNames.size() )#* + *##foreach($paramName in $operation.ParameterNames)#* + *##set( $count = $count - 1 )#* + *##set( $param = $operation.getParameter($paramName) )#* + *##if( !$entityType.FullQualifiedName.equals($param.Type.FullQualifiedName) )#* + *# @Parameter(name = "$param.Name", type = "#if( $param.Collection )Collection(#end$param.Type.FullQualifiedName.toString()#if( $param.Collection ))#end", nullable = $param.Nullable) $utility.getJavaType($param.Type, $param.Collection) $utility.uncapitalize($param.Name)#if( $count > 0 ), #end + + #end + #end#* + *##end); + + #end + + #foreach($operation in $actions) + @Operation(name = "$operation.Name", + type = OperationType.ACTION#if($operation.ReturnType), + returnType = "#if( $operation.ReturnType.Collection )Collection(#end$operation.ReturnType.Type.FullQualifiedName.toString()#if( $operation.ReturnType.Collection ))#end"#end) + #if($operation.ReturnType)$utility.getJavaType($operation.ReturnType.Type, $operation.ReturnType.Collection)#{else}void#end $utility.uncapitalize($operation.Name)( + #if($operation.ParameterNames) + #set( $count = $operation.ParameterNames.size() )#* + *##foreach($paramName in $operation.ParameterNames)#* + *##set( $count = $count - 1 )#* + *##set( $param = $operation.getParameter($paramName) )#* + *##if( !$entityType.FullQualifiedName.equals($param.Type.FullQualifiedName) )#* + *# @Parameter(name = "$param.Name", type = "#if( $param.Collection )Collection(#end$param.Type.FullQualifiedName.toString()#if( $param.Collection ))#end", nullable = $param.Nullable) $utility.getJavaType($param.Type, $param.Collection) $utility.uncapitalize($param.Name)#if( $count > 0 ), #end + + #end + #end#* + *##end); + + #end + } +#end +} diff --git a/ext/pojogen-maven-plugin/src/main/resources/entityTypeKey.vm b/ext/pojogen-maven-plugin/src/main/resources/entityTypeKey.vm new file mode 100644 index 000000000..a4392bb69 --- /dev/null +++ b/ext/pojogen-maven-plugin/src/main/resources/entityTypeKey.vm @@ -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 ${package}; + +import org.apache.olingo.ext.proxy.api.annotations.EntityType; +import org.apache.olingo.ext.proxy.api.annotations.Key; +import org.apache.olingo.ext.proxy.api.annotations.CompoundKey; +import org.apache.olingo.ext.proxy.api.annotations.CompoundKeyElement; +import org.apache.olingo.ext.proxy.api.annotations.NavigationProperty; +import org.apache.olingo.ext.proxy.api.annotations.Property; +import org.apache.olingo.ext.proxy.api.AbstractEntityKey; +import org.apache.olingo.commons.api.edm.constants.EdmContentKind; +import org.apache.olingo.client.api.edm.ConcurrencyMode; +#foreach($ns in $namespaces) +import ${basePackage}.${ns}.*; +import ${basePackage}.${ns}.types.*; +#end + +// EdmSimpleType property imports +import org.apache.olingo.commons.api.edm.geo.Geospatial; +import org.apache.olingo.commons.api.edm.geo.GeospatialCollection; +import org.apache.olingo.commons.api.edm.geo.LineString; +import org.apache.olingo.commons.api.edm.geo.MultiLineString; +import org.apache.olingo.commons.api.edm.geo.MultiPoint; +import org.apache.olingo.commons.api.edm.geo.MultiPolygon; +import org.apache.olingo.commons.api.edm.geo.Point; +import org.apache.olingo.commons.api.edm.geo.Polygon; +import java.math.BigDecimal; +import java.net.URI; +import java.util.UUID; +import java.io.Serializable; +import java.util.Collection; +import java.sql.Timestamp; +import javax.xml.datatype.Duration; + +@CompoundKey +public class $keyRef extends AbstractEntityKey { +#set ( $count = 0 ) +#foreach ($entry in $keys.entrySet()) + + private $entry.getValue() _$utility.uncapitalize($entry.getKey()); + + @CompoundKeyElement(name = "$entry.getKey()", position = $count) + public $entry.getValue() get$utility.capitalize($entry.getKey())() { + return _$utility.uncapitalize($entry.getKey()); + } + + public void set$utility.capitalize($entry.getKey())(final $entry.getValue() _$utility.uncapitalize($entry.getKey())) { + this._$utility.uncapitalize($entry.getKey()) = _$utility.uncapitalize($entry.getKey()); + }#* + *##set ( $count = $count + 1 ) + +#end} diff --git a/ext/pojogen-maven-plugin/src/main/resources/enumType.vm b/ext/pojogen-maven-plugin/src/main/resources/enumType.vm new file mode 100644 index 000000000..5467613c2 --- /dev/null +++ b/ext/pojogen-maven-plugin/src/main/resources/enumType.vm @@ -0,0 +1,56 @@ +#* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *# +package ${package}; + +import org.apache.olingo.ext.proxy.api.annotations.Namespace; +import org.apache.olingo.ext.proxy.api.annotations.EnumType; +import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind; + +#set( $enumName = $utility.capitalize($enumType.Name) ) +#set( $count = $enumType.MemberNames.size() ) +#if( $enumType.UnderlyingType ) + #set( $javatype = $utility.getJavaType($enumType.UnderlyingType) ) +#else + #set( $javatype = $utility.getJavaType("Edm.Int32") ) +#end + +@Namespace("$namespace") +@EnumType(name = "$enumType.Name", + #if( $enumType.UnderlyingType )underlyingType = EdmPrimitiveTypeKind.${utility.getEdmTypeInfo($enumType.UnderlyingType).PrimitiveTypeKind.name()}, + #{end}isFlags = $enumType.Flags) +public enum $enumName { +#foreach ($memberName in $enumType.MemberNames)#* + *##set( $member = $enumType.getMember($memberName) )#* + *##set( $count = $count - 1 ) + $member.Name#if( $member.Value )($member.Value)#set( $valued = 1 )#end#if( $count > 0 ),#elseif( $count <= 0 );#end + +#end + +#if( $valued ) + private $javatype value; + + public $javatype getValue(){ + return this.value; + } + + private $enumName(final $javatype value){ + this.value=value; + } +#end +} diff --git a/ext/pojogen-maven-plugin/src/main/resources/package-info.vm b/ext/pojogen-maven-plugin/src/main/resources/package-info.vm new file mode 100644 index 000000000..ce11c6a3b --- /dev/null +++ b/ext/pojogen-maven-plugin/src/main/resources/package-info.vm @@ -0,0 +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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *# +package $package; + diff --git a/ext/pojogen-maven-plugin/src/main/resources/services.vm b/ext/pojogen-maven-plugin/src/main/resources/services.vm new file mode 100644 index 000000000..94480f368 --- /dev/null +++ b/ext/pojogen-maven-plugin/src/main/resources/services.vm @@ -0,0 +1,21 @@ +#* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *# +#foreach ($service in $services) +$service +#end \ No newline at end of file diff --git a/ext/pojogen-maven-plugin/src/main/resources/singleton.vm b/ext/pojogen-maven-plugin/src/main/resources/singleton.vm new file mode 100644 index 000000000..7fc2bffca --- /dev/null +++ b/ext/pojogen-maven-plugin/src/main/resources/singleton.vm @@ -0,0 +1,48 @@ +#* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *# +package ${package}; + +import org.apache.olingo.ext.proxy.api.AbstractEntitySet; +import org.apache.olingo.ext.proxy.api.annotations.EntitySet; +import org.apache.olingo.ext.proxy.api.annotations.Singleton; +import org.apache.olingo.ext.proxy.api.annotations.CompoundKey; +import org.apache.olingo.ext.proxy.api.annotations.CompoundKeyElement; +#foreach($ns in $namespaces) +import ${basePackage}.${ns}.*; +import ${basePackage}.${ns}.types.*; +#end + +// EdmSimpleType property imports +import org.apache.olingo.commons.api.edm.geo.Geospatial; +import org.apache.olingo.commons.api.edm.geo.GeospatialCollection; +import org.apache.olingo.commons.api.edm.geo.LineString; +import org.apache.olingo.commons.api.edm.geo.MultiLineString; +import org.apache.olingo.commons.api.edm.geo.MultiPoint; +import org.apache.olingo.commons.api.edm.geo.MultiPolygon; +import org.apache.olingo.commons.api.edm.geo.Point; +import org.apache.olingo.commons.api.edm.geo.Polygon; +import java.math.BigDecimal; +import java.net.URI; +import java.util.UUID; +import java.io.Serializable; +import java.util.Collection; +import java.sql.Timestamp; + +#parse( "${odataVersion}/singleton.vm" ) + diff --git a/ext/pojogen-maven-plugin/src/main/resources/v30/complexType.vm b/ext/pojogen-maven-plugin/src/main/resources/v30/complexType.vm new file mode 100644 index 000000000..676440846 --- /dev/null +++ b/ext/pojogen-maven-plugin/src/main/resources/v30/complexType.vm @@ -0,0 +1,30 @@ +#* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *# +@Namespace("$namespace") +@ComplexType(name = "$complexType.Name") +public interface $utility.capitalize($complexType.Name) extends Serializable { + +#foreach($propertyName in $complexType.PropertyNames) + #set($property = $complexType.getProperty($propertyName)) + + @Property(name = "$property.Name", type = "$property.Type.FullQualifiedName.toString()", nullable = $property.Nullable) + $utility.getJavaType($property.Type) get$utility.capitalize($property.Name)(); + + void set$utility.capitalize($property.Name)(final $utility.getJavaType($property.Type) _$utility.uncapitalize($property.Name)); +#end diff --git a/ext/pojogen-maven-plugin/src/main/resources/v30/container.vm b/ext/pojogen-maven-plugin/src/main/resources/v30/container.vm new file mode 100644 index 000000000..88a989c40 --- /dev/null +++ b/ext/pojogen-maven-plugin/src/main/resources/v30/container.vm @@ -0,0 +1,19 @@ +#* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *# + diff --git a/ext/pojogen-maven-plugin/src/main/resources/v30/entitySet.vm b/ext/pojogen-maven-plugin/src/main/resources/v30/entitySet.vm new file mode 100644 index 000000000..86f2bad67 --- /dev/null +++ b/ext/pojogen-maven-plugin/src/main/resources/v30/entitySet.vm @@ -0,0 +1,19 @@ +#* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *# +@EntitySet(name = "$entitySet.Name") diff --git a/ext/pojogen-maven-plugin/src/main/resources/v40/complexType.vm b/ext/pojogen-maven-plugin/src/main/resources/v40/complexType.vm new file mode 100644 index 000000000..92307ecd3 --- /dev/null +++ b/ext/pojogen-maven-plugin/src/main/resources/v40/complexType.vm @@ -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. + *# +@Namespace("$namespace") +@ComplexType(name = "$complexType.Name", + isOpenType = $complexType.isOpenType(), + isAbstract = $complexType.Abstract#if($complexType.getBaseType()), + baseType = "$complexType.getBaseType().getFullQualifiedName().toString()"#end) +public interface $utility.capitalize($complexType.Name) extends #if($complexType.getBaseType())$utility.getJavaType($complexType.getBaseType().getFullQualifiedName().toString())#{else}Serializable#end { + +#foreach($propertyName in $complexType.PropertyNames) + #set($property = $complexType.getProperty($propertyName)) + + @Property(name = "$property.Name", + type = "$property.Type", + nullable = $property.Nullable, + defaultValue = "#if($property.getDefaultValue())$property.getDefaultValue()#end", + maxLenght = #if($property.getMaxLength() && !$property.getMaxLength().equalsIgnoreCase("max"))$property.getMaxLength()#{else}Integer.MAX_VALUE#end, + fixedLenght = #if($property.isFixedLength())$property.isFixedLength()#{else}false#end, + precision = #if($property.getPrecision())$property.getPrecision()#{else}0#end, + scale = #if($property.getScale())$property.getScale()#{else}0#end, + unicode = #if($property.isUnicode())$property.isUnicode()#{else}false#end, + collation = "#if($property.getCollation())$property.getCollation()#end", + srid = "#if($property.getSRID())$property.getSRID()#end") + $utility.getJavaType($property.Type) get$utility.capitalize($property.Name)(); + + void set$utility.capitalize($property.Name)(final $utility.getJavaType($property.Type) _$utility.uncapitalize($property.Name)); + +#end + +#foreach($propertyName in $complexType.NavigationPropertyNames) + #set($property = $complexType.getNavigationProperty($propertyName)) + #set( $type = $utility.getNavigationType($property) ) + #set( $binding = $utility.getNavigationBindingDetails($complexType, $property) ) + + @NavigationProperty(name = "$property.Name", + type = "$type", + targetSchema = "$binding.Schema.Namespace", + targetContainer = "#if($binding.Container)$binding.Container.Name#end", + targetEntitySet = "#if($binding.EntitySet)$binding.EntitySet.Name#end") + $utility.getJavaType($type, $property.Collection) get$utility.capitalize($property.Name)(); + + void set$utility.capitalize($property.Name)(final $utility.getJavaType($type, $property.Collection) _$utility.uncapitalize($property.Name)); + +#end diff --git a/ext/pojogen-maven-plugin/src/main/resources/v40/container.vm b/ext/pojogen-maven-plugin/src/main/resources/v40/container.vm new file mode 100644 index 000000000..fb8c4b3a8 --- /dev/null +++ b/ext/pojogen-maven-plugin/src/main/resources/v40/container.vm @@ -0,0 +1,22 @@ +#* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *# +#foreach($singleton in $container.Singletons) + $utility.capitalize($singleton.Name) get$utility.capitalize($singleton.Name)(); + +#end diff --git a/ext/pojogen-maven-plugin/src/main/resources/v40/entitySet.vm b/ext/pojogen-maven-plugin/src/main/resources/v40/entitySet.vm new file mode 100644 index 000000000..cf60af0cd --- /dev/null +++ b/ext/pojogen-maven-plugin/src/main/resources/v40/entitySet.vm @@ -0,0 +1,19 @@ +#* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *# +@EntitySet(name = "$entitySet.Name", includeInServiceDocument = $entitySet.IncludeInServiceDocument) diff --git a/ext/pojogen-maven-plugin/src/main/resources/v40/singleton.vm b/ext/pojogen-maven-plugin/src/main/resources/v40/singleton.vm new file mode 100644 index 000000000..71cc55392 --- /dev/null +++ b/ext/pojogen-maven-plugin/src/main/resources/v40/singleton.vm @@ -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. + *# +#set( $keys = $utility.getEntityKeyType($singleton) ) +#if( $keys.size() > 1 ) + #set( $type = $utility.getEdmType($singleton).EntityType.Name + "Key" ) +#elseif( $keys.size() == 1 ) + #set( $type = $keys.values().iterator().next() ) +#else + #set( $type = "" ) +#end + +@Singleton(name = "$singleton.Name") +public interface $utility.capitalize($singleton.Name) extends AbstractEntitySet<$utility.getJavaType($singleton.EntityType), $type, $utility.getJavaType($singleton.EntityType)Collection> { + +#foreach( $dos in $utility.getDescendantsOrSelf($utility.getEdmType($singleton)) ) + #set( $djt = $utility.getJavaType($dos) ) + #set( $sIdx = $djt.lastIndexOf('.') + 1 ) + $djt new$djt.substring($sIdx)(); +#end +} diff --git a/ext/pom.xml b/ext/pom.xml index 37c943630..c2667ae07 100644 --- a/ext/pom.xml +++ b/ext/pom.xml @@ -37,5 +37,7 @@ client-core-android + pojogen-maven-plugin + client-proxy diff --git a/fit/pom.xml b/fit/pom.xml index 84a38d682..b47bdf118 100644 --- a/fit/pom.xml +++ b/fit/pom.xml @@ -36,6 +36,7 @@ 2.4 + 1.8 @@ -105,6 +106,34 @@ + + org.apache.maven.plugins + maven-invoker-plugin + ${invoker.maven.plugin.version} + true + + true + ${project.build.directory}/it + + */pom.xml + + verify + + clean + test-compile + + + + + integration-test + + integration-test + verify + + + + + org.apache.maven.plugins maven-war-plugin diff --git a/fit/src/it/staticServiceV3/pom.xml b/fit/src/it/staticServiceV3/pom.xml new file mode 100644 index 000000000..0e2d189d0 --- /dev/null +++ b/fit/src/it/staticServiceV3/pom.xml @@ -0,0 +1,93 @@ + + + + 4.0.0 + + pojogen-maven-plugin-v3test + org.apache.olingo + @project.version@ + ${project.artifactId} + A simple IT verifying the basic use case of pojogen-man-plugin. + + + UTF-8 + + + + + pojogen-maven-plugin + org.apache.olingo + @project.version@ + runtime + + + + client-proxy + org.apache.olingo + @project.version@ + + + + + + + org.codehaus.mojo + build-helper-maven-plugin + 1.8 + + + process-sources + + add-source + + + + ${project.build.directory}/generated-sources + + + + + + + + @project.groupId@ + pojogen-maven-plugin + @project.version@ + + + + ${project.build.directory}/generated-sources + http://localhost:9080/stub/StaticService/V30/Static.svc + org.apache.olingo.proxy.staticservice + + pojosV3 + generate-sources + + pojosV3 + + + + + + + diff --git a/fit/src/it/staticServiceV3/verify.groovy b/fit/src/it/staticServiceV3/verify.groovy new file mode 100644 index 000000000..9bb42a28e --- /dev/null +++ b/fit/src/it/staticServiceV3/verify.groovy @@ -0,0 +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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +File basepkg = new File( basedir, "target/generated-sources/ojc-plugin/org/apache/olingo/proxy" ); +assert basepkg.isDirectory() && basepkg.listFiles().length>0; diff --git a/fit/src/it/staticServiceV4/pom.xml b/fit/src/it/staticServiceV4/pom.xml new file mode 100644 index 000000000..113b69bcd --- /dev/null +++ b/fit/src/it/staticServiceV4/pom.xml @@ -0,0 +1,93 @@ + + + + 4.0.0 + + pojogen-maven-plugin-v4test + org.apache.olingo + @project.version@ + ${project.artifactId} + A simple IT verifying the basic use case of pojogen-man-plugin. + + + UTF-8 + + + + + pojogen-maven-plugin + org.apache.olingo + @project.version@ + runtime + + + + client-proxy + org.apache.olingo + @project.version@ + + + + + + + org.codehaus.mojo + build-helper-maven-plugin + 1.8 + + + process-sources + + add-source + + + + ${project.build.directory}/generated-sources + + + + + + + + @project.groupId@ + pojogen-maven-plugin + @project.version@ + + + + ${project.build.directory}/generated-sources + http://localhost:9080/stub/StaticService/V40/Static.svc + org.apache.olingo.proxy.staticservice + + pojosV4 + generate-sources + + pojosV4 + + + + + + + diff --git a/fit/src/it/staticServiceV4/verify.groovy b/fit/src/it/staticServiceV4/verify.groovy new file mode 100644 index 000000000..9bb42a28e --- /dev/null +++ b/fit/src/it/staticServiceV4/verify.groovy @@ -0,0 +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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +File basepkg = new File( basedir, "target/generated-sources/ojc-plugin/org/apache/olingo/proxy" ); +assert basepkg.isDirectory() && basepkg.listFiles().length>0; diff --git a/fit/src/main/resources/V40/metadata.xml b/fit/src/main/resources/V40/metadata.xml index b51bf0f93..5e7c9c62b 100644 --- a/fit/src/main/resources/V40/metadata.xml +++ b/fit/src/main/resources/V40/metadata.xml @@ -32,6 +32,7 @@ + diff --git a/fit/src/test/java/org/apache/olingo/fit/v3/ActionOverloadingTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v3/ActionOverloadingTestITCase.java index a28b354ae..de6d62d89 100644 --- a/fit/src/test/java/org/apache/olingo/fit/v3/ActionOverloadingTestITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/v3/ActionOverloadingTestITCase.java @@ -18,9 +18,9 @@ */ package org.apache.olingo.fit.v3; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertEquals; import java.util.LinkedHashMap; import java.util.Map; @@ -37,6 +37,7 @@ import org.apache.olingo.commons.api.edm.EdmAction; import org.apache.olingo.commons.api.edm.EdmActionImport; import org.apache.olingo.commons.api.edm.EdmEntityContainer; import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException; +import org.apache.olingo.commons.api.edm.EdmSchema; import org.apache.olingo.commons.api.edm.FullQualifiedName; import org.apache.olingo.commons.core.edm.primitivetype.EdmInt32; import org.junit.Test; @@ -124,58 +125,53 @@ public class ActionOverloadingTestITCase extends AbstractTestITCase { getMetadataRequest(testActionOverloadingServiceRootURL).execute().getBody(); assertNotNull(edm); - final EdmEntityContainer container = edm.getSchemas().get(0).getEntityContainer(); - assertNotNull(container); + final EdmSchema schema = edm.getSchemas().get(0); + assertNotNull(schema); - int execs = 0; - for (EdmActionImport actImp : container.getActionImports()) { - if ("IncreaseSalaries".equals(actImp.getName())) { - final Map parameters = new LinkedHashMap(1); - parameters.put("n", getClient().getObjectFactory().newPrimitiveValueBuilder().buildInt32(5)); + EdmAction actImp = edm.getBoundAction( + new FullQualifiedName(schema.getNamespace(), "IncreaseSalaries"), + new FullQualifiedName(schema.getNamespace(), "Employee"), + true); - // 1. bound to employees - final EdmAction employeeBound = edm.getBoundAction( - new FullQualifiedName(container.getNamespace(), actImp.getName()), - new FullQualifiedName(container.getNamespace(), "Employee"), true); - assertNotNull(employeeBound); - assertNull(employeeBound.getReturnType()); + final Map parameters = new LinkedHashMap(1); + parameters.put("n", getClient().getObjectFactory().newPrimitiveValueBuilder().buildInt32(5)); - final URIBuilder employeeBuilder = getClient().getURIBuilder(testActionOverloadingServiceRootURL). - appendEntitySetSegment("Person"). - appendDerivedEntityTypeSegment("Microsoft.Test.OData.Services.AstoriaDefaultService.Employee"); - final ODataEntitySet employees = getClient().getRetrieveRequestFactory().getEntitySetRequest( - employeeBuilder.build()).execute().getBody(); - assertNotNull(employees); + // 1. bound to employees + assertNotNull(actImp); + assertNull(actImp.getReturnType()); - final ODataInvokeResponse employeeRes = getClient().getInvokeRequestFactory(). - getInvokeRequest(employeeBuilder.appendOperationCallSegment(actImp.getName()).build(), - employeeBound, parameters).execute(); - assertNotNull(employeeRes); - assertEquals(204, employeeRes.getStatusCode()); - execs++; + final URIBuilder employeeBuilder = getClient().getURIBuilder(testActionOverloadingServiceRootURL). + appendEntitySetSegment("Person"). + appendDerivedEntityTypeSegment("Microsoft.Test.OData.Services.AstoriaDefaultService.Employee"); + final ODataEntitySet employees = getClient().getRetrieveRequestFactory().getEntitySetRequest( + employeeBuilder.build()).execute().getBody(); + assertNotNull(employees); - // 1. bound to special employees - final EdmAction specEmpBound = edm.getBoundAction( - new FullQualifiedName(container.getNamespace(), actImp.getName()), - new FullQualifiedName(container.getNamespace(), "SpecialEmployee"), true); - assertNotNull(specEmpBound); - assertNull(specEmpBound.getReturnType()); + final ODataInvokeResponse employeeRes = getClient().getInvokeRequestFactory(). + getInvokeRequest(employeeBuilder.appendOperationCallSegment(actImp.getName()).build(), + actImp, parameters).execute(); + assertNotNull(employeeRes); + assertEquals(204, employeeRes.getStatusCode()); - final URIBuilder specEmpBuilder = getClient().getURIBuilder(testActionOverloadingServiceRootURL). - appendEntitySetSegment("Person"). - appendDerivedEntityTypeSegment("Microsoft.Test.OData.Services.AstoriaDefaultService.SpecialEmployee"); - final ODataEntitySet specEmps = getClient().getRetrieveRequestFactory().getEntitySetRequest( - specEmpBuilder.build()).execute().getBody(); - assertNotNull(specEmps); + // 2. bound to special employees + actImp = edm.getBoundAction( + new FullQualifiedName(schema.getNamespace(), "IncreaseSalaries"), + new FullQualifiedName(schema.getNamespace(), "SpecialEmployee"), + true); + assertNotNull(actImp); + assertNull(actImp.getReturnType()); - final ODataInvokeResponse specEmpsRes = getClient().getInvokeRequestFactory(). - getInvokeRequest(specEmpBuilder.appendOperationCallSegment(actImp.getName()).build(), - specEmpBound, parameters).execute(); - assertNotNull(specEmpsRes); - assertEquals(204, specEmpsRes.getStatusCode()); - execs++; - } - } - assertEquals(2, execs); + final URIBuilder specEmpBuilder = getClient().getURIBuilder(testActionOverloadingServiceRootURL). + appendEntitySetSegment("Person"). + appendDerivedEntityTypeSegment("Microsoft.Test.OData.Services.AstoriaDefaultService.SpecialEmployee"); + final ODataEntitySet specEmps = getClient().getRetrieveRequestFactory().getEntitySetRequest( + specEmpBuilder.build()).execute().getBody(); + assertNotNull(specEmps); + + final ODataInvokeResponse specEmpsRes = getClient().getInvokeRequestFactory(). + getInvokeRequest(specEmpBuilder.appendOperationCallSegment(actImp.getName()).build(), + actImp, parameters).execute(); + assertNotNull(specEmpsRes); + assertEquals(204, specEmpsRes.getStatusCode()); } } diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmBindingTargetImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmBindingTargetImpl.java index bb2312812..ed26215fd 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmBindingTargetImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmBindingTargetImpl.java @@ -19,20 +19,16 @@ package org.apache.olingo.client.core.edm; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; import org.apache.olingo.client.api.edm.xml.v4.BindingTarget; import org.apache.olingo.client.api.edm.xml.v4.NavigationPropertyBinding; import org.apache.olingo.commons.api.edm.Edm; import org.apache.olingo.commons.api.edm.EdmAnnotation; -import org.apache.olingo.commons.api.edm.EdmBindingTarget; import org.apache.olingo.commons.api.edm.EdmEntityContainer; -import org.apache.olingo.commons.api.edm.EdmException; import org.apache.olingo.commons.api.edm.EdmNavigationPropertyBinding; import org.apache.olingo.commons.api.edm.EdmTerm; import org.apache.olingo.commons.api.edm.FullQualifiedName; -import org.apache.olingo.commons.api.edm.Target; import org.apache.olingo.commons.core.edm.AbstractEdmBindingTarget; import org.apache.olingo.commons.core.edm.EdmAnnotationHelper; import org.apache.olingo.commons.core.edm.EdmNavigationPropertyBindingImpl; @@ -53,41 +49,6 @@ public abstract class EdmBindingTargetImpl extends AbstractEdmBindingTarget { this.helper = new EdmAnnotationHelperImpl(edm, target); } - @Override - public EdmBindingTarget getRelatedBindingTarget(final String path) { - EdmBindingTarget bindingTarget = null; - - final List navigationPropertyBindings = target.getNavigationPropertyBindings(); - boolean found = false; - for (final Iterator itor = navigationPropertyBindings.iterator(); itor - .hasNext() - && !found;) { - - final NavigationPropertyBinding binding = itor.next(); - if (binding.getPath().equals(path)) { - final Target edmTarget = new Target.Builder(binding.getTarget(), container).build(); - - final EdmEntityContainer entityContainer = edm.getEntityContainer(edmTarget.getEntityContainer()); - if (entityContainer == null) { - throw new EdmException("Cannot find entity container with name: " + edmTarget.getEntityContainer()); - } - bindingTarget = entityContainer.getEntitySet(edmTarget.getTargetName()); - if (bindingTarget == null) { - bindingTarget = entityContainer.getSingleton(edmTarget.getTargetName()); - if (bindingTarget == null) { - throw new EdmException("Cannot find target with name: " + edmTarget.getTargetName()); - } - - found = true; - } else { - found = true; - } - } - } - - return bindingTarget; - } - @Override public List getNavigationPropertyBindings() { if (navigationPropertyBindings == null) { @@ -111,5 +72,4 @@ public abstract class EdmBindingTargetImpl extends AbstractEdmBindingTarget { public List getAnnotations() { return helper.getAnnotations(); } - } diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmEntityContainerImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmEntityContainerImpl.java index 30127d315..799e439ca 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmEntityContainerImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmEntityContainerImpl.java @@ -33,6 +33,7 @@ import org.apache.olingo.client.api.edm.xml.v4.Singleton; import org.apache.olingo.client.core.edm.v3.EdmActionImportProxy; import org.apache.olingo.client.core.edm.v3.EdmEntitySetProxy; import org.apache.olingo.client.core.edm.v3.EdmFunctionImportProxy; +import org.apache.olingo.client.core.edm.v3.FunctionImportUtils; import org.apache.olingo.commons.api.edm.Edm; import org.apache.olingo.commons.api.edm.EdmActionImport; import org.apache.olingo.commons.api.edm.EdmAnnotation; @@ -169,16 +170,18 @@ public class EdmEntityContainerImpl extends AbstractEdmEntityContainer { @Override protected void loadAllFunctionImports() { final List localFunctionImports = xmlEntityContainer.getFunctionImports(); - if (localFunctionImports != null) { - for (CommonFunctionImport functionImport : localFunctionImports) { - EdmFunctionImport edmFunctionImport; - if (functionImport instanceof org.apache.olingo.client.api.edm.xml.v4.FunctionImport) { - edmFunctionImport = new EdmFunctionImportImpl(edm, this, functionImport.getName(), - (org.apache.olingo.client.api.edm.xml.v4.FunctionImport) functionImport); - } else { - edmFunctionImport = new EdmFunctionImportProxy(edm, this, functionImport.getName(), - (org.apache.olingo.client.api.edm.xml.v3.FunctionImport) functionImport); - } + for (CommonFunctionImport functionImport : localFunctionImports) { + EdmFunctionImport edmFunctionImport; + if (functionImport instanceof org.apache.olingo.client.api.edm.xml.v4.FunctionImport) { + edmFunctionImport = new EdmFunctionImportImpl(edm, this, functionImport.getName(), + (org.apache.olingo.client.api.edm.xml.v4.FunctionImport) functionImport); + functionImports.put(edmFunctionImport.getName(), edmFunctionImport); + } else if (FunctionImportUtils.canProxyFunction( + (org.apache.olingo.client.api.edm.xml.v3.FunctionImport) functionImport) + && !((org.apache.olingo.client.api.edm.xml.v3.FunctionImport) functionImport).isBindable() + && !((org.apache.olingo.client.api.edm.xml.v3.FunctionImport) functionImport).isAlwaysBindable()) { + edmFunctionImport = new EdmFunctionImportProxy(edm, this, functionImport.getName(), + (org.apache.olingo.client.api.edm.xml.v3.FunctionImport) functionImport); functionImports.put(edmFunctionImport.getName(), edmFunctionImport); } } @@ -216,8 +219,9 @@ public class EdmEntityContainerImpl extends AbstractEdmEntityContainer { } else { @SuppressWarnings("unchecked") final List localFunctionImports = (List) xmlEntityContainer.getFunctionImports(); - if (localFunctionImports != null) { - for (FunctionImport functionImport : localFunctionImports) { + for (FunctionImport functionImport : localFunctionImports) { + if (!FunctionImportUtils.canProxyFunction(functionImport) && !functionImport.isBindable() + && !functionImport.isAlwaysBindable()) { actionImports.put(functionImport.getName(), new EdmActionImportProxy(edm, this, functionImport.getName(), functionImport)); } diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmOperationImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmOperationImpl.java index 3643dbde1..9e8b3bca2 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmOperationImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmOperationImpl.java @@ -20,6 +20,7 @@ package org.apache.olingo.client.core.edm; import java.util.ArrayList; import java.util.List; +import org.apache.commons.lang3.StringUtils; import org.apache.olingo.client.api.edm.xml.CommonParameter; import org.apache.olingo.client.api.edm.xml.v4.Action; @@ -46,7 +47,12 @@ public abstract class EdmOperationImpl extends AbstractEdmOperation { } instance.setParameters(_parameters); - instance.setEntitySetPath(instance.operation.getEntitySetPath()); + final String entitySetPath = instance.operation.getEntitySetPath(); + if (StringUtils.isNotBlank(entitySetPath)) { + // remove bindingParameter info and keep path only + int firstSlashIndex = entitySetPath.indexOf("/"); + instance.setEntitySetPath(entitySetPath.substring(firstSlashIndex + 1)); + } instance.setIsBound(instance.operation.isBound()); diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmSchemaImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmSchemaImpl.java index 12107ba19..61e5267d7 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmSchemaImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/edm/EdmSchemaImpl.java @@ -78,9 +78,10 @@ public class EdmSchemaImpl extends AbstractEdmSchema { @Override public List getEntityContainers() { if (entityContainers == null) { + entityContainerByName = new HashMap(); + if (schema instanceof org.apache.olingo.client.api.edm.xml.v4.Schema) { entityContainers = super.getEntityContainers(); - entityContainerByName = new HashMap(); entityContainerByName.put(getEntityContainer().getFullQualifiedName(), getEntityContainer()); } else { entityContainers = new ArrayList(schema.getEntityContainers().size()); diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/MetadataTest.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/MetadataTest.java index 51a2356c5..f6bcdb938 100644 --- a/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/MetadataTest.java +++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/v3/MetadataTest.java @@ -123,6 +123,10 @@ public class MetadataTest extends AbstractTest { assertEquals(container.getEntitySet("Customer").getEntityContainer().getFullQualifiedName(), logins.getRelatedBindingTarget("Customer").getEntityContainer().getFullQualifiedName()); assertEquals(container.getEntitySet("Customer").getName(), logins.getRelatedBindingTarget("Customer").getName()); + assertEquals(6, container.getFunctionImports().size()); + assertEquals(1, container.getActionImports().size()); + assertNotNull(container.getActionImports().iterator().next().getUnboundAction()); + assertEquals("ResetDataSource", container.getActionImports().iterator().next().getUnboundAction().getName()); // 5. Operation final EdmFunctionImport funcImp = container.getFunctionImport("InStreamErrorGetCustomer"); diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/MetadataTest.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/MetadataTest.java index 267083a72..ace8960c6 100644 --- a/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/MetadataTest.java +++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/v4/MetadataTest.java @@ -100,11 +100,15 @@ public class MetadataTest extends AbstractTest { final EdmEntityType user = edm.getEntityType( new FullQualifiedName("Microsoft.Exchange.Services.OData.Model", "User")); assertNotNull(user); + assertFalse(user.getPropertyNames().isEmpty()); + assertFalse(user.getNavigationPropertyNames().isEmpty()); + final EdmEntityType entity = edm.getEntityType( new FullQualifiedName("Microsoft.Exchange.Services.OData.Model", "Entity")); assertEquals(entity, user.getBaseType()); - assertFalse(user.getPropertyNames().isEmpty()); - assertFalse(user.getNavigationPropertyNames().isEmpty()); + assertFalse(entity.getPropertyNames().isEmpty()); + assertTrue(entity.getNavigationPropertyNames().isEmpty()); + final EdmEntityType folder = edm.getEntityType( new FullQualifiedName("Microsoft.Exchange.Services.OData.Model", "Folder")); assertEquals(folder, user.getNavigationProperty("Inbox").getType()); diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmEntityContainer.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmEntityContainer.java index 4db1e8e18..74e490ed8 100644 --- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmEntityContainer.java +++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmEntityContainer.java @@ -111,5 +111,4 @@ public interface EdmEntityContainer extends EdmNamed, EdmAnnotationsTarget, EdmA * @return the {@link FullQualifiedName} of the parentContainer or null if no parent is specified */ FullQualifiedName getParentContainerName(); - } diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdm.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdm.java index 0aa7404f4..4e9381125 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdm.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdm.java @@ -82,6 +82,26 @@ public abstract class AbstractEdm implements Edm { @Override public List getSchemas() { + initSchemas(); + return schemaList; + } + + @Override + public EdmSchema getSchema(final String namespace) { + initSchemas(); + + EdmSchema schema = schemas.get(namespace); + if (schema == null) { + if (aliasToNamespaceInfo == null) { + aliasToNamespaceInfo = createAliasToNamespaceInfo(); + } + schema = schemas.get(aliasToNamespaceInfo.get(namespace)); + } + + return schema; + } + + private void initSchemas() { if (schemas == null) { schemas = createSchemas(); if (schemas != null) { @@ -89,6 +109,8 @@ public abstract class AbstractEdm implements Edm { aliasToNamespaceInfo = new HashMap(); for (EdmSchema schema : schemas.values()) { final String namespace = schema.getNamespace(); + schemas.put(namespace, schema); + if (schema.getAlias() != null) { aliasToNamespaceInfo.put(schema.getAlias(), namespace); } @@ -166,25 +188,6 @@ public abstract class AbstractEdm implements Edm { } } } - return schemaList; - } - - @Override - public EdmSchema getSchema(final String namespace) { - // enusure schemas are loaded - getSchemas(); - - EdmSchema schema = null; - if (schemas != null) { - schema = schemas.get(namespace); - if (schema == null) { - if (aliasToNamespaceInfo == null) { - aliasToNamespaceInfo = createAliasToNamespaceInfo(); - } - schema = schemas.get(aliasToNamespaceInfo.get(namespace)); - } - } - return schema; } @Override diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmBindingTarget.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmBindingTarget.java index d4efd430b..58317f1e1 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmBindingTarget.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmBindingTarget.java @@ -18,12 +18,15 @@ */ package org.apache.olingo.commons.core.edm; +import java.util.Iterator; import org.apache.olingo.commons.api.edm.Edm; import org.apache.olingo.commons.api.edm.EdmBindingTarget; import org.apache.olingo.commons.api.edm.EdmEntityContainer; import org.apache.olingo.commons.api.edm.EdmEntityType; import org.apache.olingo.commons.api.edm.EdmException; +import org.apache.olingo.commons.api.edm.EdmNavigationPropertyBinding; import org.apache.olingo.commons.api.edm.FullQualifiedName; +import org.apache.olingo.commons.api.edm.Target; public abstract class AbstractEdmBindingTarget extends EdmNamedImpl implements EdmBindingTarget { @@ -63,4 +66,40 @@ public abstract class AbstractEdmBindingTarget extends EdmNamedImpl implements E return getName(); } + @Override + public EdmBindingTarget getRelatedBindingTarget(final String path) { + EdmBindingTarget bindingTarget = null; + boolean found = false; + for (final Iterator itor = getNavigationPropertyBindings().iterator(); + itor.hasNext() && !found;) { + + final EdmNavigationPropertyBinding binding = itor.next(); + if (binding.getPath().equals(path)) { + final Target edmTarget = new Target.Builder(binding.getTarget(), container).build(); + + final EdmEntityContainer entityContainer = edm.getEntityContainer(edmTarget.getEntityContainer()); + if (entityContainer == null) { + throw new EdmException("Cannot find entity container with name: " + edmTarget.getEntityContainer()); + } + try { + bindingTarget = entityContainer.getEntitySet(edmTarget.getTargetName()); + + if (bindingTarget == null) { + throw new EdmException("Cannot find EntitySet " + edmTarget.getTargetName()); + } + } catch (EdmException e) { + // try with singletons ... + bindingTarget = entityContainer.getSingleton(edmTarget.getTargetName()); + + if (bindingTarget == null) { + throw new EdmException("Cannot find Singleton " + edmTarget.getTargetName()); + } + } finally { + found = bindingTarget != null; + } + } + } + + return bindingTarget; + } } diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmEntityContainer.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmEntityContainer.java index 5c387fc44..f7a71f17e 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmEntityContainer.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmEntityContainer.java @@ -82,7 +82,9 @@ public abstract class AbstractEdmEntityContainer extends EdmNamedImpl implements EdmSingleton singleton = singletons.get(singletonName); if (singleton == null) { singleton = createSingleton(singletonName); - singletons.put(singletonName, singleton); + if (singleton != null) { + singletons.put(singletonName, singleton); + } } return singleton; } @@ -94,7 +96,9 @@ public abstract class AbstractEdmEntityContainer extends EdmNamedImpl implements EdmEntitySet entitySet = entitySets.get(entitySetName); if (entitySet == null) { entitySet = createEntitySet(entitySetName); - entitySets.put(entitySetName, entitySet); + if (entitySet != null) { + entitySets.put(entitySetName, entitySet); + } } return entitySet; } @@ -106,7 +110,9 @@ public abstract class AbstractEdmEntityContainer extends EdmNamedImpl implements EdmActionImport actionImport = actionImports.get(actionImportName); if (actionImport == null) { actionImport = createActionImport(actionImportName); - actionImports.put(actionImportName, actionImport); + if (actionImport != null) { + actionImports.put(actionImportName, actionImport); + } } return actionImport; } @@ -118,7 +124,9 @@ public abstract class AbstractEdmEntityContainer extends EdmNamedImpl implements EdmFunctionImport functionImport = functionImports.get(functionImportName); if (functionImport == null) { functionImport = createFunctionImport(functionImportName); - functionImports.put(functionImportName, functionImport); + if (functionImport != null) { + functionImports.put(functionImportName, functionImport); + } } return functionImport; } @@ -186,5 +194,4 @@ public abstract class AbstractEdmEntityContainer extends EdmNamedImpl implements public FullQualifiedName getAnnotationsTargetFQN() { return getFullQualifiedName(); } - } diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmNavigationProperty.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmNavigationProperty.java index 2ac876c1a..ed494510b 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmNavigationProperty.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/AbstractEdmNavigationProperty.java @@ -72,6 +72,7 @@ public abstract class AbstractEdmNavigationProperty extends EdmElementImpl imple return partnerNavigationProperty; } + @Override public abstract String getReferencingPropertyName(String referencedPropertyName); @Override diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmTypeInfo.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmTypeInfo.java index 5e4f13ef5..3a6b3d165 100644 --- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmTypeInfo.java +++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmTypeInfo.java @@ -68,8 +68,6 @@ public class EdmTypeInfo { } private final Edm edm; - private final String typeExpression; - private final boolean collection; private final FullQualifiedName fullQualifiedName; @@ -124,7 +122,6 @@ public class EdmTypeInfo { final StringBuilder exp = new StringBuilder(); exp.append(baseType); - this.typeExpression = (this.collection ? exp.insert(0, "Collection(").append(")") : exp).toString(); this.fullQualifiedName = new FullQualifiedName(namespace, typeName); try { diff --git a/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/EdmImplCachingTest.java b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/EdmImplCachingTest.java index 6d9fbaba7..0c6a15d4c 100644 --- a/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/EdmImplCachingTest.java +++ b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/EdmImplCachingTest.java @@ -65,8 +65,7 @@ public class EdmImplCachingTest { assertEquals(1, schemas.size()); List cachedSchemas = edm.getSchemas(); - assertTrue(schemas == cachedSchemas); - assertEquals(schemas, schemas); + assertEquals(schemas, cachedSchemas); } @Test @@ -421,7 +420,15 @@ public class EdmImplCachingTest { @Override protected Map createSchemas() { - return Collections.singletonMap(StringUtils.EMPTY, mock(EdmSchema.class)); + final EdmSchema schema = mock(EdmSchema.class); + when(schema.getNamespace()).thenReturn(NAME1.getNamespace()); + return new HashMap() { + private static final long serialVersionUID = 3109256773218160485L; + + { + put(StringUtils.EMPTY, schema); + } + }; } @Override diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmBindingTargetImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmBindingTargetImpl.java index 78651bc86..a8bac25d0 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmBindingTargetImpl.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/edm/provider/EdmBindingTargetImpl.java @@ -19,13 +19,10 @@ package org.apache.olingo.server.core.edm.provider; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; import org.apache.olingo.commons.api.edm.Edm; -import org.apache.olingo.commons.api.edm.EdmBindingTarget; import org.apache.olingo.commons.api.edm.EdmEntityContainer; -import org.apache.olingo.commons.api.edm.EdmException; import org.apache.olingo.commons.api.edm.EdmNavigationPropertyBinding; import org.apache.olingo.commons.api.edm.Target; import org.apache.olingo.commons.core.edm.AbstractEdmBindingTarget; @@ -43,42 +40,6 @@ public abstract class EdmBindingTargetImpl extends AbstractEdmBindingTarget { this.target = target; } - @Override - public EdmBindingTarget getRelatedBindingTarget(final String path) { - EdmBindingTarget bindingTarget = null; - - final List navigationPropertyBindings = target.getNavigationPropertyBindings(); - if (navigationPropertyBindings != null) { - boolean found = false; - for (final Iterator itor = navigationPropertyBindings.iterator(); itor.hasNext() - && !found;) { - - final NavigationPropertyBinding binding = itor.next(); - if (binding.getPath().equals(path)) { - final Target providerTarget = binding.getTarget(); - final EdmEntityContainer entityContainer = edm.getEntityContainer(providerTarget.getEntityContainer()); - if (entityContainer == null) { - throw new EdmException("Cant find entity container with name: " + providerTarget.getEntityContainer()); - } - final String targetName = providerTarget.getTargetName(); - bindingTarget = entityContainer.getEntitySet(targetName); - if (bindingTarget == null) { - bindingTarget = entityContainer.getSingleton(targetName); - if (bindingTarget == null) { - throw new EdmException("Cant find target with name: " + targetName); - } - - found = true; - } else { - found = true; - } - } - } - } - - return bindingTarget; - } - @Override public List getNavigationPropertyBindings() { if (navigationPropertyBindings == null) { diff --git a/pom.xml b/pom.xml index 18c133b91..9cadeaf97 100644 --- a/pom.xml +++ b/pom.xml @@ -35,7 +35,7 @@ org.apache apache - 13 + 14 @@ -67,6 +67,7 @@ 1.9 2.4 3.3.2 + 1.8.3 1.1.3 2.0 @@ -74,6 +75,10 @@ 3.0.1 2.7.11 4.0.3.RELEASE + + 1.7 + 3.1.0 + 3.2 4.2.6 2.3.3 @@ -117,6 +122,11 @@ ${commons.logging.version} provided + + commons-beanutils + commons-beanutils-core + ${commons.beanutils.version} + org.antlr @@ -192,6 +202,24 @@ spring-web ${spring.version} + + + + org.apache.velocity + velocity + ${velocity.version} + + + org.apache.maven + maven-plugin-api + ${maven.plugin.api.version} + + + org.apache.maven.plugin-tools + maven-plugin-annotations + ${maven.plugin.tools.version} + + junit