org.apache.olingo.odata2.api.edm.provider.EntityType Java Examples

The following examples show how to use org.apache.olingo.odata2.api.edm.provider.EntityType. 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: XmlMetadataConsumerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test()
public void testAlias() throws XMLStreamException, EntityProviderException {
  final String xml =
      "<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 + "\" Alias=\"RS\"  xmlns=\"" + Edm.NAMESPACE_EDM_2008_09 + "\">"
          + "<EntityType Name= \"Employee\">" + "<Key><PropertyRef Name=\"EmployeeId\"/></Key>" + "<Property Name=\""
          + propertyNames[0] + "\" Type=\"Edm.String\" Nullable=\"false\"/>" + "</EntityType>"
          + "<EntityType Name=\"Manager\" BaseType=\"RS.Employee\" m:HasStream=\"true\">" + "</EntityType>"
          + "</Schema>" + "</edmx:DataServices>" + "</edmx:Edmx>";
  XmlMetadataConsumer parser = new XmlMetadataConsumer();
  XMLStreamReader reader = createStreamReader(xml);
  DataServices result = parser.readMetadata(reader, true);
  for (Schema schema : result.getSchemas()) {
    assertEquals("RS", schema.getAlias());
    for (EntityType entityType : schema.getEntityTypes()) {
      if ("Manager".equals(entityType.getName())) {
        assertEquals("Employee", entityType.getBaseType().getName());
        assertEquals("RS", entityType.getBaseType().getNamespace());
      }
    }

  }
}
 
Example #2
Source File: ServiceDocumentProducerTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Before
public void before() throws ODataException {
  EdmProvider edmProvider = mock(EdmProvider.class);

  EntityType entityType = new EntityType().setName("EntityType1");
  when(edmProvider.getEntityType(new FullQualifiedName("EntityType1Ns", "EntityType1"))).thenReturn(entityType);

  ComplexType complexType = new ComplexType().setName("ComplexType1");
  when(edmProvider.getComplexType(new FullQualifiedName("ComplexType1Ns", "ComplexType1"))).thenReturn(complexType);

  Association association = new Association().setName("Association1");
  when(edmProvider.getAssociation(new FullQualifiedName("Association1Ns", "Association1"))).thenReturn(association);

  EntityContainerInfo defaultEntityContainer = new EntityContainerInfo().setName("Container1");
  when(edmProvider.getEntityContainerInfo(null)).thenReturn(defaultEntityContainer);
  when(edmProvider.getEntityContainerInfo("Container1")).thenReturn(defaultEntityContainer);

  edm = new EdmImplProv(edmProvider);

}
 
Example #3
Source File: EdmxProviderTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void testEntityType() throws Exception {
  Edm edm = createEdm();

  assertNotNull(edm);
  FullQualifiedName fqNameEmployee = new FullQualifiedName("RefScenario", "Employee");
  EdmProvider testProvider = new EdmTestProvider();
  EdmImplProv edmImpl = (EdmImplProv) edm;
  EntityType employee = edmImpl.getEdmProvider().getEntityType(fqNameEmployee);
  EntityType testEmployee = testProvider.getEntityType(fqNameEmployee);
  assertEquals(testEmployee.getName(), employee.getName());
  assertEquals(testEmployee.isHasStream(), employee.isHasStream());
  assertEquals(testEmployee.getProperties().size(), employee.getProperties().size());
  assertEquals(testEmployee.getNavigationProperties().size(), employee.getNavigationProperties().size());

}
 
Example #4
Source File: AnnotationEdmProvider.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
public EntityType buildEntityType() {
  EntityType entityType = new EntityType();
  if (baseEntityType != null) {
    entityType.setBaseType(baseEntityType);
  }
  if (!keyProperties.isEmpty()) {
    entityType.setKey(new Key().setKeys(keyProperties));
  }
  if (!navProperties.isEmpty()) {
    entityType.setNavigationProperties(navProperties);
  }
  return entityType.setName(name)
      .setAbstract(isAbstract)
      .setHasStream(isMediaResource)
      .setProperties(properties)
      .setMapping(new Mapping().setMediaResourceMimeTypeKey(mediaResourceMimeTypeKey)
                                .setMediaResourceSourceKey(mediaResourceSourceKey));
}
 
Example #5
Source File: AnnotationEdmProviderTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void loadAnnotatedClassesFromPackage() throws Exception {
  AnnotationEdmProvider localAep = new AnnotationEdmProvider(TEST_MODEL_PACKAGE);

  // validate employee
  EntityType employee = localAep.getEntityType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "Employee"));
  assertEquals("Employee", employee.getName());
  final List<PropertyRef> employeeKeys = employee.getKey().getKeys();
  assertEquals(1, employeeKeys.size());
  assertEquals("EmployeeId", employeeKeys.get(0).getName());
  assertEquals(6, employee.getProperties().size());
  assertEquals(3, employee.getNavigationProperties().size());

  List<Schema> schemas = localAep.getSchemas();
  assertEquals(1, schemas.size());
  EntityContainerInfo info = localAep.getEntityContainerInfo(ModelSharedConstants.CONTAINER_1);
  assertTrue(info.isDefaultEntityContainer());
}
 
Example #6
Source File: AnnotationEdmProviderTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void facetsTest() throws Exception {
  EntityType employee = aep.getEntityType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "Employee"));
  assertEquals("Employee", employee.getName());
  Property name = getProperty(employee, "EmployeeName");
  assertEquals(Integer.valueOf(20), name.getFacets().getMaxLength());
  assertNull(name.getFacets().getConcurrencyMode());
  assertTrue(name.getFacets().isNullable());
  Property id = getProperty(employee, "EmployeeId");
  assertFalse(id.getFacets().isNullable());

  ComplexType city = aep.getComplexType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "c_City"));
  Property postalCode = getProperty(city.getProperties(), "PostalCode");
  assertEquals(Integer.valueOf(5), postalCode.getFacets().getMaxLength());

  EntityType room = aep.getEntityType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "Room"));
  Property version = getProperty(room, "Version");
  assertEquals(Integer.valueOf(0), version.getFacets().getScale());
  assertEquals(Integer.valueOf(0), version.getFacets().getPrecision());
  assertEquals(EdmConcurrencyMode.Fixed, version.getFacets().getConcurrencyMode());
}
 
Example #7
Source File: AnnotationEdmProviderTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void entityTypeAbstractBaseType() throws Exception {
  // validate employee
  EntityType baseType = aep.getEntityType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "Base"));
  assertEquals("Base", baseType.getName());
  final List<PropertyRef> keys = baseType.getKey().getKeys();
  assertEquals(1, keys.size());
  assertEquals("Id", keys.get(0).getName());
  assertEquals(2, baseType.getProperties().size());
  assertTrue(baseType.isAbstract());

  // validate base for team
  EntityType team = aep.getEntityType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "Team"));
  assertEquals("Team", team.getName());
  assertEquals("Base", team.getBaseType().getName());
  assertEquals(ModelSharedConstants.NAMESPACE_1, team.getBaseType().getNamespace());
}
 
Example #8
Source File: AnnotationEdmProviderTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void complexTypeLocation() throws Exception {
  // validate employee
  EntityType employee = aep.getEntityType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "Employee"));
  final List<Property> properties = employee.getProperties();
  Property location = null;
  for (Property property : properties) {
    if (property.getName().equals("Location")) {
      location = property;
    }
  }
  assertNotNull(location);
  assertEquals("Location", location.getName());

  // validate location complex type
  ComplexType locationType = aep.getComplexType(
      new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "c_Location"));
  assertEquals("c_Location", locationType.getName());
  assertEquals(2, locationType.getProperties().size());
  assertEquals(false, location.getFacets().isNullable());
}
 
Example #9
Source File: AnnotationEdmProviderTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Test
public void entityTypeRoomWithNavigation() throws Exception {
  // validate employee
  EntityType room = aep.getEntityType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "Room"));
  assertEquals("Room", room.getName());
  assertEquals("Base", room.getBaseType().getName());
  assertEquals(2, room.getProperties().size());
  final List<NavigationProperty> navigationProperties = room.getNavigationProperties();
  assertEquals(2, navigationProperties.size());

  for (NavigationProperty navigationProperty : navigationProperties) {
    if (navigationProperty.getName().equals("nr_Employees")) {
      validateNavProperty(navigationProperty, "r_Employees_2_r_Room", "r_Room", "r_Employees");
    } else if (navigationProperty.getName().equals("nr_Building")) {
      validateNavProperty(navigationProperty, "BuildingRooms", "r_Rooms", "r_Building");
    } else {
      fail("Got unexpected navigation property with name '" + navigationProperty.getName() + "'.");
    }
  }
}
 
Example #10
Source File: XmlMetadataConsumer.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
private void validateEntityTypes() throws EntityProviderException {
  for (Map.Entry<FullQualifiedName, EntityType> entityTypes : entityTypesMap.entrySet()) {
    if (entityTypes.getValue() != null && entityTypes.getKey() != null) {
      EntityType entityType = entityTypes.getValue();
      if (entityType.getBaseType() != null) {
        FullQualifiedName baseTypeFQName = entityType.getBaseType();
        EntityType baseEntityType;
        if (!entityTypesMap.containsKey(baseTypeFQName)) {
          FullQualifiedName fqName = validateEntityTypeWithAlias(baseTypeFQName);
          baseEntityType = entityTypesMap.get(fqName);
        } else {
          baseEntityType = fetchLastBaseType(baseTypeFQName,entityTypesMap);
        }
        if (baseEntityType != null && baseEntityType.getKey() == null) {
          throw new EntityProviderException(EntityProviderException.ILLEGAL_ARGUMENT
              .addContent("Missing key for EntityType " + baseEntityType.getName()));
        }
      } else if (entityType.getKey() == null) {
        throw new EntityProviderException(EntityProviderException.ILLEGAL_ARGUMENT
            .addContent("Missing key for EntityType " + entityType.getName()));
      }
    }
  }
}
 
Example #11
Source File: EdmNavigationPropertyImplProvTest.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setup() throws Exception {

  edmProvider = mock(EdmProvider.class);
  EdmImplProv edmImplProv = new EdmImplProv(edmProvider);

  FullQualifiedName relationship = new FullQualifiedName("namespace", "associationName");
  Association association = new Association().setName("associationName");
  when(edmProvider.getAssociation(relationship)).thenReturn(association);

  AssociationEnd end1 = new AssociationEnd().setRole("fromRole");
  FullQualifiedName entityName = new FullQualifiedName("namespace", "entityName");
  AssociationEnd end2 =
      new AssociationEnd().setRole("toRole").setMultiplicity(EdmMultiplicity.ONE).setType(entityName);
  association.setEnd1(end1).setEnd2(end2);

  EntityType entityType = new EntityType().setName("entityName");
  when(edmProvider.getEntityType(entityName)).thenReturn(entityType);

  NavigationProperty navProperty =
      new NavigationProperty().setName("navProperty").setFromRole("fromRole").setToRole("toRole").setRelationship(
          relationship);
  navPropertyProvider = new EdmNavigationPropertyImplProv(edmImplProv, navProperty);
}
 
Example #12
Source File: JPAEdmNameBuilder.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
public static void build(final JPAEdmEntityTypeView view) {

    EntityType edmEntityType = view.getEdmEntityType();
    String jpaEntityName = view.getJPAEntityType().getName();
    JPAEdmMappingModelAccess mappingModelAccess = view.getJPAEdmMappingModelAccess();
    String edmEntityTypeName = null;
    if (mappingModelAccess != null && mappingModelAccess.isMappingModelExists()) {
      edmEntityTypeName = mappingModelAccess.mapJPAEntityType(jpaEntityName);
    }

    JPAEdmMapping mapping = new JPAEdmMappingImpl();
    mapping.setJPAType(view.getJPAEntityType().getJavaType());

    if (edmEntityTypeName == null) {
      edmEntityTypeName = jpaEntityName;
    }
    // Setting the mapping object
    edmEntityType.setMapping(((Mapping) mapping).setInternalName(jpaEntityName));

    edmEntityType.setName(edmEntityTypeName);

  }
 
Example #13
Source File: ClassEntitySet.java    From DataHubSystem with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public EntityType getEntityType ()
{
   List<Property> properties = new ArrayList<Property> ();
   properties.add (new SimpleProperty ()
   .setName (ID)
   .setType (EdmSimpleTypeKind.String)
   .setFacets (new Facets ().setNullable (false))
   .setCustomizableFeedMappings (
      new CustomizableFeedMappings ()
         .setFcTargetPath (EdmTargetPath.SYNDICATION_TITLE)));
   
   properties.add (new SimpleProperty ().setName (URI).setType (
      EdmSimpleTypeKind.String));
  
   // Navigation Properties
   List<NavigationProperty> navigationProperties =
      new ArrayList<NavigationProperty> ();
   // TODO (OData v3) setContainsTarget(true)
   navigationProperties.add (new NavigationProperty ().setName (getName ())
      .setRelationship (ASSO_CLASS_CLASS).setFromRole (ROLE_CLASS_PARENT)
      .setToRole (ROLE_CLASS_CLASSES));

   // Key
   Key key =
      new Key ().setKeys (Collections.singletonList (new PropertyRef ()
         .setName (ID)));

   return new EntityType ().setName (ENTITY_NAME).setProperties (properties)
      .setKey (key).setNavigationProperties (navigationProperties);
}
 
Example #14
Source File: SystemRoleEntitySet.java    From DataHubSystem with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public EntityType getEntityType ()
{
   Key key = new Key ();
   List<PropertyRef> property_refs =
         Collections.singletonList (new PropertyRef ().setName (NAME));
   key.setKeys (property_refs);

   SimpleProperty name = new SimpleProperty ();
   name.setName (NAME);
   name.setType (EdmSimpleTypeKind.String);
   name.setFacets (new Facets ().setNullable (false));
   name.setCustomizableFeedMappings (new CustomizableFeedMappings ()
         .setFcTargetPath (EdmTargetPath.SYNDICATION_TITLE));

   SimpleProperty description = new SimpleProperty ();
   description.setName (DESCRIPTION);
   description.setType (EdmSimpleTypeKind.String);
   description.setFacets (new Facets ().setNullable (false));

   List<Property> properties = new ArrayList<> ();
   properties.add (name);
   properties.add (description);

   EntityType entityType = new EntityType ();
   entityType.setName (ENTITY_NAME);
   entityType.setProperties (properties);
   entityType.setKey (key);

   return entityType;
}
 
Example #15
Source File: AnnotationEdmProviderTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void entityTypeTeam() throws Exception {
  // validate team
  EntityType team = aep.getEntityType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "Team"));
  assertEquals("Team", team.getName());
  assertEquals("Base", team.getBaseType().getName());
  assertEquals(ModelSharedConstants.NAMESPACE_1, team.getBaseType().getNamespace());

  assertEquals(1, team.getProperties().size());
  assertEquals(2, team.getNavigationProperties().size());
  NavigationProperty navPropTeamEmployess = team.getNavigationProperties().get(0);
  validateNavProperty(navPropTeamEmployess, "TeamEmployees", "r_Team", "r_Employees");
  NavigationProperty navPropTeamTeam = team.getNavigationProperties().get(1);
  validateNavProperty(navPropTeamTeam, "Team_2_r_SubTeam", "Team", "r_SubTeam");
}
 
Example #16
Source File: AnnotationEdmProviderTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void entityTypePhotoWithTwoKeyProperties() throws Exception {
  // validate team
  EntityType photo = aep.getEntityType(new FullQualifiedName(ModelSharedConstants.NAMESPACE_1, "Photo"));
  assertEquals("Photo", photo.getName());
  final List<Property> properties = photo.getProperties();
  assertEquals(5, properties.size());
  assertTrue(containsProperty(properties, "Name"));
  assertTrue(containsProperty(properties, "ImageFormat"));
  assertTrue(containsProperty(properties, "MimeType"));
  assertTrue(containsProperty(properties, "ImageUrl"));
  assertTrue(containsProperty(properties, "Image"));
  assertFalse(photo.isAbstract());
  assertTrue(photo.isHasStream());
  assertEquals("MimeType",photo.getMapping().getMediaResourceMimeTypeKey());
  assertEquals("ImageUrl",photo.getMapping().getMediaResourceSourceKey());

  Key photoKey = photo.getKey();
  List<PropertyRef> keyReferences = photoKey.getKeys();
  assertEquals(2, keyReferences.size());
  PropertyRef name = getPropertyRef(keyReferences, "Name");
  assertEquals("Name", name.getName());
  PropertyRef imageFormat = getPropertyRef(keyReferences, "ImageFormat");
  assertEquals("ImageFormat", imageFormat.getName());

  // assertEquals(0, photo.getNavigationProperties().size());
  assertNull(photo.getNavigationProperties());
}
 
Example #17
Source File: NodeEntitySet.java    From DataHubSystem with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public EntityType getEntityType ()
{
   EntityType res = Model.ITEM.getEntityType();

   res.getProperties ().add (
      new SimpleProperty ().setName (CHILDREN_NUMBER).setType (
         EdmSimpleTypeKind.Int64));
   res.getProperties ().add (
      new SimpleProperty ().setName (VALUE).setType (
         EdmSimpleTypeKind.String));

   // Navigation Properties
   List<NavigationProperty> navigationProperties =
      new ArrayList<NavigationProperty> ();
   // TODO (OData v3) setContainsTarget(true)
   navigationProperties.add (new NavigationProperty ().setName (getName ())
      .setRelationship (ASSO_NODE_NODE).setFromRole (ROLE_NODE_PARENT)
      .setToRole (ROLE_NODE_NODES));
   navigationProperties.add (new NavigationProperty ()
      .setName(Model.ATTRIBUTE.getName())
      .setRelationship (ASSO_NODE_ATTRIBUTE)
      .setFromRole (ROLE_ATTRIBUTE_NODE).setToRole (ROLE_NODE_ATTRIBUTES));
   navigationProperties.add (new NavigationProperty ()
      .setName ("Class")
      .setRelationship (ASSO_NODE_CLASS)
      .setFromRole (ROLE_CLASS_NODES)
      .setToRole (ROLE_NODE_CLASS));

   // TODO (OData v3) setAbstract(true) setBaseType(ENTITY_ITEM)
   return res.setName (ENTITY_NAME)
      .setNavigationProperties (navigationProperties).setHasStream (true);
}
 
Example #18
Source File: NetworkStatisticEntitySet.java    From DataHubSystem with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public EntityType getEntityType ()
{
   // Properties
   List<Property> properties = new ArrayList<Property> ();

   properties.add (new SimpleProperty ()
   .setName (ID)
   .setType (EdmSimpleTypeKind.Int64)
   .setFacets (new Facets ().setNullable (false))
   .setCustomizableFeedMappings (
      new CustomizableFeedMappings ()
         .setFcTargetPath (EdmTargetPath.SYNDICATION_TITLE)));

   properties.add (new SimpleProperty ()
      .setName (ACTIVITYPERIOD)
      .setType (EdmSimpleTypeKind.Int64));

   properties.add (new SimpleProperty ()
      .setName (CONNECTIONNUMBER)
      .setType (EdmSimpleTypeKind.Int64));
   // Key
   Key key =
      new Key ().setKeys (Collections.singletonList (new PropertyRef ()
         .setName (ID)));

   return new EntityType ().setName (ENTITY_NAME).setProperties (properties)
      .setKey (key);
}
 
Example #19
Source File: RestrictionEntitySet.java    From DataHubSystem with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public EntityType getEntityType ()
{
   List<Property> properties = new ArrayList<> ();

   SimpleProperty uuid = new SimpleProperty ();
   uuid.setName (UUID);
   uuid.setType (EdmSimpleTypeKind.String);
   uuid.setFacets (new Facets ().setNullable (false));
   uuid.setCustomizableFeedMappings (new CustomizableFeedMappings ()
         .setFcTargetPath (EdmTargetPath.SYNDICATION_TITLE));
   properties.add (uuid);

   SimpleProperty restriction_type = new SimpleProperty ();
   restriction_type.setName (RESTRICTION_TYPE);
   restriction_type.setType (EdmSimpleTypeKind.String);
   restriction_type.setFacets (new Facets ().setNullable (false));
   properties.add (restriction_type);

   SimpleProperty reason = new SimpleProperty ();
   reason.setName (REASON);
   reason.setType (EdmSimpleTypeKind.String);
   reason.setFacets (new Facets ().setNullable (false));
   properties.add (reason);

   Key key = new Key ();
   List<PropertyRef> propertyRefs = Collections.singletonList (
         new PropertyRef ().setName (UUID));
   key.setKeys (propertyRefs);

   EntityType entityType = new EntityType ();
   entityType.setName (ENTITY_NAME);
   entityType.setProperties (properties);
   entityType.setKey (key);

   return entityType;
}
 
Example #20
Source File: NetworkEntitySet.java    From DataHubSystem with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public EntityType getEntityType ()
{
   // Properties
   List<Property> properties = new ArrayList<Property> ();

   properties.add (new SimpleProperty ()
   .setName (ID)
   .setType (EdmSimpleTypeKind.Int64)
   .setFacets (new Facets ().setNullable (false))
   .setCustomizableFeedMappings (
      new CustomizableFeedMappings ()
         .setFcTargetPath (EdmTargetPath.SYNDICATION_TITLE)));

   // Key
   Key key =
      new Key ().setKeys (Collections.singletonList (new PropertyRef ()
         .setName (ID)));

   // Navigation Properties
   List<NavigationProperty> navigationProperties =
      new ArrayList<NavigationProperty> ();

   if (Security.currentUserHasRole(Role.STATISTICS))
   {
      navigationProperties.add (new NavigationProperty ()
         .setName ("NetworkStatistic")
         .setRelationship (ASSO_NETWORK_NETWORKSTATISTIC)
         .setFromRole (ROLE_NETWORKSTATISTIC_NETWORK)
         .setToRole (ROLE_NETWORK_NETWORKSTATISTIC));
   }

   return new EntityType ().setName (ENTITY_NAME).setProperties (properties)
      .setKey (key).setNavigationProperties (navigationProperties);
}
 
Example #21
Source File: ODataJPAEdmProvider.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
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 vote down vote up
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: ODataJPAEdmProvider.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Override
public EntityType getEntityType(final FullQualifiedName edmFQName) throws ODataException {

  String strEdmFQName = null;

  if (edmFQName != null) {
    strEdmFQName = edmFQName.toString();
    if (entityTypes.containsKey(strEdmFQName)) {
      return entityTypes.get(strEdmFQName);
    } else if (schemas == null) {
      getSchemas();
    }

    String entityTypeNamespace = edmFQName.getNamespace();
    String entityTypeName = edmFQName.getName();

    for (Schema schema : schemas) {
      String schemaNamespace = schema.getNamespace();
      if (schemaNamespace.equals(entityTypeNamespace)) {
        if (schema.getEntityTypes() == null) {
          return null;
        }
        for (EntityType et : schema.getEntityTypes()) {
          if (et.getName().equals(entityTypeName)) {
            entityTypes.put(strEdmFQName, et);
            return et;
          }
        }
      }
    }
  }

  return null;
}
 
Example #24
Source File: JPAEdmEntitySet.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Override
public void build() throws ODataJPAModelException, ODataJPARuntimeException {

  if (consistentEntitySetList == null) {
    consistentEntitySetList = new ArrayList<EntitySet>();
  }

  entityTypeView = new JPAEdmEntityType(schemaView);
  entityTypeView.getBuilder().build();

  if (entityTypeView.isConsistent() && entityTypeView.getConsistentEdmEntityTypes() != null) {

    String nameSpace = schemaView.getEdmSchema().getNamespace();
    for (EntityType entityType : entityTypeView.getConsistentEdmEntityTypes()) {

      currentEntitySet = new EntitySet();
      currentEntitySet.setEntityType(new FullQualifiedName(nameSpace, entityType.getName()));
      JPAEdmNameBuilder.build(JPAEdmEntitySet.this, entityTypeView);
      consistentEntitySetList.add(currentEntitySet);

    }
    isConsistent = true;
  } else {
    isConsistent = false;
    return;
  }

}
 
Example #25
Source File: MapProvider.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Override
public EntityType getEntityType(final FullQualifiedName edmFQName) throws ODataException {
  if (!NAMESPACE.equals(edmFQName.getNamespace()) || !mapping[ENTITYTYPE][EDM].equals(edmFQName.getName())) {
    throw new ODataException("not found: " + edmFQName);
  }

  return entityType;
}
 
Example #26
Source File: ItemEntitySet.java    From DataHubSystem with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public EntityType getEntityType ()
{
   List<Property> properties = new ArrayList<Property> ();
   properties.add (new SimpleProperty ().setName (ID)
      .setType (EdmSimpleTypeKind.String)
      .setFacets (new Facets ().setNullable (false)));
   properties.add (new SimpleProperty ()
      .setName (NAME)
      .setType (EdmSimpleTypeKind.String)
      .setCustomizableFeedMappings (
         new CustomizableFeedMappings ()
            .setFcTargetPath (EdmTargetPath.SYNDICATION_TITLE)));
   properties.add (new SimpleProperty ().setName (CONTENT_TYPE).setType (
      EdmSimpleTypeKind.String));
   properties.add (new SimpleProperty ().setName (CONTENT_LENGTH).setType (
      EdmSimpleTypeKind.Int64));

   // Key
   Key key =
      new Key ().setKeys (Collections.singletonList (new PropertyRef ()
         .setName (ID)));

   // TODO (OData v3) setOpenType(true) setAbstract(true)
   return new EntityType ().setName (ENTITY_NAME).setProperties (properties)
      .setKey (key);
}
 
Example #27
Source File: XmlMetadataConsumerTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Test
public void ODATAJAVA_77_testBaseTypeKey() throws Exception {
  final String metadata = ""
      + "<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=\"" + NAMESPACE2 + "\" xmlns=\"" + Edm.NAMESPACE_EDM_2008_09 + "\">"
      + "         <EntityType Name= \"Parameter\">"
      + "               <Key> "
      + "                 <PropertyRef Name=\"Id\" />"
      + "               </Key>"
      + "               <Property Name=\"Id\" Type=\"Edm.Int16\" Nullable=\"false\" />"
      + "           </EntityType>"
      + "           <EntityType Name= \"ConfigParameter\" BaseType= \"RefScenario2.Parameter\" />"
      + "           <EntityType Name= \"DataConfigParameter\" BaseType= \"RefScenario2.ConfigParameter\" >"
      + "               <Key> "
      + "                 <PropertyRef Name=\"Name\" />"
      + "               </Key>"
      + "               <Property Name=\"Name\" Type=\"Edm.String\" Nullable=\"false\" />"
      + "           </EntityType>"
      + "           <EntityType Name= \"StringDataConfigParameter\" BaseType= \"RefScenario2.DataConfigParameter\" />"
      + "       </Schema>"
      + "  </edmx:DataServices>"
      + "</edmx:Edmx>";

  XmlMetadataConsumer parser = new XmlMetadataConsumer();
  XMLStreamReader reader = createStreamReader(metadata);
  DataServices result = parser.readMetadata(reader, true);

  assertEquals(1, result.getSchemas().size());
  List<EntityType> entityTypes = result.getSchemas().get(0).getEntityTypes();
  assertEquals(4, entityTypes.size());

}
 
Example #28
Source File: JPAEdmFunctionImportTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Override
public EntityType searchEdmEntityType(final String arg0) {
  if (arg0.equals(JPACustomProcessorMock.class.getSimpleName())) {
    return new EntityType().setName(JPACustomProcessorMock.edmName);
  } else {
    return null;
  }
}
 
Example #29
Source File: JPAEdmEntityType.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
@Override
public EntityType previous() {
  if (pos > 0 && pos < size) {
    currentEdmEntityType = consistentEntityTypes.get(--pos);
    return currentEdmEntityType;
  }
  return null;
}
 
Example #30
Source File: JPAEdmExtension.java    From lemonaid with MIT License 5 votes vote down vote up
private EntityType getEntityType(Schema edmSchema, FullQualifiedName entityType) {
	for (EntityType e : edmSchema.getEntityTypes()) {
		if (entityType.equals(new FullQualifiedName(edmSchema.getNamespace(), e.getName()))) {
			return e;
		}
	}
	return null;
}