Java Code Examples for org.apache.olingo.odata2.api.annotation.edm.EdmFunctionImport#returnType()

The following examples show how to use org.apache.olingo.odata2.api.annotation.edm.EdmFunctionImport#returnType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JPAEdmFunctionImport.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
private FunctionImport buildEdmFunctionImport(final Method method,
    final EdmFunctionImport edmAnnotationFunctionImport)
    throws ODataJPAModelException {
  if (edmAnnotationFunctionImport != null && edmAnnotationFunctionImport.returnType() != null) {
    FunctionImport functionImport = new FunctionImport();

    if ("".equals(edmAnnotationFunctionImport.name())) {
      functionImport.setName(method.getName());
    } else {
      functionImport.setName(edmAnnotationFunctionImport.name());
    }

    JPAEdmMapping mapping = new JPAEdmMappingImpl();
    ((Mapping) mapping).setInternalName(method.getName());
    mapping.setJPAType(method.getDeclaringClass());
    functionImport.setMapping((Mapping) mapping);

    functionImport.setHttpMethod(edmAnnotationFunctionImport.httpMethod().name().toString());

    buildEdmReturnType(functionImport, method, edmAnnotationFunctionImport);
    buildEdmParameter(functionImport, method);

    return functionImport;
  }
  return null;
}
 
Example 2
Source File: JPAEdmFunctionImport.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private FunctionImport buildFunctionImport(final Method method) throws ODataJPAModelException {

      EdmFunctionImport edmAnnotationFunctionImport = method.getAnnotation(EdmFunctionImport.class);
      if (edmAnnotationFunctionImport != null && edmAnnotationFunctionImport.returnType() != null) {
        return buildEdmFunctionImport(method, edmAnnotationFunctionImport);
      }

      return null;
    }
 
Example 3
Source File: JPAEdmFunctionImport.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
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 ("".equals(entitySet)) {
        throw ODataJPAModelException.throwException(ODataJPAModelException.FUNC_ENTITYSET_EXP, null);
      }
      functionImport.setEntitySet(entitySet);
    }

    Class<?> methodReturnType = method.getReturnType();
    if (methodReturnType == null || "void".equals(methodReturnType.getName())) {
      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 = JPATypeConverter.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);
      }

      complexType = jpaEdmComplexTypeView.searchEdmComplexType(embeddableTypeName);

      if (complexType == null) {// This could occure of non JPA Embeddable Types : Extension Scenario
        List<ComplexType> complexTypeList = schemaView.getEdmSchema().getComplexTypes();
        String[] complexTypeNameParts = embeddableTypeName.split("\\.");
        String complexTypeName = complexTypeNameParts[complexTypeNameParts.length - 1];
        for (ComplexType complexType1 : complexTypeList) {
          if (complexType1.getName().equals(complexTypeName)) {
            complexType = complexType1;
            exists = true;
            break;
          }
        }
        if (exists == false) {
          throw ODataJPAModelException.throwException(ODataJPAModelException.FUNC_RETURN_TYPE_ENTITY_NOT_FOUND
              .addContent(method.getDeclaringClass(), method.getName(), methodReturnType.getSimpleName()), null);
        }
      }
      functionReturnType.setTypeName(JPAEdmNameBuilder.build(schemaView, complexType.getName()));
      break;
    default:
      break;
    }
    functionImport.setReturnType(functionReturnType);
  }
}