Java Code Examples for org.apache.olingo.commons.api.data.Entity#getType()

The following examples show how to use org.apache.olingo.commons.api.data.Entity#getType() . 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: DataProvider.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
public void update(final String rawBaseUri, final EdmEntitySet edmEntitySet, Entity entity,
    final Entity changedEntity, final boolean patch, final boolean isInsert) throws DataProviderException {

  final EdmEntityType entityType = changedEntity.getType()!=null ?
      edm.getEntityType(new FullQualifiedName(changedEntity.getType())):edmEntitySet.getEntityType();
  final List<String> keyNames = entityType.getKeyPredicateNames();

  // Update Properties
  for (final String propertyName : entityType.getPropertyNames()) {
    if (!keyNames.contains(propertyName)) {
      updateProperty(entityType.getStructuralProperty(propertyName),
          entity.getProperty(propertyName),
          changedEntity.getProperty(propertyName),
          patch);
    }
  }

  // For insert operations collection navigation property bind operations and deep insert operations can be combined.
  // In this case, the bind operations MUST appear before the deep insert operations in the payload.
  // => Apply bindings first
  final boolean navigationBindingsAvailable = !changedEntity.getNavigationBindings().isEmpty();
  if (navigationBindingsAvailable) {
    applyNavigationBinding(rawBaseUri, edmEntitySet, entity, changedEntity.getNavigationBindings());
  }

  // Deep insert (only if not an update)
  if (isInsert) {
    handleDeepInsert(rawBaseUri, edmEntitySet, entity, changedEntity);
  } else {
    handleDeleteSingleNavigationProperties(edmEntitySet, entity, changedEntity);
  }

  // Update the ETag if present.
  updateETag(entity);
}
 
Example 2
Source File: EdmAssistedJsonSerializer.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
protected void doSerialize(final EdmEntityType entityType, final Entity entity,
    final String contextURLString, final String metadataETag, JsonGenerator json)
    throws IOException, SerializerException {

  json.writeStartObject();

  final String typeName = entity.getType() == null ? null : new EdmTypeInfo.Builder().setTypeExpression(entity
      .getType()).build().external();
  metadata(contextURLString, metadataETag, entity.getETag(), typeName, entity.getId(), true, json);

  for (final Annotation annotation : entity.getAnnotations()) {
    valuable(json, annotation, '@' + annotation.getTerm(), null, null);
  }

  for (final Property property : entity.getProperties()) {
    final String name = property.getName();
    final EdmProperty edmProperty = entityType == null || entityType.getStructuralProperty(name) == null ? null
        : entityType.getStructuralProperty(name);
    valuable(json, property, name, edmProperty == null ? null : edmProperty.getType(), edmProperty);
  }

  if (!isODataMetadataNone &&
      entity.getEditLink() != null && entity.getEditLink().getHref() != null) {
    json.writeStringField(Constants.JSON_EDIT_LINK, entity.getEditLink().getHref());

    if (entity.isMediaEntity()) {
      json.writeStringField(Constants.JSON_MEDIA_READ_LINK, entity.getEditLink().getHref() + "/$value");
    }
  }

  links(entity, entityType, json);

  json.writeEndObject();
}
 
Example 3
Source File: Storage.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private String getEntitySetName(Entity entity) {
  if(DemoEdmProvider.ET_CATEGORY_FQN.getFullQualifiedNameAsString().equals(entity.getType())) {
    return DemoEdmProvider.ES_CATEGORIES_NAME;
  } else if(DemoEdmProvider.ET_PRODUCT_FQN.getFullQualifiedNameAsString().equals(entity.getType())) {
    return DemoEdmProvider.ES_PRODUCTS_NAME;
  }
  return entity.getType();
}
 
Example 4
Source File: Storage.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
public EntityCollection getRelatedEntityCollection(Entity sourceEntity, EdmEntityType targetEntityType) {
  EntityCollection navigationTargetEntityCollection = new EntityCollection();

  FullQualifiedName relatedEntityFqn = targetEntityType.getFullQualifiedName();
  String sourceEntityFqn = sourceEntity.getType();

  if (sourceEntityFqn.equals(DemoEdmProvider.ET_PRODUCT_FQN.getFullQualifiedNameAsString())
      && relatedEntityFqn.equals(DemoEdmProvider.ET_CATEGORY_FQN)) {
    // relation Products->Category (result all categories)
    int productID = (Integer) sourceEntity.getProperty("ID").getValue();
    if (productID == 0 || productID == 1) {
      navigationTargetEntityCollection.getEntities().add(categoryList.get(0));
    } else if (productID == 2 || productID == 3) {
      navigationTargetEntityCollection.getEntities().add(categoryList.get(1));
    } else if (productID == 4 || productID == 5) {
      navigationTargetEntityCollection.getEntities().add(categoryList.get(2));
    }
  } else if (sourceEntityFqn.equals(DemoEdmProvider.ET_CATEGORY_FQN.getFullQualifiedNameAsString())
      && relatedEntityFqn.equals(DemoEdmProvider.ET_PRODUCT_FQN)) {
    // relation Category->Products (result all products)
    int categoryID = (Integer) sourceEntity.getProperty("ID").getValue();
    if (categoryID == 0) {
      // the first 2 products are notebooks
      navigationTargetEntityCollection.getEntities().addAll(productList.subList(0, 2));
    } else if (categoryID == 1) {
      // the next 2 products are organizers
      navigationTargetEntityCollection.getEntities().addAll(productList.subList(2, 4));
    } else if (categoryID == 2) {
      // the first 2 products are monitors
      navigationTargetEntityCollection.getEntities().addAll(productList.subList(4, 6));
    }
  }

  return navigationTargetEntityCollection;
}
 
Example 5
Source File: Storage.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private String getEntitySetName(Entity entity) {
  if(DemoEdmProvider.ET_CATEGORY_FQN.getFullQualifiedNameAsString().equals(entity.getType())) {
    return DemoEdmProvider.ES_CATEGORIES_NAME;
  } else if(DemoEdmProvider.ET_PRODUCT_FQN.getFullQualifiedNameAsString().equals(entity.getType())) {
    return DemoEdmProvider.ES_PRODUCTS_NAME;
  } else if (DemoEdmProvider.ET_ADVERTISEMENT_FQN.getFullQualifiedNameAsString().equals(entity.getType())) {
    return DemoEdmProvider.ES_ADVERTISEMENTS_NAME;
  }
  return entity.getType();
}
 
Example 6
Source File: Storage.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private String getEntitySetName(Entity entity) {
  if (DemoEdmProvider.ET_CATEGORY_FQN.getFullQualifiedNameAsString().equals(entity.getType())) {
    return DemoEdmProvider.ES_CATEGORIES_NAME;
  } else if (DemoEdmProvider.ET_PRODUCT_FQN.getFullQualifiedNameAsString().equals(entity.getType())) {
    return DemoEdmProvider.ES_PRODUCTS_NAME;
  } else if (DemoEdmProvider.ET_ADVERTISEMENT_FQN.getFullQualifiedNameAsString().equals(entity.getType())) {
    return DemoEdmProvider.ES_ADVERTISEMENTS_NAME;
  }
  return entity.getType();
}
 
Example 7
Source File: Storage.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
public EntityCollection getRelatedEntityCollection(Entity sourceEntity, EdmEntityType targetEntityType) {
  EntityCollection navigationTargetEntityCollection = new EntityCollection();

  FullQualifiedName relatedEntityFqn = targetEntityType.getFullQualifiedName();
  String sourceEntityFqn = sourceEntity.getType();

  if (sourceEntityFqn.equals(DemoEdmProvider.ET_PRODUCT_FQN.getFullQualifiedNameAsString())
      && relatedEntityFqn.equals(DemoEdmProvider.ET_CATEGORY_FQN)) {
    // relation Products->Category (result all categories)
    int productID = (Integer) sourceEntity.getProperty("ID").getValue();
    if (productID == 0 || productID == 1) {
      navigationTargetEntityCollection.getEntities().add(categoryList.get(0));
    } else if (productID == 2 || productID == 3) {
      navigationTargetEntityCollection.getEntities().add(categoryList.get(1));
    } else if (productID == 4 || productID == 5) {
      navigationTargetEntityCollection.getEntities().add(categoryList.get(2));
    }
  } else if (sourceEntityFqn.equals(DemoEdmProvider.ET_CATEGORY_FQN.getFullQualifiedNameAsString())
      && relatedEntityFqn.equals(DemoEdmProvider.ET_PRODUCT_FQN)) {
    // relation Category->Products (result all products)
    int categoryID = (Integer) sourceEntity.getProperty("ID").getValue();
    if (categoryID == 0) {
      // the first 2 products are notebooks
      navigationTargetEntityCollection.getEntities().addAll(productList.subList(0, 2));
    } else if (categoryID == 1) {
      // the next 2 products are organizers
      navigationTargetEntityCollection.getEntities().addAll(productList.subList(2, 4));
    } else if (categoryID == 2) {
      // the first 2 products are monitors
      navigationTargetEntityCollection.getEntities().addAll(productList.subList(4, 6));
    }
  }

  return navigationTargetEntityCollection;
}
 
Example 8
Source File: Storage.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private String getEntitySetName(Entity entity) {
  if(DemoEdmProvider.ET_CATEGORY_FQN.getFullQualifiedNameAsString().equals(entity.getType())) {
    return DemoEdmProvider.ES_CATEGORIES_NAME;
  } else if(DemoEdmProvider.ET_PRODUCT_FQN.getFullQualifiedNameAsString().equals(entity.getType())) {
    return DemoEdmProvider.ES_PRODUCTS_NAME;
  }
  return entity.getType();
}
 
Example 9
Source File: Storage.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private String getEntitySetName(Entity entity) {
  if(DemoEdmProvider.ET_CATEGORY_FQN.getFullQualifiedNameAsString().equals(entity.getType())) {
    return DemoEdmProvider.ES_CATEGORIES_NAME;
  } else if(DemoEdmProvider.ET_PRODUCT_FQN.getFullQualifiedNameAsString().equals(entity.getType())) {
    return DemoEdmProvider.ES_PRODUCTS_NAME;
  }
  return entity.getType();
}
 
Example 10
Source File: Storage.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
public EntityCollection getRelatedEntityCollection(Entity sourceEntity, EdmEntityType targetEntityType) {
  EntityCollection navigationTargetEntityCollection = new EntityCollection();

  FullQualifiedName relatedEntityFqn = targetEntityType.getFullQualifiedName();
  String sourceEntityFqn = sourceEntity.getType();

  if (sourceEntityFqn.equals(DemoEdmProvider.ET_PRODUCT_FQN.getFullQualifiedNameAsString())
      && relatedEntityFqn.equals(DemoEdmProvider.ET_CATEGORY_FQN)) {
    // relation Products->Category (result all categories)
    int productID = (Integer) sourceEntity.getProperty("ID").getValue();
    if (productID == 0 || productID == 1) {
      navigationTargetEntityCollection.getEntities().add(categoryList.get(0));
    } else if (productID == 2 || productID == 3) {
      navigationTargetEntityCollection.getEntities().add(categoryList.get(1));
    } else if (productID == 4 || productID == 5) {
      navigationTargetEntityCollection.getEntities().add(categoryList.get(2));
    }
  } else if (sourceEntityFqn.equals(DemoEdmProvider.ET_CATEGORY_FQN.getFullQualifiedNameAsString())
      && relatedEntityFqn.equals(DemoEdmProvider.ET_PRODUCT_FQN)) {
    // relation Category->Products (result all products)
    int categoryID = (Integer) sourceEntity.getProperty("ID").getValue();
    if (categoryID == 0) {
      // the first 2 products are notebooks
      navigationTargetEntityCollection.getEntities().addAll(productList.subList(0, 2));
    } else if (categoryID == 1) {
      // the next 2 products are organizers
      navigationTargetEntityCollection.getEntities().addAll(productList.subList(2, 4));
    } else if (categoryID == 2) {
      // the first 2 products are monitors
      navigationTargetEntityCollection.getEntities().addAll(productList.subList(4, 6));
    }
  }

  return navigationTargetEntityCollection;
}
 
Example 11
Source File: Storage.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private String getEntitySetName(Entity entity) {
  if(DemoEdmProvider.ET_CATEGORY_FQN.getFullQualifiedNameAsString().equals(entity.getType())) {
    return DemoEdmProvider.ES_CATEGORIES_NAME;
  } else if(DemoEdmProvider.ET_PRODUCT_FQN.getFullQualifiedNameAsString().equals(entity.getType())) {
    return DemoEdmProvider.ES_PRODUCTS_NAME;
  }
  return entity.getType();
}
 
Example 12
Source File: Storage.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private String getEntitySetName(Entity entity) {
  if(DemoEdmProvider.ET_CATEGORY_FQN.getFullQualifiedNameAsString().equals(entity.getType())) {
    return DemoEdmProvider.ES_CATEGORIES_NAME;
  } else if(DemoEdmProvider.ET_PRODUCT_FQN.getFullQualifiedNameAsString().equals(entity.getType())) {
    return DemoEdmProvider.ES_PRODUCTS_NAME;
  } else if(DemoEdmProvider.ET_SUPPLIER_FQN.getFullQualifiedNameAsString().equals(entity.getType())) {
    return DemoEdmProvider.ES_PRODUCTS_NAME;
  }
  return entity.getType();
}
 
Example 13
Source File: Storage.java    From olingo-odata4 with Apache License 2.0 5 votes vote down vote up
private String getEntitySetName(Entity entity) {
  if(DemoEdmProvider.ET_CATEGORY_FQN.getFullQualifiedNameAsString().equals(entity.getType())) {
    return DemoEdmProvider.ES_CATEGORIES_NAME;
  } else if(DemoEdmProvider.ET_PRODUCT_FQN.getFullQualifiedNameAsString().equals(entity.getType())) {
    return DemoEdmProvider.ES_PRODUCTS_NAME;
  }
  return entity.getType();
}
 
Example 14
Source File: JsonEntitySerializer.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
protected void doContainerSerialize(final ResWrap<Entity> container, final JsonGenerator jgen)
    throws IOException, EdmPrimitiveTypeException {

  final Entity entity = container.getPayload();

  jgen.writeStartObject();

  if (serverMode && !isODataMetadataNone) {
    if (container.getContextURL() != null) {
      jgen.writeStringField(Constants.JSON_CONTEXT, container.getContextURL().toASCIIString());
    }
    if (container.getMetadataETag() != null) {
      jgen.writeStringField(Constants.JSON_METADATA_ETAG, container.getMetadataETag());
    }

    if (entity.getETag() != null) {
      jgen.writeStringField(Constants.JSON_ETAG, entity.getETag());
    }
  }

  if (entity.getType() != null && isODataMetadataFull) {
    jgen.writeStringField(Constants.JSON_TYPE,
        new EdmTypeInfo.Builder().setTypeExpression(entity.getType()).build().external());
  }

  if (entity.getId() != null && isODataMetadataFull) {
    jgen.writeStringField(Constants.JSON_ID, entity.getId().toASCIIString());
  }

  for (Annotation annotation : entity.getAnnotations()) {
    valuable(jgen, annotation, "@" + annotation.getTerm());
  }

  for (Property property : entity.getProperties()) {
    valuable(jgen, property, property.getName());
  }

  if (serverMode && entity.getEditLink() != null && 
      entity.getEditLink().getHref() != null && isODataMetadataFull) {
    jgen.writeStringField(Constants.JSON_EDIT_LINK, entity.getEditLink().getHref());

    if (entity.isMediaEntity() && isODataMetadataFull) {
      jgen.writeStringField(Constants.JSON_MEDIA_READ_LINK,
          entity.getEditLink().getHref() + "/$value");
    }
  }

  if (!isODataMetadataNone) {
    links(entity, jgen);
  }

  if (isODataMetadataFull) {
    for (Link link : entity.getMediaEditLinks()) {
      if (link.getTitle() == null) {
        jgen.writeStringField(Constants.JSON_MEDIA_EDIT_LINK, link.getHref());
      }

      if (link.getInlineEntity() != null) {
        jgen.writeObjectField(link.getTitle(), link.getInlineEntity());
      }
      if (link.getInlineEntitySet() != null) {
        jgen.writeArrayFieldStart(link.getTitle());
        for (Entity subEntry : link.getInlineEntitySet().getEntities()) {
          jgen.writeObject(subEntry);
        }
        jgen.writeEndArray();
      }
    }
  }

  if (serverMode && isODataMetadataFull) {
    for (Operation operation : entity.getOperations()) {
      final String anchor = operation.getMetadataAnchor();
      final int index = anchor.lastIndexOf('#');
      jgen.writeObjectFieldStart('#' + anchor.substring(index < 0 ? 0 : (index + 1)));
      jgen.writeStringField(Constants.ATTR_TITLE, operation.getTitle());
      jgen.writeStringField(Constants.ATTR_TARGET, operation.getTarget().toASCIIString());
      jgen.writeEndObject();
    }
  }

  jgen.writeEndObject();
}
 
Example 15
Source File: Storage.java    From olingo-odata4 with Apache License 2.0 4 votes vote down vote up
public EntityCollection getRelatedEntityCollection(Entity sourceEntity, EdmEntityType targetEntityType) {
  EntityCollection navigationTargetEntityCollection = new EntityCollection();

  FullQualifiedName relatedEntityFqn = targetEntityType.getFullQualifiedName();
  String sourceEntityFqn = sourceEntity.getType();

  if (sourceEntityFqn.equals(DemoEdmProvider.ET_PRODUCT_FQN.getFullQualifiedNameAsString())
      && relatedEntityFqn.equals(DemoEdmProvider.ET_CATEGORY_FQN)) {
    navigationTargetEntityCollection.setId(createId(sourceEntity, "ID", DemoEdmProvider.NAV_TO_CATEGORY));
    // relation Products->Category (result all categories)
    int productID = (Integer) sourceEntity.getProperty("ID").getValue();
    if (productID == 1 || productID == 2) {
      navigationTargetEntityCollection.getEntities().add(categoryList.get(0));
    } else if (productID == 3 || productID == 4) {
      navigationTargetEntityCollection.getEntities().add(categoryList.get(1));
    } else if (productID == 5 || productID == 6) {
      navigationTargetEntityCollection.getEntities().add(categoryList.get(2));
    }
  } else if (sourceEntityFqn.equals(DemoEdmProvider.ET_CATEGORY_FQN.getFullQualifiedNameAsString())
      && relatedEntityFqn.equals(DemoEdmProvider.ET_PRODUCT_FQN)) {
    navigationTargetEntityCollection.setId(createId(sourceEntity, "ID", DemoEdmProvider.NAV_TO_PRODUCTS));
    // relation Category->Products (result all products)
    int categoryID = (Integer) sourceEntity.getProperty("ID").getValue();
    if (categoryID == 1) {
      // the first 2 products are notebooks
      navigationTargetEntityCollection.getEntities().addAll(productList.subList(0, 2));
    } else if (categoryID == 2) {
      // the next 2 products are organizers
      navigationTargetEntityCollection.getEntities().addAll(productList.subList(2, 4));
    } else if (categoryID == 3) {
      // the first 2 products are monitors
      navigationTargetEntityCollection.getEntities().addAll(productList.subList(4, 6));
    }
  }

  if (navigationTargetEntityCollection.getEntities().isEmpty()) {
    return null;
  }

  return navigationTargetEntityCollection;
}