Java Code Examples for org.apache.olingo.odata2.api.edm.provider.Schema#setEntityContainers()

The following examples show how to use org.apache.olingo.odata2.api.edm.provider.Schema#setEntityContainers() . 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: TechnicalScenarioEdmProvider.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
@Override
public List<Schema> getSchemas() throws ODataMessageException {
  final Schema schema = new Schema();
  schema.setNamespace(NAMESPACE_1);

  schema.setEntityTypes(Arrays.asList(
      getEntityType(ET_KEY_IS_STRING),
      getEntityType(ET_KEY_IS_INTEGER),
      getEntityType(ET_COMPLEX_KEY),
      getEntityType(ET_ALL_TYPES)));

  schema.setComplexTypes(Arrays.asList(getComplexType(CT_ALL_TYPES)));

  final EntityContainer entityContainer = new EntityContainer();
  entityContainer.setName(ENTITY_CONTAINER_1).setDefaultEntityContainer(true);
  entityContainer.setEntitySets(Arrays.asList(
      getEntitySet(ENTITY_CONTAINER_1, ES_KEY_IS_STRING),
      getEntitySet(ENTITY_CONTAINER_1, ES_KEY_IS_INTEGER),
      getEntitySet(ENTITY_CONTAINER_1, ES_COMPLEX_KEY),
      getEntitySet(ENTITY_CONTAINER_1, ES_ALL_TYPES),
      getEntitySet(ENTITY_CONTAINER_1, ES_STRING_FACETS)));

  schema.setEntityContainers(Arrays.asList(entityContainer));

  return Arrays.asList(schema);
}
 
Example 2
Source File: AnnotationEdmProvider.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
public Schema build() {
  Schema s = new Schema();
  s.setUsings(usings);
  s.setEntityTypes(entityTypes);
  s.setComplexTypes(complexTypes);
  s.setAssociations(new ArrayList<Association>(name2Associations.values()));
  s.setEntityContainers(entityContainers);
  s.setAnnotationAttributes(annotationAttributes);
  s.setAnnotationElements(annotationElements);
  s.setNamespace(namespace);
  return s;
}
 
Example 3
Source File: EdmSchemaMock.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
public static Schema createMockEdmSchema() {
  Schema schema = new Schema();
  schema.setNamespace(NAMESPACE);
  schema.setComplexTypes(createComplexTypes());
  schema.setEntityContainers(createEntityContainer());
  schema.setEntityTypes(createEntityTypes());
  schema.setAssociations(createAssociations());
  return schema;
}
 
Example 4
Source File: Model.java    From DataHubSystem with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public List<Schema> getSchemas() throws ODataException
{
   List<Schema> schemas = new ArrayList<>();

   Schema schema = new Schema();
   schema.setNamespace(NAMESPACE);

   fr.gael.dhus.database.object.User u = Security.getCurrentUser();

   ArrayList<EntityType> entities = new ArrayList<>();
   ArrayList<EntitySet> entitysets = new ArrayList<>();
   ArrayList<Association> associations = new ArrayList<>();
   ArrayList<AssociationSet> association_sets = new ArrayList<>();
   List<FunctionImport> function_imports = new ArrayList<>();

   for (AbstractEntitySet<?> entitySet: ENTITYSETS.values())
   {
      if (entitySet.isAuthorized(u))
      {
         entities.add(entitySet.getEntityType());
         entitysets.add(entitySet.getEntitySet());
         associations.addAll(entitySet.getAssociations());
         association_sets.addAll(entitySet.getAssociationSets());
      }
   }

   for (AbstractOperation op: OPERATIONS.values())
   {
      if (op.canExecute(u))
      {
         function_imports.add(op.getFunctionImport());
      }
   }

   schema.setEntityTypes(entities);
   schema.setComplexTypes(new ArrayList<>(COMPLEX_TYPES.values()));
   schema.setAssociations(new ArrayList<>(associations));

   EntityContainer entityContainer = new EntityContainer();
   entityContainer.setName(ENTITY_CONTAINER).setDefaultEntityContainer(true);

   entityContainer.setEntitySets(entitysets);
   entityContainer.setAssociationSets(new ArrayList<>(association_sets));
   entityContainer.setFunctionImports(function_imports);

   schema.setEntityContainers(Collections.singletonList(entityContainer));

   schemas.add(schema);

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

  schema = new Schema();
  JPAEdmNameBuilder.build(JPAEdmSchema.this);

  associationView = new JPAEdmAssociation(JPAEdmSchema.this);

  complexTypeView = new JPAEdmComplexType(JPAEdmSchema.this);
  complexTypeView.getBuilder().build();

  entityContainerView = new JPAEdmEntityContainer(JPAEdmSchema.this);
  entityContainerView.getBuilder().build();
  schema.setEntityContainers(entityContainerView.getConsistentEdmEntityContainerList());

  JPAEdmEntitySetView entitySetView = entityContainerView.getJPAEdmEntitySetView();
  if (entitySetView.isConsistent() && entitySetView.getJPAEdmEntityTypeView() != null) {
    JPAEdmEntityTypeView entityTypeView = entitySetView.getJPAEdmEntityTypeView();
    if (entityTypeView.isConsistent() && !entityTypeView.getConsistentEdmEntityTypes().isEmpty()) {
      schema.setEntityTypes(entityTypeView.getConsistentEdmEntityTypes());
    }
  }
  if (complexTypeView.isConsistent()) {
    List<ComplexType> complexTypes = complexTypeView.getConsistentEdmComplexTypes();
    List<ComplexType> existingComplexTypes = new ArrayList<ComplexType>();
    for (ComplexType complexType : complexTypes) {
      if (complexType != null && complexTypeView.isReferencedInKey(complexType.getName())) {// null check for
                                                                                            // exclude
        existingComplexTypes.add(complexType);
      }
    }
    if (!existingComplexTypes.isEmpty()) {
      schema.setComplexTypes(existingComplexTypes);
    }
  }

  List<String> existingAssociationList = new ArrayList<String>();
  if (associationView.isConsistent() && !associationView.getConsistentEdmAssociationList().isEmpty()) {

    List<Association> consistentAssociationList = associationView.getConsistentEdmAssociationList();
    schema.setAssociations(consistentAssociationList);
    for (Association association : consistentAssociationList) {
      existingAssociationList.add(association.getName());
    }

  }
  List<EntityType> entityTypes =
      entityContainerView.getJPAEdmEntitySetView().getJPAEdmEntityTypeView().getConsistentEdmEntityTypes();
  List<NavigationProperty> navigationProperties;
  if (entityTypes != null && !entityTypes.isEmpty()) {
    for (EntityType entityType : entityTypes) {

      List<NavigationProperty> consistentNavigationProperties = null;
      navigationProperties = entityType.getNavigationProperties();
      if (navigationProperties != null) {
        consistentNavigationProperties = new ArrayList<NavigationProperty>();
        for (NavigationProperty navigationProperty : navigationProperties) {
          if (existingAssociationList.contains(navigationProperty.getRelationship().getName())) {
            consistentNavigationProperties.add(navigationProperty);
          }
        }
        if (consistentNavigationProperties.isEmpty()) {
          entityType.setNavigationProperties(null);
        } else {
          entityType.setNavigationProperties(consistentNavigationProperties);
        }
      }

    }
  }

  JPAEdmExtension edmExtension = getJPAEdmExtension();
  if (edmExtension != null) {
    edmExtension.extendJPAEdmSchema(JPAEdmSchema.this);
    edmExtension.extendWithOperation(JPAEdmSchema.this);

    JPAEdmFunctionImportView functionImportView = new JPAEdmFunctionImport(JPAEdmSchema.this);
    functionImportView.getBuilder().build();
    if (functionImportView.getConsistentFunctionImportList() != null) {
      entityContainerView.getEdmEntityContainer().setFunctionImports(
          functionImportView.getConsistentFunctionImportList());
    }

  }
}
 
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);
}
 
Example 7
Source File: CarEdmProvider.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
@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 8
Source File: MyEdmProvider.java    From wildfly-camel with Apache License 2.0 4 votes vote down vote up
@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;
}