Java Code Examples for org.apache.olingo.odata2.api.edm.provider.FunctionImport#setEntitySet()
The following examples show how to use
org.apache.olingo.odata2.api.edm.provider.FunctionImport#setEntitySet() .
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 | 4 votes |
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); } }
Example 2
Source File: XmlMetadataConsumer.java From olingo-odata2 with Apache License 2.0 | 4 votes |
private FunctionImport readFunctionImport(final XMLStreamReader reader) throws XMLStreamException, EntityProviderException { reader.require(XMLStreamConstants.START_ELEMENT, edmNamespace, XmlMetadataConstants.EDM_FUNCTION_IMPORT); FunctionImport function = new FunctionImport(); List<FunctionImportParameter> functionParameters = new ArrayList<FunctionImportParameter>(); List<AnnotationElement> annotationElements = new ArrayList<AnnotationElement>(); FullQualifiedName fqName; function.setName(reader.getAttributeValue(null, XmlMetadataConstants.EDM_NAME)); function.setHttpMethod(reader.getAttributeValue(Edm.NAMESPACE_M_2007_08, XmlMetadataConstants.EDM_FUNCTION_IMPORT_HTTP_METHOD)); function.setEntitySet(reader.getAttributeValue(null, XmlMetadataConstants.EDM_ENTITY_SET)); String returnTypeString = reader.getAttributeValue(null, XmlMetadataConstants.EDM_FUNCTION_IMPORT_RETURN); if (returnTypeString != null) { ReturnType returnType = new ReturnType(); if (returnTypeString.startsWith("Collection") || returnTypeString.startsWith("collection")) { returnTypeString = returnTypeString.substring(returnTypeString.indexOf("(") + 1, returnTypeString.length() - 1); returnType.setMultiplicity(EdmMultiplicity.MANY); } else { returnType.setMultiplicity(EdmMultiplicity.ONE); } fqName = extractFQName(returnTypeString); returnType.setTypeName(fqName); function.setReturnType(returnType); } function.setAnnotationAttributes(readAnnotationAttribute(reader)); while (reader.hasNext() && !(reader.isEndElement() && edmNamespace.equals(reader.getNamespaceURI()) && XmlMetadataConstants.EDM_FUNCTION_IMPORT.equals(reader.getLocalName()))) { reader.next(); if (reader.isStartElement()) { extractNamespaces(reader); currentHandledStartTagName = reader.getLocalName(); if (XmlMetadataConstants.EDM_FUNCTION_PARAMETER.equals(currentHandledStartTagName)) { functionParameters.add(readFunctionImportParameter(reader)); } else { annotationElements.add(readAnnotationElement(reader)); } } } if (!annotationElements.isEmpty()) { function.setAnnotationElements(annotationElements); } function.setParameters(functionParameters); return function; }