org.apache.olingo.odata2.api.edm.provider.FunctionImport Java Examples
The following examples show how to use
org.apache.olingo.odata2.api.edm.provider.FunctionImport.
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: Sparql.java From DataHubSystem with GNU Affero General Public License v3.0 | 6 votes |
@Override public FunctionImport getFunctionImport() { // Returns the Result Set of the given query as String. ReturnType rt = new ReturnType() .setMultiplicity(EdmMultiplicity.ZERO_TO_ONE) .setTypeName(EdmSimpleTypeKind.String.getFullQualifiedName()); // One required param: the SPARQL query. List<FunctionImportParameter> params = new ArrayList<>(); params.add(new FunctionImportParameter() .setName("query") .setType(EdmSimpleTypeKind.String) .setFacets(new Facets().setNullable(false))); return new FunctionImport() .setName(NAME) .setHttpMethod("GET") .setParameters(params) .setReturnType(rt); }
Example #2
Source File: EdmImplProv.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Override protected List<EdmFunctionImport> createFunctionImports() throws ODataException { List<EdmFunctionImport> edmFunctionImports = new ArrayList<EdmFunctionImport>(); if (schemas == null) { schemas = edmProvider.getSchemas(); } for (Schema schema : schemas) { for (EntityContainer entityContainer : schema.getEntityContainers()) { for (FunctionImport functionImport : entityContainer.getFunctionImports()) { EdmEntityContainer edmEntityContainer = createEntityContainer(entityContainer.getName()); edmFunctionImports.add(new EdmFunctionImportImplProv(this, functionImport, edmEntityContainer)); } } } return edmFunctionImports; }
Example #3
Source File: EdmEntityContainerImplProv.java From olingo-odata2 with Apache License 2.0 | 6 votes |
@Override public EdmFunctionImport getFunctionImport(final String name) throws EdmException { EdmFunctionImport edmFunctionImport = edmFunctionImports.get(name); if (edmFunctionImport != null) { return edmFunctionImport; } FunctionImport functionImport; try { functionImport = edm.edmProvider.getFunctionImport(entityContainerInfo.getName(), name); } catch (ODataException e) { throw new EdmException(EdmException.PROVIDERPROBLEM, e); } if (functionImport != null) { edmFunctionImport = createFunctionImport(functionImport); edmFunctionImports.put(name, edmFunctionImport); } else if (edmExtendedEntityContainer != null) { edmFunctionImport = edmExtendedEntityContainer.getFunctionImport(name); if (edmFunctionImport != null) { edmFunctionImports.put(name, edmFunctionImport); } } return edmFunctionImport; }
Example #4
Source File: XmlMetadataConsumer.java From olingo-odata2 with Apache License 2.0 | 6 votes |
private void validateFunctionImport() throws EntityProviderException { for (FunctionImport functionImport : edmFunctionImportList) { ReturnType returnType = functionImport.getReturnType(); if (returnType != null) { String entitySet = functionImport.getEntitySet(); FullQualifiedName fqn = returnType.getTypeName(); if (returnType.getMultiplicity() == EdmMultiplicity.MANY && entitySet == null && entityTypesMap.get( fqn) != null) { throw new EntityProviderException(EntityProviderException.MISSING_ATTRIBUTE.addContent("EntitySet = " + entitySet, XmlMetadataConstants.EDM_FUNCTION_IMPORT + " = " + functionImport.getName())); } else if (returnType.getMultiplicity() != EdmMultiplicity.MANY && entitySet != null && entityTypesMap.get( fqn) == null) { throw new EntityProviderException(EntityProviderException.INVALID_ATTRIBUTE.addContent("EntitySet = " + entitySet, XmlMetadataConstants.EDM_FUNCTION_IMPORT + " = " + functionImport.getName())); } } } }
Example #5
Source File: JPAEdmFunctionImportTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
/** * Test Case - Function Import test for ReturnType.COMPLEX where Complex type is non JPA Embeddable Type * */ @Test public void testNonJPAReturnTypeComplex() { VARIANT = 18; build(); List<FunctionImport> functionImportList = jpaEdmfunctionImport.getConsistentFunctionImportList(); assertEquals(functionImportList.size(), 1); FunctionImport functionImport = functionImportList.get(0); assertEquals(functionImport.getName(), "method18"); assertNotNull(functionImport.getMapping()); ReturnType returnType = functionImport.getReturnType(); assertNotNull(returnType); assertEquals(EdmMultiplicity.ONE, returnType.getMultiplicity()); assertEquals(returnType.getTypeName().toString(), ODataJPAContextMock.PERSISTENCE_UNIT_NAME + "." + JPACustomProcessorMock.nonJPAEmbeddableType); }
Example #6
Source File: JPAEdmFunctionImportTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
/** * Test Case - Function Import test for default facets */ @Test public void testFunctionImportParamFacetsDefault() { VARIANT = 15; build(); List<FunctionImport> functionImportList = jpaEdmfunctionImport.getConsistentFunctionImportList(); assertEquals(functionImportList.size(), 1); List<FunctionImportParameter> funcImpParamList = functionImportList.get(0).getParameters(); EdmFacets facets = funcImpParamList.get(0).getFacets(); assertNotNull(facets); assertNull(facets.getMaxLength()); assertEquals(true, facets.isNullable()); assertNull(facets.getPrecision()); assertNull(facets.getScale()); }
Example #7
Source File: JPAEdmFunctionImportTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
/** * Test Case - Function Import test for facets */ @Test public void testFunctionImportParamFacets() { VARIANT = 14; build(); List<FunctionImport> functionImportList = jpaEdmfunctionImport.getConsistentFunctionImportList(); assertEquals(functionImportList.size(), 1); List<FunctionImportParameter> funcImpParamList = functionImportList.get(0).getParameters(); EdmFacets facets = funcImpParamList.get(0).getFacets(); assertNotNull(facets); assertEquals(2, facets.getMaxLength().intValue()); assertEquals(true, facets.isNullable()); facets = funcImpParamList.get(1).getFacets(); assertNotNull(facets); assertEquals(true, facets.isNullable()); assertEquals(10, facets.getPrecision().intValue()); assertEquals(2, facets.getScale().intValue()); }
Example #8
Source File: JPAEdmFunctionImportTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
/** * Test Case - Function Import that returns a complex Type with multiplicity * Many */ @Test public void testFunctionImportComplexTypeMany() { VARIANT = 10; build(); List<FunctionImport> functionImportList = jpaEdmfunctionImport.getConsistentFunctionImportList(); assertEquals(functionImportList.size(), 1); FunctionImport functionImport = functionImportList.get(0); assertEquals(functionImport.getName(), "method10"); assertNotNull(functionImport.getMapping()); ReturnType returnType = functionImport.getReturnType(); assertNotNull(returnType); assertEquals(EdmMultiplicity.MANY, returnType.getMultiplicity()); assertEquals(returnType.getTypeName().toString(), ODataJPAContextMock.PERSISTENCE_UNIT_NAME + "." + JPACustomProcessorMock.edmName); }
Example #9
Source File: JPAEdmFunctionImportTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
/** * Test Case - Function Import that returns a complex Type */ @Test public void testFunctionImportComplexType() { VARIANT = 9; build(); List<FunctionImport> functionImportList = jpaEdmfunctionImport.getConsistentFunctionImportList(); assertEquals(functionImportList.size(), 1); FunctionImport functionImport = functionImportList.get(0); assertEquals(functionImport.getName(), "method9"); assertNotNull(functionImport.getMapping()); ReturnType returnType = functionImport.getReturnType(); assertNotNull(returnType); assertEquals(EdmMultiplicity.ONE, returnType.getMultiplicity()); assertEquals(returnType.getTypeName().toString(), ODataJPAContextMock.PERSISTENCE_UNIT_NAME + "." + JPACustomProcessorMock.edmName); }
Example #10
Source File: JPAEdmFunctionImportTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
/** * Test Case - Function Import that returns an Entity Type with Multiplicity * as ONE. -->Positive Case */ @Test public void testFunctionImportEntityTypeSingleReturn() { VARIANT = 7; build(); List<FunctionImport> functionImportList = jpaEdmfunctionImport.getConsistentFunctionImportList(); assertEquals(functionImportList.size(), 1); FunctionImport functionImport = functionImportList.get(0); assertEquals(functionImport.getName(), "method7"); assertNotNull(functionImport.getMapping()); JPAEdmMapping mapping = (JPAEdmMapping) functionImport.getMapping(); assertEquals(JPACustomProcessorMock.class, mapping.getJPAType()); ReturnType returnType = functionImport.getReturnType(); assertNotNull(returnType); assertEquals(EdmMultiplicity.ONE, returnType.getMultiplicity()); assertEquals(returnType.getTypeName().toString(), ODataJPAContextMock.PERSISTENCE_UNIT_NAME + "." + JPACustomProcessorMock.edmName); }
Example #11
Source File: JPAEdmFunctionImportTest.java From olingo-odata2 with Apache License 2.0 | 6 votes |
/** * Test Case - Function Import with no names. Default name is Java method * name. */ @Test public void testFunctionImportNoName() { VARIANT = 3; build(); List<FunctionImport> functionImportList = jpaEdmfunctionImport.getConsistentFunctionImportList(); assertEquals(functionImportList.size(), 1); FunctionImport functionImport = functionImportList.get(0); assertEquals(functionImport.getName(), "method3"); assertNotNull(functionImport.getMapping()); ReturnType returnType = functionImport.getReturnType(); assertNotNull(returnType); assertEquals(EdmMultiplicity.ONE, returnType.getMultiplicity()); assertEquals(returnType.getTypeName().toString(), EdmSimpleTypeKind.Int32.getFullQualifiedName().toString()); }
Example #12
Source File: JPAEdmFunctionImport.java From olingo-odata2 with Apache License 2.0 | 6 votes |
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 #13
Source File: Model.java From DataHubSystem with GNU Affero General Public License v3.0 | 6 votes |
@Override public FunctionImport getFunctionImport(String entity_container, String name) throws ODataException { if (entity_container == null || entity_container.equals(ENTITY_CONTAINER)) { AbstractOperation op = getServiceOperation(name); if (op == null) { return null; } return op.getFunctionImport(); } return null; }
Example #14
Source File: MyEdmProvider.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Override public FunctionImport getFunctionImport(String entityContainer, String name) throws ODataException { if (ENTITY_CONTAINER.equals(entityContainer)) { if (FUNCTION_IMPORT.equals(name)) { return new FunctionImport().setName(name) .setReturnType(new ReturnType().setTypeName(ENTITY_TYPE_1_1).setMultiplicity(EdmMultiplicity.MANY)) .setHttpMethod("GET"); } } return null; }
Example #15
Source File: CarEdmProvider.java From olingo-odata2 with Apache License 2.0 | 5 votes |
@Override public FunctionImport getFunctionImport(final String entityContainer, final String name) throws ODataException { if (ENTITY_CONTAINER.equals(entityContainer)) { if (FUNCTION_IMPORT.equals(name)) { return new FunctionImport().setName(name) .setReturnType(new ReturnType().setTypeName(ENTITY_TYPE_1_1).setMultiplicity(EdmMultiplicity.MANY)) .setHttpMethod("GET"); } } return null; }
Example #16
Source File: EdmFunctionImportImplProvTest.java From olingo-odata2 with Apache License 2.0 | 5 votes |
@BeforeClass public static void getEdmEntityContainerImpl() throws Exception { EdmProvider edmProvider = mock(EdmProvider.class); EdmImplProv edmImplProv = new EdmImplProv(edmProvider); EntityContainerInfo containerInfo = new EntityContainerInfo().setName("Container"); when(edmProvider.getEntityContainerInfo("Container")).thenReturn(containerInfo); edmEntityContainer = new EdmEntityContainerImplProv(edmImplProv, containerInfo); EntitySet fooEntitySet = new EntitySet().setName("fooEntitySet"); when(edmProvider.getEntitySet("Container", "fooEntitySet")).thenReturn(fooEntitySet); ReturnType fooReturnType = new ReturnType().setTypeName(EdmSimpleTypeKind.String.getFullQualifiedName()).setMultiplicity( EdmMultiplicity.ONE); List<FunctionImportParameter> parameters = new ArrayList<FunctionImportParameter>(); FunctionImportParameter parameter = new FunctionImportParameter().setName("fooParameter1").setType(EdmSimpleTypeKind.String); parameters.add(parameter); parameter = new FunctionImportParameter().setName("fooParameter2").setType(EdmSimpleTypeKind.String); parameters.add(parameter); parameter = new FunctionImportParameter().setName("fooParameter3").setType(EdmSimpleTypeKind.String); parameters.add(parameter); FunctionImport functionImportFoo = new FunctionImport().setName("foo").setHttpMethod("GET").setReturnType(fooReturnType).setEntitySet( "fooEntitySet").setParameters(parameters); when(edmProvider.getFunctionImport("Container", "foo")).thenReturn(functionImportFoo); edmFunctionImport = new EdmFunctionImportImplProv(edmImplProv, functionImportFoo, edmEntityContainer); FunctionImport functionImportBar = new FunctionImport().setName("bar").setHttpMethod("GET"); when(edmProvider.getFunctionImport("Container", "bar")).thenReturn(functionImportBar); edmFunctionImportWithoutParameters = new EdmFunctionImportImplProv(edmImplProv, functionImportBar, edmEntityContainer); }
Example #17
Source File: EdmxProvider.java From olingo-odata2 with Apache License 2.0 | 5 votes |
@Override public FunctionImport getFunctionImport(final String entityContainer, final String name) throws ODataException { for (Schema schema : dataServices.getSchemas()) { for (EntityContainer container : schema.getEntityContainers()) { if (container.getName().equals(entityContainer)) { for (FunctionImport function : container.getFunctionImports()) { if (function.getName().equals(name)) { return function; } } } } } return null; }
Example #18
Source File: EdmFunctionImportImplProv.java From olingo-odata2 with Apache License 2.0 | 5 votes |
public EdmFunctionImportImplProv(final EdmImplProv edm, final FunctionImport functionImport, final EdmEntityContainer edmEntityContainer) throws EdmException { super(edm, functionImport.getName()); this.functionImport = functionImport; this.edmEntityContainer = edmEntityContainer; buildFunctionImportParametersInternal(); edmParameters = new HashMap<String, EdmParameter>(); }
Example #19
Source File: AnnotationEdmProvider.java From olingo-odata2 with Apache License 2.0 | 5 votes |
@Override public FunctionImport getFunctionImport(final String entityContainer, final String name) throws ODataException { EntityContainer container = name2Container.get(entityContainer); if (container != null) { List<FunctionImport> functionImports = container.getFunctionImports(); for (FunctionImport functionImport : functionImports) { if (functionImport.getName().equals(name)) { return functionImport; } } } return null; }
Example #20
Source File: AnnotationEdmProviderTest.java From olingo-odata2 with Apache License 2.0 | 5 votes |
@Test public void annotationProviderBasic() throws Exception { assertNotNull(aep); List<Schema> schemas = aep.getSchemas(); assertEquals(1, schemas.size()); EntityContainerInfo info = aep.getEntityContainerInfo(ModelSharedConstants.CONTAINER_1); assertTrue(info.isDefaultEntityContainer()); FunctionImport funImp = aep.getFunctionImport(ModelSharedConstants.CONTAINER_1, "NoImport"); assertNull(funImp); final FullQualifiedName associationFqn = new FullQualifiedName( ModelSharedConstants.NAMESPACE_1, "NoAssociation"); Association noAssociation = aep.getAssociation(associationFqn); assertNull(noAssociation); AssociationSet noAssociationSet = aep.getAssociationSet( ModelSharedConstants.CONTAINER_1, associationFqn, "NoSrc", "NoSrcEntity"); assertNull(noAssociationSet); AssociationSet asBuildingRooms = aep.getAssociationSet( ModelSharedConstants.CONTAINER_1, defaultFqn("BuildingRooms"), "Buildings", "r_Building"); assertNotNull(asBuildingRooms); assertEquals("Buildings", asBuildingRooms.getEnd1().getEntitySet()); assertEquals("r_Building", asBuildingRooms.getEnd1().getRole()); assertEquals("Rooms", asBuildingRooms.getEnd2().getEntitySet()); assertEquals("r_Rooms", asBuildingRooms.getEnd2().getRole()); }
Example #21
Source File: ODataJPAEdmProvider.java From olingo-odata2 with Apache License 2.0 | 5 votes |
public ODataJPAEdmProvider() { entityTypes = new LinkedHashMap<String, EntityType>(); entityContainerInfos = new LinkedHashMap<String, EntityContainerInfo>(); complexTypes = new LinkedHashMap<String, ComplexType>(); associations = new LinkedHashMap<String, Association>(); functionImports = new LinkedHashMap<String, FunctionImport>(); }
Example #22
Source File: ODataJPAEdmProvider.java From olingo-odata2 with Apache License 2.0 | 5 votes |
public ODataJPAEdmProvider(final ODataJPAContext oDataJPAContext) { if (oDataJPAContext == null) { throw new IllegalArgumentException(ODataJPAException.ODATA_JPACTX_NULL); } entityTypes = new LinkedHashMap<String, EntityType>(); entityContainerInfos = new LinkedHashMap<String, EntityContainerInfo>(); complexTypes = new LinkedHashMap<String, ComplexType>(); associations = new LinkedHashMap<String, Association>(); functionImports = new LinkedHashMap<String, FunctionImport>(); jpaEdmModel = ODataJPAFactory.createFactory().getJPAAccessFactory().getJPAEdmModelView(oDataJPAContext); }
Example #23
Source File: JPAEdmFunctionImport.java From olingo-odata2 with Apache License 2.0 | 5 votes |
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 #24
Source File: JPAEdmFunctionImportTest.java From olingo-odata2 with Apache License 2.0 | 5 votes |
/** * Test Case - Function Import Basic test - Positive Case */ @Test public void testFunctionImportBasic() { VARIANT = 0; build(); List<FunctionImport> functionImportList = jpaEdmfunctionImport.getConsistentFunctionImportList(); assertEquals(functionImportList.size(), 1); for (FunctionImport functionImport : functionImportList) { assertEquals(functionImport.getName(), "Method1"); assertNotNull(functionImport.getMapping()); Mapping mapping = new Mapping(); mapping.setInternalName("method1"); assertEquals(mapping.getInternalName(), functionImport.getMapping().getInternalName()); ReturnType returnType = functionImport.getReturnType(); assertNotNull(returnType); assertEquals(EdmMultiplicity.MANY, returnType.getMultiplicity()); List<FunctionImportParameter> funcImpList = functionImport.getParameters(); assertEquals(2, funcImpList.size()); assertEquals("Param1", funcImpList.get(0).getName()); assertEquals(EdmSimpleTypeKind.String, funcImpList.get(0).getType()); assertEquals("Param3", funcImpList.get(1).getName()); assertEquals(EdmSimpleTypeKind.Double, funcImpList.get(1).getType()); } }
Example #25
Source File: JPAEdmFunctionImport.java From olingo-odata2 with Apache License 2.0 | 4 votes |
@Override public List<FunctionImport> getConsistentFunctionImportList() { return consistentFunctionImportList; }
Example #26
Source File: JPAEdmFunctionImport.java From olingo-odata2 with Apache License 2.0 | 4 votes |
private void buildEdmParameter(final FunctionImport functionImport, final Method method) throws ODataJPAModelException { Annotation[][] annotations = method.getParameterAnnotations(); Class<?>[] parameterTypes = method.getParameterTypes(); List<FunctionImportParameter> funcImpList = new ArrayList<FunctionImportParameter>(); JPAEdmMapping mapping = null; int j = 0; for (Annotation[] annotationArr : annotations) { Class<?> parameterType = parameterTypes[j++]; for (Annotation element : annotationArr) { if (element instanceof EdmFunctionImportParameter) { EdmFunctionImportParameter annotation = (EdmFunctionImportParameter) element; FunctionImportParameter functionImportParameter = new FunctionImportParameter(); if ("".equals(annotation.name())) { throw ODataJPAModelException.throwException(ODataJPAModelException.FUNC_PARAM_NAME_EXP.addContent(method .getDeclaringClass().getName(), method.getName()), null); } else { functionImportParameter.setName(annotation.name()); } functionImportParameter.setType(JPATypeConverter.convertToEdmSimpleType(parameterType, null)); Facets facets = new Facets(); if (annotation.facets().maxLength() > 0) { facets.setMaxLength(annotation.facets().maxLength()); } if (annotation.facets().nullable() == false) { facets.setNullable(false); } else { facets.setNullable(true); } if (annotation.facets().precision() > 0) { facets.setPrecision(annotation.facets().precision()); } if (annotation.facets().scale() >= 0) { facets.setScale(annotation.facets().scale()); } functionImportParameter.setFacets(facets); mapping = new JPAEdmMappingImpl(); mapping.setJPAType(parameterType); functionImportParameter.setMapping((Mapping) mapping); funcImpList.add(functionImportParameter); } } } if (!funcImpList.isEmpty()) { functionImport.setParameters(funcImpList); } }
Example #27
Source File: MyEdmProvider.java From wildfly-camel with Apache License 2.0 | 4 votes |
@Override public List<Schema> getSchemas() throws ODataException { List<Schema> schemas = new ArrayList<>(); Schema schema = new Schema(); schema.setNamespace(NAMESPACE); List<EntityType> entityTypes = new ArrayList<>(); entityTypes.add(getEntityType(ENTITY_TYPE_1_1)); entityTypes.add(getEntityType(ENTITY_TYPE_1_2)); schema.setEntityTypes(entityTypes); List<ComplexType> complexTypes = new ArrayList<>(); complexTypes.add(getComplexType(COMPLEX_TYPE)); schema.setComplexTypes(complexTypes); List<Association> associations = new ArrayList<>(); associations.add(getAssociation(ASSOCIATION_CAR_MANUFACTURER)); schema.setAssociations(associations); List<EntityContainer> entityContainers = new ArrayList<>(); EntityContainer entityContainer = new EntityContainer(); entityContainer.setName(ENTITY_CONTAINER).setDefaultEntityContainer(true); List<EntitySet> entitySets = new ArrayList<>(); entitySets.add(getEntitySet(ENTITY_CONTAINER, ENTITY_SET_NAME_CARS)); entitySets.add(getEntitySet(ENTITY_CONTAINER, ENTITY_SET_NAME_MANUFACTURERS)); entityContainer.setEntitySets(entitySets); List<AssociationSet> associationSets = new ArrayList<>(); associationSets.add(getAssociationSet(ENTITY_CONTAINER, ASSOCIATION_CAR_MANUFACTURER, ENTITY_SET_NAME_MANUFACTURERS, ROLE_1_2)); entityContainer.setAssociationSets(associationSets); List<FunctionImport> functionImports = new ArrayList<>(); functionImports.add(getFunctionImport(ENTITY_CONTAINER, FUNCTION_IMPORT)); entityContainer.setFunctionImports(functionImports); entityContainers.add(entityContainer); schema.setEntityContainers(entityContainers); schemas.add(schema); return schemas; }
Example #28
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 #29
Source File: CarEdmProvider.java From olingo-odata2 with Apache License 2.0 | 4 votes |
@Override public List<Schema> getSchemas() throws ODataException { List<Schema> schemas = new ArrayList<Schema>(); Schema schema = new Schema(); schema.setNamespace(NAMESPACE); List<EntityType> entityTypes = new ArrayList<EntityType>(); entityTypes.add(getEntityType(ENTITY_TYPE_1_1)); entityTypes.add(getEntityType(ENTITY_TYPE_1_2)); schema.setEntityTypes(entityTypes); List<ComplexType> complexTypes = new ArrayList<ComplexType>(); complexTypes.add(getComplexType(COMPLEX_TYPE)); schema.setComplexTypes(complexTypes); List<Association> associations = new ArrayList<Association>(); associations.add(getAssociation(ASSOCIATION_CAR_MANUFACTURER)); schema.setAssociations(associations); List<EntityContainer> entityContainers = new ArrayList<EntityContainer>(); EntityContainer entityContainer = new EntityContainer(); entityContainer.setName(ENTITY_CONTAINER).setDefaultEntityContainer(true); List<EntitySet> entitySets = new ArrayList<EntitySet>(); entitySets.add(getEntitySet(ENTITY_CONTAINER, ENTITY_SET_NAME_CARS)); entitySets.add(getEntitySet(ENTITY_CONTAINER, ENTITY_SET_NAME_MANUFACTURERS)); entityContainer.setEntitySets(entitySets); List<AssociationSet> associationSets = new ArrayList<AssociationSet>(); associationSets.add(getAssociationSet(ENTITY_CONTAINER, ASSOCIATION_CAR_MANUFACTURER, ENTITY_SET_NAME_MANUFACTURERS, ROLE_1_2)); entityContainer.setAssociationSets(associationSets); List<FunctionImport> functionImports = new ArrayList<FunctionImport>(); functionImports.add(getFunctionImport(ENTITY_CONTAINER, FUNCTION_IMPORT)); entityContainer.setFunctionImports(functionImports); entityContainers.add(entityContainer); schema.setEntityContainers(entityContainers); schemas.add(schema); return schemas; }
Example #30
Source File: TechnicalScenarioEdmProvider.java From olingo-odata2 with Apache License 2.0 | 4 votes |
@Override public FunctionImport getFunctionImport(final String entityContainer, final String name) throws ODataMessageException { return null; }