Package org.apache.olingo.odata2.api.edm.provider

Examples of org.apache.olingo.odata2.api.edm.provider.FunctionImport


        switch (uriInfo.getUriType()) {
        case URI4:
        case URI5:
            // simple property
            final List<EdmProperty> simplePropertyPath = uriInfo.getPropertyPath();
            final EdmProperty simpleProperty = simplePropertyPath.get(simplePropertyPath.size() - 1);
            responseContentType = simpleProperty.getMimeType();
            if (uriInfo.isValue()) {
                response = EntityProvider.writePropertyValue(simpleProperty, content);
                responseContentType = ContentType.TEXT_PLAIN_CS_UTF_8.toString();
            } else {
                response = EntityProvider.writeProperty(getContentType(), simpleProperty, content);
            }
            break;

        case URI3:
            // complex property
            final List<EdmProperty> complexPropertyPath = uriInfo.getPropertyPath();
            final EdmProperty complexProperty = complexPropertyPath.get(complexPropertyPath.size() - 1);
            response = EntityProvider.writeProperty(responseContentType, complexProperty, content);
            break;

        case URI7A:
            // $links with 0..1 cardinality property
View Full Code Here


    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);
    }
View Full Code Here

      for (EntityContainer container : schema.getEntityContainers()) {
        assertEquals("Container1", container.getName());
        assertEquals(Boolean.TRUE, container.isDefaultEntityContainer());

        assertEquals(4, container.getFunctionImports().size());
        FunctionImport functionImport1 = container.getFunctionImports().get(0);

        assertEquals("EmployeeSearch", functionImport1.getName());
        assertEquals("Employees", functionImport1.getEntitySet());
        assertEquals(NAMESPACE, functionImport1.getReturnType().getTypeName().getNamespace());
        assertEquals("Employee", functionImport1.getReturnType().getTypeName().getName());
        assertEquals(EdmMultiplicity.MANY, functionImport1.getReturnType().getMultiplicity());
        assertEquals("GET", functionImport1.getHttpMethod());
        assertEquals(2, functionImport1.getParameters().size());

        assertEquals("q1", functionImport1.getParameters().get(0).getName());
        assertEquals(EdmSimpleTypeKind.String, functionImport1.getParameters().get(0).getType());
        assertEquals(Boolean.TRUE, functionImport1.getParameters().get(0).getFacets().isNullable());

        assertEquals("q2", functionImport1.getParameters().get(1).getName());
        assertEquals(EdmSimpleTypeKind.Int32, functionImport1.getParameters().get(1).getType());
        assertEquals(Boolean.FALSE, functionImport1.getParameters().get(1).getFacets().isNullable());

        FunctionImport functionImport2 = container.getFunctionImports().get(1);

        assertEquals("RoomSearch", functionImport2.getName());
        assertEquals("Rooms", functionImport2.getEntitySet());
        assertEquals(NAMESPACE, functionImport2.getReturnType().getTypeName().getNamespace());
        assertEquals("Room", functionImport2.getReturnType().getTypeName().getName());
        assertEquals(EdmMultiplicity.MANY, functionImport2.getReturnType().getMultiplicity());
        assertEquals("GET", functionImport2.getHttpMethod());
        assertEquals(2, functionImport2.getParameters().size());

        assertEquals("q1", functionImport2.getParameters().get(0).getName());
        assertEquals(EdmSimpleTypeKind.String, functionImport2.getParameters().get(0).getType());
        assertEquals(Boolean.TRUE, functionImport2.getParameters().get(0).getFacets().isNullable());

        assertEquals("q2", functionImport2.getParameters().get(1).getName());
        assertEquals(EdmSimpleTypeKind.Int32, functionImport2.getParameters().get(1).getType());
        assertEquals(Boolean.FALSE, functionImport2.getParameters().get(1).getFacets().isNullable());

        FunctionImport functionImport3 = container.getFunctionImports().get(2);

        assertEquals("NoParamters", functionImport3.getName());
        List<FunctionImportParameter> parameters3 = functionImport3.getParameters();
        assertNotNull(parameters3);
        assertEquals(0, parameters3.size());

        FunctionImport functionImport4 = container.getFunctionImports().get(3);
        assertEquals("NoReturn", functionImport4.getName());
        List<FunctionImportParameter> parameters4 = functionImport4.getParameters();
        assertNotNull(parameters4);
        assertEquals(0, parameters4.size());
        assertNull(functionImport4.getReturnType());
      }
    }
  }
View Full Code Here

    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);
View Full Code Here

                }
              } else {
                method = methods[i];
              }

              FunctionImport functionImport = buildFunctionImport(method);
              if (functionImport != null) {
                consistentFunctionImportList.add(functionImport);
              }

            } catch (SecurityException e) {
View Full Code Here

    private FunctionImport buildEdmFunctionImport(final Method method,
        final EdmFunctionImport edmAnnotationFunctionImport)
        throws ODataJPAModelException {
      if (edmAnnotationFunctionImport != null && edmAnnotationFunctionImport.returnType() != null) {
        FunctionImport functionImport = new FunctionImport();

        if (edmAnnotationFunctionImport.name().equals("")) {
          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;
View Full Code Here

    if (ENTITY_CONTAINER_1.equals(entityContainer)) {
      if (FUNCTION_IMPORT_1.equals(name)) {
        final List<FunctionImportParameter> parameters = new ArrayList<FunctionImportParameter>();
        parameters.add(new FunctionImportParameter().setName("q").setType(EdmSimpleTypeKind.String)
            .setFacets(new Facets().setNullable(true)));
        return new FunctionImport().setName(name)
            .setReturnType(new ReturnType().setTypeName(ENTITY_TYPE_1_1).setMultiplicity(EdmMultiplicity.MANY))
            .setEntitySet(ENTITY_SET_1_1)
            .setHttpMethod("GET")
            .setParameters(parameters);

      } else if (FUNCTION_IMPORT_2.equals(name)) {
        return new FunctionImport().setName(name)
            .setReturnType(new ReturnType().setTypeName(COMPLEX_TYPE_1).setMultiplicity(EdmMultiplicity.MANY))
            .setHttpMethod("GET");

      } else if (FUNCTION_IMPORT_3.equals(name)) {
        return new FunctionImport().setName(name)
            .setReturnType(
                new ReturnType().setTypeName(EdmSimpleTypeKind.String.getFullQualifiedName()).setMultiplicity(
                    EdmMultiplicity.MANY))
            .setHttpMethod("GET");

      } else if (FUNCTION_IMPORT_4.equals(name)) {
        return new FunctionImport().setName(name)
            .setReturnType(
                new ReturnType().setTypeName(EdmSimpleTypeKind.Int16.getFullQualifiedName()).setMultiplicity(
                    EdmMultiplicity.ONE))
            .setHttpMethod("GET");

      } else if (FUNCTION_IMPORT_5.equals(name)) {
        return new FunctionImport().setName(name)
            .setReturnType(new ReturnType().setTypeName(COMPLEX_TYPE_1).setMultiplicity(EdmMultiplicity.ONE))
            .setHttpMethod("GET");

      } else if (FUNCTION_IMPORT_6.equals(name)) {
        final List<FunctionImportParameter> parameters = new ArrayList<FunctionImportParameter>();
        parameters.add(new FunctionImportParameter().setName("Id").setType(EdmSimpleTypeKind.String)
            .setFacets(new Facets().setNullable(false)));
        return new FunctionImport().setName(name)
            .setReturnType(
                new ReturnType().setTypeName(EdmSimpleTypeKind.Binary.getFullQualifiedName()).setMultiplicity(
                    EdmMultiplicity.ONE))
            .setHttpMethod("GET")
            .setParameters(parameters);

      } else if (FUNCTION_IMPORT_7.equals(name)) {
        return new FunctionImport().setName(name)
            .setReturnType(
                new ReturnType().setTypeName(new FullQualifiedName(NAMESPACE_1, "Employee")).setMultiplicity(
                    EdmMultiplicity.ZERO_TO_ONE))
            .setEntitySet(ENTITY_SET_1_1)
            .setHttpMethod("GET");
View Full Code Here

  }

  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>();

    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")) {
        returnType.setMultiplicity(EdmMultiplicity.MANY);
        returnTypeString = returnTypeString.substring(returnTypeString.indexOf("(") + 1, returnTypeString.length() - 1);
      }
      FullQualifiedName 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;
  }
View Full Code Here

    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);
  }
View Full Code Here

    FullQualifiedName parentAssocFQName = new FullQualifiedName("AssocNs", "AssocNameParent");
    when(edmProvider.getAssociationSet(containerParentName,
        parentAssocFQName, "fooFromParent", "fromParentRole")).thenReturn(parentAssociationSet);
    parentEntityContainer.setAssociationSets(Arrays.asList(parentAssociationSet));

    FunctionImport functionImportFoo = new FunctionImport().setName("foo");
    when(edmProvider.getFunctionImport(containerName, "foo")).thenReturn(functionImportFoo);

    FunctionImport functionImportBar = new FunctionImport().setName("foo");
    when(edmProvider.getFunctionImport(containerName, "foo")).thenReturn(functionImportBar);

    edmEntityContainer = new EdmEntityContainerImplProv(edmImplProv, entityContainerInfo);
  }
View Full Code Here

TOP

Related Classes of org.apache.olingo.odata2.api.edm.provider.FunctionImport

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.