Java Code Examples for org.apache.olingo.odata2.api.edm.provider.EntityType#setProperties()

The following examples show how to use org.apache.olingo.odata2.api.edm.provider.EntityType#setProperties() . 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: 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 2
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 3
Source File: JPAEdmEntityType.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void build() throws ODataJPAModelException, ODataJPARuntimeException {

  Set<javax.persistence.metamodel.EntityType<?>> jpaEntityTypes = metaModel.getEntities();

  if (jpaEntityTypes == null || jpaEntityTypes.isEmpty() == true) {
    return;
  } else if (consistentEntityTypes == null) {
    consistentEntityTypes = new EntityTypeList<EntityType>();

  }

  for (javax.persistence.metamodel.EntityType<?> jpaEntityType : jpaEntityTypes) {
    currentEdmEntityType = new EntityType();
    currentJPAEntityType = jpaEntityType;

    // Check for need to Exclude
    if (isExcluded(JPAEdmEntityType.this)) {
      continue;
    }

    JPAEdmNameBuilder.build(JPAEdmEntityType.this);
    JPAEdmMapping jpaEdmMapping = (JPAEdmMapping) currentEdmEntityType.getMapping();
    EntityListeners entityListners = currentJPAEntityType.getJavaType().getAnnotation(EntityListeners.class);
    if (entityListners != null) {
      for (Class<EntityListeners> entityListner : entityListners.value()) {
        if (ODataJPATombstoneEntityListener.class.isAssignableFrom(entityListner)) {
          jpaEdmMapping
              .setODataJPATombstoneEntityListener((Class<? extends ODataJPATombstoneEntityListener>)
              (Object) entityListner);
          break;
        }
      }
    }
    JPAEdmPropertyView propertyView = new JPAEdmProperty(schemaView);
    propertyView.getBuilder().build();

    currentEdmEntityType.setProperties(propertyView.getEdmPropertyList());
    if (propertyView.getJPAEdmNavigationPropertyView() != null) {
      JPAEdmNavigationPropertyView navPropView = propertyView.getJPAEdmNavigationPropertyView();
      if (navPropView.getConsistentEdmNavigationProperties() != null
          && !navPropView.getConsistentEdmNavigationProperties().isEmpty()) {
        currentEdmEntityType.setNavigationProperties(navPropView.getConsistentEdmNavigationProperties());
      }
    }
    JPAEdmKeyView keyView = propertyView.getJPAEdmKeyView();
    currentEdmEntityType.setKey(keyView.getEdmKey());

    consistentEntityTypes.add(currentEdmEntityType);
    consistentEntityTypeMap.put(currentJPAEntityType.getName(), currentEdmEntityType);
  }

}
 
Example 4
Source File: JPAEdmReferentialConstraintRoleTest.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@Override
public EntityType searchEdmEntityType(final String arg0) {

  EntityType entityType = new EntityType();

  JPAEdmMappingImpl mapping = new JPAEdmMappingImpl();
  mapping.setJPAColumnName("SOID");

  List<Property> propList = new ArrayList<Property>();

  Property property = new Property() {};
  property.setMapping((Mapping) mapping);
  property.setName("SOID");
  propList.add(property);

  entityType.setProperties(propList);

  return entityType;
}
 
Example 5
Source File: EdmEntityTypeImplProvTest.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void getEdmEntityContainerImpl() throws Exception {

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

  List<NavigationProperty> navigationProperties = new ArrayList<NavigationProperty>();
  FullQualifiedName fooBarAssocName = new FullQualifiedName("namespace", "fooBarAssoc");
  navigationProperties.add(new NavigationProperty().setName("fooBarNav").setFromRole("fromFoo").setRelationship(
      fooBarAssocName).setToRole("toBar"));

  EntityType fooEntityType = new EntityType().setName("fooEntityType").setNavigationProperties(navigationProperties);
  FullQualifiedName fooEntityTypeFullName = new FullQualifiedName("namespace", "fooEntityType");
  when(edmProvider.getEntityType(fooEntityTypeFullName)).thenReturn(fooEntityType);

  List<Property> keyPropertysFoo = new ArrayList<Property>();
  Property keyPropFoo = new SimpleProperty().setName("Id").setType(EdmSimpleTypeKind.String);
  keyPropertysFoo.add(keyPropFoo);
  fooEntityType.setProperties(keyPropertysFoo);

  PropertyRef refToKeyFoo = new PropertyRef().setName("Id");
  List<PropertyRef> propRefKeysFoo = new ArrayList<PropertyRef>();
  propRefKeysFoo.add(refToKeyFoo);

  Key fooTypeKey = new Key().setKeys(propRefKeysFoo);
  fooEntityType.setKey(fooTypeKey);

  edmEntityType = new EdmEntityTypeImplProv(edmImplProv, fooEntityType, "namespace");

  FullQualifiedName barBaseTypeName = new FullQualifiedName("namespace", "barBase");
  EntityType barBase = new EntityType().setName("barBase");
  when(edmProvider.getEntityType(barBaseTypeName)).thenReturn(barBase);

  List<NavigationProperty> navigationPropertiesBarBase = new ArrayList<NavigationProperty>();
  navigationPropertiesBarBase.add(new NavigationProperty().setName("barBaseNav"));
  barBase.setNavigationProperties(navigationPropertiesBarBase);

  List<Property> keyPropertysBarBase = new ArrayList<Property>();
  Property keyPropBarBase = new SimpleProperty().setName("Id").setType(EdmSimpleTypeKind.String);
  keyPropertysBarBase.add(keyPropBarBase);
  keyPropBarBase = new SimpleProperty().setName("NotrmalProp").setType(EdmSimpleTypeKind.String);
  keyPropertysBarBase.add(keyPropBarBase);
  barBase.setProperties(keyPropertysBarBase);

  PropertyRef refToKeyBarBase = new PropertyRef().setName("Id");
  List<PropertyRef> propRefKeysBarBase = new ArrayList<PropertyRef>();
  propRefKeysBarBase.add(refToKeyBarBase);

  Key barBaseTypeKey = new Key().setKeys(propRefKeysBarBase);
  barBase.setKey(barBaseTypeKey);

  EntityType barEntityType = new EntityType().setName("barEntityType").setBaseType(barBaseTypeName);
  FullQualifiedName barEntityTypeFullName = new FullQualifiedName("namespace", "barEntityType");
  when(edmProvider.getEntityType(barEntityTypeFullName)).thenReturn(barEntityType);

  edmEntityTypeWithBaseType = new EdmEntityTypeImplProv(edmImplProv, barEntityType, "namespace");

}
 
Example 6
Source File: MapProvider.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
private void buildSchema() {
  propertyRef = new PropertyRef();
  propertyRef.setName("p1");

  key = new Key();
  key.setKeys(Arrays.asList(propertyRef));

  property1 =
      new SimpleProperty().setName(mapping[P1][EDM]).setType(EdmSimpleTypeKind.String).setMapping(
          new Mapping().setObject(mapping[P1][BACKEND]));
  property2 =
      new SimpleProperty().setName(mapping[P2][EDM]).setType(EdmSimpleTypeKind.String).setMapping(
          new Mapping().setObject(mapping[P2][BACKEND]));
  property3 =
      new SimpleProperty().setName(mapping[P3][EDM]).setType(EdmSimpleTypeKind.String).setMapping(
          new Mapping().setObject(mapping[P3][BACKEND]));

  entityType = new EntityType();
  entityType.setName(mapping[ENTITYTYPE][EDM]);
  entityType.setKey(key);
  entityType.setProperties(Arrays.asList(property1, property2, property3));
  entityType.setMapping(new Mapping().setObject(mapping[ENTITYTYPE][BACKEND]));

  entitySet = new EntitySet();
  entitySet.setName(mapping[ENTITYSET][EDM]);
  entitySet.setEntityType(new FullQualifiedName(NAMESPACE, mapping[ENTITYTYPE][EDM]));
  entitySet.setMapping(new Mapping().setObject(mapping[ENTITYSET][BACKEND]));

  entityContainer = new EntityContainer();
  entityContainer.setDefaultEntityContainer(true);
  entityContainer.setName(MAPPING_CONTAINER);
  entityContainer.setEntitySets(Arrays.asList(entitySet));

  schema = new Schema();
  schema.setNamespace("mapping");
  schema.setAlias(NAMESPACE);
  schema.setEntityContainers(Arrays.asList(entityContainer));
  schema.setEntityTypes(Arrays.asList(entityType));

  schemas = Arrays.asList(schema);
}