}
}
private void buildEdmReturnType(final FunctionImport functionImport, final Method method,
final EdmFunctionImport edmAnnotationFunctionImport) throws ODataJPAModelException {
ReturnType returnType = edmAnnotationFunctionImport.returnType();
if (returnType != null) {
org.apache.olingo.odata2.api.edm.provider.ReturnType functionReturnType =
new org.apache.olingo.odata2.api.edm.provider.ReturnType();
if (returnType.isCollection()) {
functionReturnType.setMultiplicity(EdmMultiplicity.MANY);
} else {
functionReturnType.setMultiplicity(EdmMultiplicity.ONE);
}
if (returnType.type() == ReturnType.Type.ENTITY) {
String entitySet = edmAnnotationFunctionImport.entitySet();
if (entitySet.equals("")) {
throw ODataJPAModelException.throwException(ODataJPAModelException.FUNC_ENTITYSET_EXP, null);
}
functionImport.setEntitySet(entitySet);
}
Class<?> methodReturnType = method.getReturnType();
if (methodReturnType == null || methodReturnType.getName().equals("void")) {
throw ODataJPAModelException.throwException(ODataJPAModelException.FUNC_RETURN_TYPE_EXP.addContent(method
.getDeclaringClass(), method.getName()), null);
}
switch (returnType.type()) {
case ENTITY:
EntityType edmEntityType = null;
if (returnType.isCollection() == false) {
edmEntityType = jpaEdmEntityTypeView.searchEdmEntityType(methodReturnType.getSimpleName());
} else {
edmEntityType = jpaEdmEntityTypeView.searchEdmEntityType(getReturnTypeSimpleName(method));
}
if (edmEntityType == null) {
throw ODataJPAModelException.throwException(ODataJPAModelException.FUNC_RETURN_TYPE_ENTITY_NOT_FOUND
.addContent(method.getDeclaringClass(), method.getName(), methodReturnType.getSimpleName()), null);
}
functionReturnType.setTypeName(JPAEdmNameBuilder.build(schemaView, edmEntityType.getName()));
break;
case SIMPLE:
EdmSimpleTypeKind edmSimpleTypeKind = JPATypeConvertor.convertToEdmSimpleType(methodReturnType, null);
functionReturnType.setTypeName(edmSimpleTypeKind.getFullQualifiedName());
break;
case COMPLEX:
String embeddableTypeName = null;
ComplexType complexType = null;
boolean exists = false;
if (returnType.isCollection() == false) {
embeddableTypeName = methodReturnType.getName();
} else {
embeddableTypeName = getReturnTypeName(method);
}