Java Code Examples for org.apache.olingo.odata2.api.edm.EdmEntityContainer#getFunctionImport()

The following examples show how to use org.apache.olingo.odata2.api.edm.EdmEntityContainer#getFunctionImport() . 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: UriParserImpl.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private void handleNormalInitialSegment() throws UriSyntaxException, UriNotMatchingException, EdmException {
  final Matcher matcher = INITIAL_SEGMENT_PATTERN.matcher(currentPathSegment);
  if (!matcher.matches()) {
    throw new UriNotMatchingException(UriNotMatchingException.MATCHPROBLEM.addContent(currentPathSegment));
  }

  final String entityContainerName = percentDecode(matcher.group(1));
  final String segmentName = percentDecode(matcher.group(2));
  final String keyPredicate = matcher.group(3);
  final String emptyParentheses = matcher.group(4);

  final EdmEntityContainer entityContainer =
      entityContainerName == null ? edm.getDefaultEntityContainer() : edm.getEntityContainer(entityContainerName);
  if (entityContainer == null) {
    throw new UriNotMatchingException(UriNotMatchingException.CONTAINERNOTFOUND.addContent(entityContainerName));
  }
  uriResult.setEntityContainer(entityContainer);

  final EdmEntitySet entitySet = entityContainer.getEntitySet(segmentName);
  if (entitySet != null) {
    uriResult.setStartEntitySet(entitySet);
    handleEntitySet(entitySet, keyPredicate);
  } else {
    final EdmFunctionImport functionImport = entityContainer.getFunctionImport(segmentName);
    if (functionImport == null) {
      throw new UriNotMatchingException(UriNotMatchingException.NOTFOUND.addContent(segmentName));
    }
    uriResult.setFunctionImport(functionImport);
    handleFunctionImport(functionImport, emptyParentheses, keyPredicate);
  }
}
 
Example 2
Source File: XMLMetadataFunctionImportDeserializerTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void testFunctionImportProperty() throws Exception {
  final String xmWithEntityContainer =
      "<edmx:Edmx Version=\"1.0\" xmlns:edmx=\""
          + Edm.NAMESPACE_EDMX_2007_06
          + "\">"
          + "<edmx:DataServices m:DataServiceVersion=\"2.0\" xmlns:m=\""
          + Edm.NAMESPACE_M_2007_08
          + "\">"
          + "<Schema Namespace=\""
          + NAMESPACE
          + "\" xmlns=\""
          + Edm.NAMESPACE_EDM_2008_09
          + "\">"
          + "<EntityType Name= \"Employee\" m:HasStream=\"true\">"
          + "<Key><PropertyRef Name=\"EmployeeId\"/></Key>"
          + "<Property Name=\""
          + propertyNames[0]
          + "\" Type=\"Edm.String\" Nullable=\"false\"/>"
          + "<Property Name=\""
          + propertyNames[1]
          + "\" Type=\"Edm.String\" m:FC_TargetPath=\"SyndicationTitle\"/>"
          + "</EntityType>"
          + "<EntityContainer Name=\"Container1\" m:IsDefaultEntityContainer=\"true\">"
          + "<EntitySet Name=\"Employees\" EntityType=\"RefScenario.Employee\"/>"
          + "<FunctionImport Name=\"GetId\" ReturnType=\"Edm.String\""
          + " m:HttpMethod=\"GET\"/>"
          + "</EntityContainer>" + "</Schema>" + "</edmx:DataServices>" + "</edmx:Edmx>";
  XmlMetadataDeserializer parser = new XmlMetadataDeserializer();
  InputStream reader = createStreamReader(xmWithEntityContainer);
  EdmDataServices result = parser.readMetadata(reader, true);
  for (EdmSchema schema : result.getEdm().getSchemas()) {
    for (EdmEntityContainer container : schema.getEntityContainers()) {
      EdmFunctionImport functionImport4 = container.getFunctionImport("GetId");
      assertEquals("GetId", functionImport4.getName());
      assertNull(functionImport4.getEntitySet());
    }
  }
}
 
Example 3
Source File: XMLMetadataFunctionImportDeserializerTest.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@Test
public void testFunctionImportIn2Containers() throws XMLStreamException, 
EntityProviderException, EdmException, UnsupportedEncodingException {
  final String xmWithEntityContainer =
      "<edmx:Edmx Version=\"1.0\" xmlns:edmx=\""
          + Edm.NAMESPACE_EDMX_2007_06
          + "\">"
          + "<edmx:DataServices m:DataServiceVersion=\"2.0\" xmlns:m=\""
          + Edm.NAMESPACE_M_2007_08
          + "\">"
          + "<Schema Namespace=\""
          + NAMESPACE
          + "\" xmlns=\""
          + Edm.NAMESPACE_EDM_2008_09
          + "\">"
          + "<EntityType Name= \"Employee\" m:HasStream=\"true\">"
          + "<Key><PropertyRef Name=\"EmployeeId\"/></Key>"
          + "<Property Name=\""
          + propertyNames[0]
          + "\" Type=\"Edm.String\" Nullable=\"false\"/>"
          + "<Property Name=\""
          + propertyNames[1]
          + "\" Type=\"Edm.String\" m:FC_TargetPath=\"SyndicationTitle\"/>"
          + "</EntityType>"
          + "<EntityContainer Name=\"Container1\" m:IsDefaultEntityContainer=\"true\">"
          + "<EntitySet Name=\"Employees\" EntityType=\"RefScenario.Employee\"/>"
          + "<FunctionImport Name=\"EmployeeSearch\" ReturnType=\"Collection(RefScenario.Employee)\" " +
          "EntitySet=\"Employees\" m:HttpMethod=\"GET\">"
          + "<Parameter Name=\"q1\" Type=\"Edm.String\" Nullable=\"true\" />"
          + "<Parameter Name=\"q2\" Type=\"Edm.Int32\" Nullable=\"false\" />"
          + "</FunctionImport>"
          + "<FunctionImport Name=\"RoomSearch\" ReturnType=\"Collection(RefScenario.Employee)\" " +
          "EntitySet=\"Employees\" m:HttpMethod=\"GET\">"
          + "<Parameter Name=\"q1\" Type=\"Edm.String\" Nullable=\"true\" Mode=\"In\"/>"
          + "<Parameter Name=\"q2\" Type=\"Edm.Int32\" Nullable=\"false\" />"
          + "</FunctionImport>"
          + "</EntityContainer>" 
          + "<EntityContainer Name=\"Container2\" m:IsDefaultEntityContainer=\"false\">"
          + "<EntitySet Name=\"Employees\" EntityType=\"RefScenario.Employee\"/>"
          + "<FunctionImport Name=\"RoomSearch\" ReturnType=\"Collection(RefScenario.Employee)\" " +
          "EntitySet=\"Employees\" m:HttpMethod=\"GET\">"
          + "<Parameter Name=\"q1\" Type=\"Edm.String\" Nullable=\"true\" Mode=\"In\"/>"
          + "<Parameter Name=\"q2\" Type=\"Edm.Int32\" Nullable=\"false\" />"
          + "</FunctionImport>"
          + "</EntityContainer>" + 
          "</Schema>" + "</edmx:DataServices>" + "</edmx:Edmx>";
  XmlMetadataDeserializer parser = new XmlMetadataDeserializer();
  InputStream reader = createStreamReader(xmWithEntityContainer);
  EdmDataServices result = parser.readMetadata(reader, true);
  for (EdmSchema schema : result.getEdm().getSchemas()) {
    int i = 0;
    for (EdmEntityContainer container : schema.getEntityContainers()) {
      i++;
      assertEquals("Container" + i, container.getName());
      EdmFunctionImport functionImport = null;
      if (container.getName().equals("Container1")) {
        assertEquals(Boolean.TRUE, container.isDefaultEntityContainer());
        functionImport = container.getFunctionImport("EmployeeSearch");
        assertEquals("EmployeeSearch", functionImport.getName());
        checkParameters1(functionImport);
        assertEquals(Boolean.TRUE, container.isDefaultEntityContainer());
        functionImport = container.getFunctionImport("RoomSearch");
        assertEquals("RoomSearch", functionImport.getName());
        checkParameters1(functionImport);
      } else {
        assertEquals(Boolean.FALSE, container.isDefaultEntityContainer());
        functionImport = container.getFunctionImport("RoomSearch");
        assertEquals("RoomSearch", functionImport.getName());
      }
      
    }
  }
}
 
Example 4
Source File: XMLMetadataFunctionImportDeserializerTest.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@Test
public void testFunctionImportEntity() throws Exception {
  final String xmWithEntityContainer =
      "<edmx:Edmx Version=\"1.0\" xmlns:edmx=\""
          + Edm.NAMESPACE_EDMX_2007_06
          + "\">"
          + "<edmx:DataServices m:DataServiceVersion=\"2.0\" xmlns:m=\""
          + Edm.NAMESPACE_M_2007_08
          + "\">"
          + "<Schema Namespace=\""
          + NAMESPACE
          + "\" xmlns=\""
          + Edm.NAMESPACE_EDM_2008_09
          + "\">"
         + "<EntityContainer Name=\"Container1\" m:IsDefaultEntityContainer=\"true\">"
          + "<EntitySet Name=\"Employees\" EntityType=\"RefScenario.Employee\"/>"
          + "<FunctionImport Name=\"EmployeeSearch\" ReturnType=\"RefScenario.Employee\" " +
          "EntitySet=\"Employees\" m:HttpMethod=\"GET\">"
          + "<Parameter Name=\"q1\" Type=\"Edm.String\" Nullable=\"true\" />"
          + "<Parameter Name=\"q2\" Type=\"Edm.Int32\" Nullable=\"false\" />"
          + "</FunctionImport>"
          + "</EntityContainer>" 
          + "<EntityType Name= \"Employee\" m:HasStream=\"true\">"
          + "<Key><PropertyRef Name=\"EmployeeId\"/></Key>"
          + "<Property Name=\""
          + propertyNames[0]
          + "\" Type=\"Edm.String\" Nullable=\"false\"/>"
          + "<Property Name=\""
          + propertyNames[1]
          + "\" Type=\"Edm.String\" m:FC_TargetPath=\"SyndicationTitle\"/>"
          + "</EntityType>"
          + "</Schema>" + "</edmx:DataServices>" + "</edmx:Edmx>";
  XmlMetadataDeserializer parser = new XmlMetadataDeserializer();
  InputStream reader = createStreamReader(xmWithEntityContainer);
  EdmDataServices result = parser.readMetadata(reader, true);
  for (EdmSchema schema : result.getEdm().getSchemas()) {
    for (EdmEntityContainer container : schema.getEntityContainers()) {
      assertEquals("Container1", container.getName());
      assertEquals(Boolean.TRUE, container.isDefaultEntityContainer());

      EdmFunctionImport functionImport1 = container.getFunctionImport("EmployeeSearch");

      assertEquals("EmployeeSearch", functionImport1.getName());
      assertEquals("Employees", functionImport1.getEntitySet().getName());
      assertEquals(EdmMultiplicity.ONE, functionImport1.getReturnType().getMultiplicity());
      assertEquals("GET", functionImport1.getHttpMethod());
    }
  }
}
 
Example 5
Source File: XMLMetadataFunctionImportDeserializerTest.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@Test
public void testFunctionImportEntityOrderChange() throws Exception {
  final String xmWithEntityContainer =
      "<edmx:Edmx Version=\"1.0\" xmlns:edmx=\""
          + Edm.NAMESPACE_EDMX_2007_06
          + "\">"
          + "<edmx:DataServices m:DataServiceVersion=\"2.0\" xmlns:m=\""
          + Edm.NAMESPACE_M_2007_08
          + "\">"
          + "<Schema Namespace=\""
          + NAMESPACE
          + "\" xmlns=\""
          + Edm.NAMESPACE_EDM_2008_09
          + "\">"
          + "<EntityType Name= \"Employee\" m:HasStream=\"true\">"
         + "<Key><PropertyRef Name=\"EmployeeId\"/></Key>"
         + "<Property Name=\""
         + propertyNames[0]
         + "\" Type=\"Edm.String\" Nullable=\"false\"/>"
         + "<Property Name=\""
         + propertyNames[1]
         + "\" Type=\"Edm.String\" m:FC_TargetPath=\"SyndicationTitle\"/>"
         + "</EntityType>"
         + "<EntityContainer Name=\"Container1\" m:IsDefaultEntityContainer=\"true\">"
          + "<EntitySet Name=\"Employees\" EntityType=\"RefScenario.Employee\"/>"
          + "<FunctionImport Name=\"EmployeeSearch\" ReturnType=\"RefScenario.Employee\" " +
          "EntitySet=\"Employees\" m:HttpMethod=\"GET\">"
          + "<Parameter Name=\"q1\" Type=\"Edm.String\" Nullable=\"true\" />"
          + "<Parameter Name=\"q2\" Type=\"Edm.Int32\" Nullable=\"false\" />"
          + "</FunctionImport>"
          + "</EntityContainer>" 
          + "</Schema>" + "</edmx:DataServices>" + "</edmx:Edmx>";
  XmlMetadataDeserializer parser = new XmlMetadataDeserializer();
  InputStream reader = createStreamReader(xmWithEntityContainer);
  EdmDataServices result = parser.readMetadata(reader, true);
  for (EdmSchema schema : result.getEdm().getSchemas()) {
    for (EdmEntityContainer container : schema.getEntityContainers()) {
      assertEquals("Container1", container.getName());
      assertEquals(Boolean.TRUE, container.isDefaultEntityContainer());

      EdmFunctionImport functionImport1 = container.getFunctionImport("EmployeeSearch");

      assertEquals("EmployeeSearch", functionImport1.getName());
      assertEquals("Employees", functionImport1.getEntitySet().getName());
      assertEquals(EdmMultiplicity.ONE, functionImport1.getReturnType().getMultiplicity());
      assertEquals("GET", functionImport1.getHttpMethod());
    }
  }
}
 
Example 6
Source File: XMLMetadataFunctionImportDeserializerTest.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@Test
public void testFunctionImportEntityWithoutEntitySet() throws Exception {
  final String xmWithEntityContainer =
      "<edmx:Edmx Version=\"1.0\" xmlns:edmx=\""
          + Edm.NAMESPACE_EDMX_2007_06
          + "\">"
          + "<edmx:DataServices m:DataServiceVersion=\"2.0\" xmlns:m=\""
          + Edm.NAMESPACE_M_2007_08
          + "\">"
          + "<Schema Namespace=\""
          + NAMESPACE
          + "\" xmlns=\""
          + Edm.NAMESPACE_EDM_2008_09
          + "\">"
          + "<EntityType Name= \"Employee\" m:HasStream=\"true\">"
          + "<Key><PropertyRef Name=\"EmployeeId\"/></Key>"
          + "<Property Name=\""
          + propertyNames[0]
          + "\" Type=\"Edm.String\" Nullable=\"false\"/>"
          + "<Property Name=\""
          + propertyNames[1]
          + "\" Type=\"Edm.String\" m:FC_TargetPath=\"SyndicationTitle\"/>"
          + "</EntityType>"
          + "<EntityContainer Name=\"Container1\" m:IsDefaultEntityContainer=\"true\">"
          + "<EntitySet Name=\"Employees\" EntityType=\"RefScenario.Employee\"/>"
          + "<FunctionImport Name=\"EmployeeSearch\" ReturnType=\"RefScenario.Employee\" " +
          " m:HttpMethod=\"GET\">"
          + "<Parameter Name=\"q1\" Type=\"Edm.String\" Nullable=\"true\" />"
          + "<Parameter Name=\"q2\" Type=\"Edm.Int32\" Nullable=\"false\" />"
          + "</FunctionImport>"
          + "</EntityContainer>" + "</Schema>" + "</edmx:DataServices>" + "</edmx:Edmx>";
  XmlMetadataDeserializer parser = new XmlMetadataDeserializer();
  InputStream reader = createStreamReader(xmWithEntityContainer);
  EdmDataServices result = parser.readMetadata(reader, true);
  for (EdmSchema schema : result.getEdm().getSchemas()) {
    for (EdmEntityContainer container : schema.getEntityContainers()) {
      assertEquals("Container1", container.getName());
      EdmFunctionImport functionImport1 = container.getFunctionImport("EmployeeSearch");

      assertEquals("EmployeeSearch", functionImport1.getName());
      assertNull(functionImport1.getEntitySet());
      assertEquals("GET", functionImport1.getHttpMethod());
    }
  }
}
 
Example 7
Source File: XMLMetadataFunctionImportDeserializerTest.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@Test
public void testFunctionImportCollection() throws Exception {
  final String xmWithEntityContainer =
      "<edmx:Edmx Version=\"1.0\" xmlns:edmx=\""
          + Edm.NAMESPACE_EDMX_2007_06
          + "\">"
          + "<edmx:DataServices m:DataServiceVersion=\"2.0\" xmlns:m=\""
          + Edm.NAMESPACE_M_2007_08
          + "\">"
          + "<Schema Namespace=\""
          + NAMESPACE
          + "\" xmlns=\""
          + Edm.NAMESPACE_EDM_2008_09
          + "\">"
          + "<EntityType Name= \"Room\" >"
          + "<Key><PropertyRef Name=\"RoomId\"/></Key>"
          + "<Property Name=\""
          + "RoomId"
          + "\" Type=\"Edm.String\" Nullable=\"false\"/>"
          + "<Property Name=\""
          + propertyNames[2]
          + "\" Type=\"Edm.String\" />"
          + "</EntityType>"
          + "<EntityContainer Name=\"Container1\" m:IsDefaultEntityContainer=\"true\">"
          + "<EntitySet Name=\"Rooms\" EntityType=\"RefScenario.Room\"/>"
          + "<FunctionImport Name=\"LocationSearch\" ReturnType=\"Collection(RefScenario.Location)\" " +
          " m:HttpMethod=\"GET\">"
          + "<Parameter Name=\"q1\" Type=\"Edm.String\" Nullable=\"true\" Mode=\"In\"/>"
          + "<Parameter Name=\"q2\" Type=\"Edm.Int32\" Nullable=\"false\" />"
          + "</FunctionImport>"
          + "</EntityContainer>" + "</Schema>" + "</edmx:DataServices>" + "</edmx:Edmx>";
  XmlMetadataDeserializer parser = new XmlMetadataDeserializer();
  InputStream reader = createStreamReader(xmWithEntityContainer);
  EdmDataServices result = parser.readMetadata(reader, true);
  for (EdmSchema schema : result.getEdm().getSchemas()) {
    for (EdmEntityContainer container : schema.getEntityContainers()) {
      assertEquals("Container1", container.getName());
      assertEquals(Boolean.TRUE, container.isDefaultEntityContainer());

      EdmFunctionImport functionImport2 = container.getFunctionImport("LocationSearch");
      assertEquals("LocationSearch", functionImport2.getName());
      assertNull(functionImport2.getEntitySet());
      assertEquals(EdmMultiplicity.MANY, functionImport2.getReturnType().getMultiplicity());
      assertEquals("GET", functionImport2.getHttpMethod());
      assertEquals(EdmMultiplicity.MANY, functionImport2.getReturnType().getMultiplicity());
    }
  }
}
 
Example 8
Source File: XMLMetadataFunctionImportDeserializerTest.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@Test
public void testFunctionImportWithAnnotations() throws XMLStreamException, 
EntityProviderException, EdmException, UnsupportedEncodingException {
  final String xmWithEntityContainer =
      "<edmx:Edmx Version=\"1.0\" xmlns:edmx=\""
          + Edm.NAMESPACE_EDMX_2007_06 
          + "\" xmlns:sap=\"http://www.sap.com/Protocols/SAPData\">"
          + "<edmx:DataServices m:DataServiceVersion=\"2.0\" xmlns:m=\""
          + Edm.NAMESPACE_M_2007_08
          + "\">"
          + "<Schema Namespace=\""
          + NAMESPACE
          + "\" xmlns=\""
          + Edm.NAMESPACE_EDM_2008_09
          + "\">"
          + "<EntityType Name= \"Employee\" m:HasStream=\"true\">"
          + "<Key><PropertyRef Name=\"EmployeeId\"/></Key>"
          + "<Property Name=\""
          + propertyNames[0]
          + "\" Type=\"Edm.String\" Nullable=\"false\"/>"
          + "<Property Name=\""
          + propertyNames[1]
          + "\" Type=\"Edm.String\" m:FC_TargetPath=\"SyndicationTitle\"/>"
          + "</EntityType>"
          + "<EntityContainer Name=\"Container1\" m:IsDefaultEntityContainer=\"true\">"
          + "<EntitySet Name=\"Employees\" EntityType=\"RefScenario.Employee\"/>"
          + "<FunctionImport Name=\"EmployeeSearch\" ReturnType=\"Collection(RefScenario.Employee)\" " 
          + "EntitySet=\"Employees\" m:HttpMethod=\"GET\" sap:label=\"Approve\" "
          + "sap:action-for=\"RefScenario.LeaveRequest\" sap:applicable-path=\"ControlData/NeedsApproval\">"
          + "<Parameter Name=\"q1\" Type=\"Edm.String\" Nullable=\"true\" />"
          + "<Parameter Name=\"q2\" Type=\"Edm.Int32\" Nullable=\"false\" >"
          + "<sap:value-constraint set=\"Employees\">"
          + "<sap:parameter-ref name=\"EmployeeId\" />"
          + "</sap:value-constraint>"
          + "</Parameter>"
          + "</FunctionImport>"
          + "</EntityContainer>" + "</Schema>" + "</edmx:DataServices>" + "</edmx:Edmx>";
  XmlMetadataDeserializer parser = new XmlMetadataDeserializer();
  InputStream reader = createStreamReader(xmWithEntityContainer);
  EdmDataServices result = parser.readMetadata(reader, true);
  for (EdmSchema schema : result.getEdm().getSchemas()) {
    for (EdmEntityContainer container : schema.getEntityContainers()) {
      assertEquals("Container1", container.getName());
      assertEquals(Boolean.TRUE, container.isDefaultEntityContainer());

      EdmFunctionImport functionImport1 = container.getFunctionImport("EmployeeSearch");

      assertEquals("EmployeeSearch", functionImport1.getName());
      checkParametersWithAnnotations(functionImport1);
    }
  }
}