Java Code Examples for org.apache.olingo.odata2.api.edm.provider.EntitySet#setEntityType()

The following examples show how to use org.apache.olingo.odata2.api.edm.provider.EntitySet#setEntityType() . 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: AbstractEntitySet.java    From DataHubSystem with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * @return Olingo ES object for this ES.
 */
public EntitySet getEntitySet()
{
   EntitySet res = new EntitySet().setName(getName());
   res.setEntityType(getFullQualifiedName());
   return res;
}
 
Example 2
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 3
Source File: JPAEdmAssociationSetTest.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private List<EntitySet> getEntitySetListLocal() {
  List<EntitySet> entitySetList = new ArrayList<EntitySet>();

  EntitySet entitySet = new EntitySet();
  entitySet.setName("SalesOrderHeader");
  entitySet.setEntityType(new FullQualifiedName("salesorderprocessing", "SOID"));

  EntitySet entitySet2 = new EntitySet();
  entitySet2.setName("SalesOrderItem");
  entitySet2.setEntityType(new FullQualifiedName("salesorderprocessing", "SOID"));

  entitySetList.add(entitySet);
  entitySetList.add(entitySet2);
  return entitySetList;
}
 
Example 4
Source File: XmlMetadataConsumer.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
private EntitySet readEntitySet(final XMLStreamReader reader) throws XMLStreamException, EntityProviderException {
  reader.require(XMLStreamConstants.START_ELEMENT, edmNamespace, XmlMetadataConstants.EDM_ENTITY_SET);
  EntitySet entitySet = new EntitySet();
  List<AnnotationElement> annotationElements = new ArrayList<AnnotationElement>();
  entitySet.setName(reader.getAttributeValue(null, XmlMetadataConstants.EDM_NAME));
  String entityType = reader.getAttributeValue(null, XmlMetadataConstants.EDM_ENTITY_TYPE);
  if (entityType != null) {
    FullQualifiedName fqName = extractFQName(entityType);
    entitySet.setEntityType(fqName);
  } else {
    throw new EntityProviderException(EntityProviderException.MISSING_ATTRIBUTE
        .addContent(XmlMetadataConstants.EDM_ENTITY_TYPE).addContent(XmlMetadataConstants.EDM_ENTITY_SET));
  }
  entitySet.setAnnotationAttributes(readAnnotationAttribute(reader));
  while (reader.hasNext()
      && !(reader.isEndElement() && edmNamespace.equals(reader.getNamespaceURI())
      && XmlMetadataConstants.EDM_ENTITY_SET.equals(reader.getLocalName()))) {
    reader.next();
    if (reader.isStartElement()) {
      extractNamespaces(reader);
      annotationElements.add(readAnnotationElement(reader));
    }
  }
  if (!annotationElements.isEmpty()) {
    entitySet.setAnnotationElements(annotationElements);
  }
  return entitySet;
}
 
Example 5
Source File: EdmEntitySetProvTest.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);

  EntityContainerInfo entityContainer = new EntityContainerInfo().setName("Container");
  when(edmProvider.getEntityContainerInfo("Container")).thenReturn(entityContainer);
  EdmEntityContainerImplProv edmEntityContainer = new EdmEntityContainerImplProv(edmImplProv, entityContainer);

  EntitySet entitySetFoo = new EntitySet().setName("foo");
  when(edmProvider.getEntitySet("Container", "foo")).thenReturn(entitySetFoo);

  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");
  entitySetFoo.setEntityType(fooEntityTypeFullName);
  when(edmProvider.getEntityType(fooEntityTypeFullName)).thenReturn(fooEntityType);

  EntitySet entitySetBar = new EntitySet().setName("bar");
  when(edmProvider.getEntitySet("Container", "bar")).thenReturn(entitySetBar);

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

  AssociationEnd fooEnd = new AssociationEnd().setRole("fromFoo");
  AssociationEnd barEnd = new AssociationEnd().setRole("toBar");

  Association fooBarAssoc = new Association().setName("fooBarAssoc").setEnd1(fooEnd).setEnd2(barEnd);
  when(edmProvider.getAssociation(fooBarAssocName)).thenReturn(fooBarAssoc);

  AssociationSet associationSet =
      new AssociationSet().setName("fooBarRelation").setEnd1(
          new AssociationSetEnd().setRole("fromFoo").setEntitySet("foo")).setEnd2(
          new AssociationSetEnd().setRole("toBar").setEntitySet("bar"));
  FullQualifiedName assocFQName = new FullQualifiedName("namespace", "fooBarAssoc");
  when(edmProvider.getAssociationSet("Container", assocFQName, "foo", "fromFoo")).thenReturn(associationSet);

  edmEntitySetFoo = new EdmEntitySetImplProv(edmImplProv, entitySetFoo, edmEntityContainer);
  edmEnitiySetBar = new EdmEntitySetImplProv(edmImplProv, entitySetBar, edmEntityContainer);
}
 
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);
}