Java Code Examples for org.apache.olingo.commons.api.edm.EdmEntityType#getPropertyNames()

The following examples show how to use org.apache.olingo.commons.api.edm.EdmEntityType#getPropertyNames() . 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: ODataJsonDeserializer.java    From olingo-odata4 with Apache License 2.0 6 votes vote down vote up
private void consumeEntityProperties(final EdmEntityType edmEntityType, final ObjectNode node,
    final Entity entity) throws DeserializerException {
  List<String> propertyNames = edmEntityType.getPropertyNames();
  for (String propertyName : propertyNames) {
    JsonNode jsonNode = node.get(propertyName);
    if (jsonNode != null) {
      EdmProperty edmProperty = (EdmProperty) edmEntityType.getProperty(propertyName);
      if (jsonNode.isNull() && !edmProperty.isNullable()) {
        throw new DeserializerException("Property: " + propertyName + " must not be null.",
            DeserializerException.MessageKeys.INVALID_NULL_PROPERTY, propertyName);
      }
      Property property = consumePropertyNode(edmProperty.getName(), edmProperty.getType(),
          edmProperty.isCollection(), edmProperty.isNullable(), edmProperty.getMaxLength(),
          edmProperty.getPrecision(), edmProperty.getScale(), edmProperty.isUnicode(), edmProperty.getMapping(),
          jsonNode);
      entity.addProperty(property);
      node.remove(propertyName);
    }
  }
}
 
Example 2
Source File: ODataAdapter.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
/**
   * This method updates the entity to the table by invoking ODataDataHandler updateEntityInTable method.
   *
   * @param edmEntityType  EdmEntityType
   * @param entity         entity with changes
   * @param existingEntity existing entity
   * @param merge          PUT/PATCH
   * @throws ODataApplicationException
   * @throws DataServiceFault
   * @see ODataDataHandler#updateEntityInTableTransactional(String, ODataEntry, ODataEntry)
   */
  private boolean updateEntityWithETagMatched(EdmEntityType edmEntityType, Entity entity, Entity existingEntity,
                                              boolean merge) throws ODataApplicationException, DataServiceFault {
/* loop over all properties and replace the values with the values of the given payload
   Note: ignoring ComplexType, as we don't have it in wso2dss oData model */
      List<Property> oldProperties = existingEntity.getProperties();
      ODataEntry newProperties = new ODataEntry();
      Map<String, EdmProperty> propertyMap = new HashMap<>();
      for (String property : edmEntityType.getPropertyNames()) {
          Property updateProperty = entity.getProperty(property);
          EdmProperty propertyType = (EdmProperty) edmEntityType.getProperty(property);
          if (isKey(edmEntityType, property)) {
              propertyMap.put(property, (EdmProperty) edmEntityType.getProperty(property));
              continue;
          }
          // the request payload might not consider ALL properties, so it can be null
          if (updateProperty == null) {
              // if a property has NOT been added to the request payload
              // depending on the HttpMethod, our behavior is different
              if (merge) {
                  // as of the OData spec, in case of PATCH, the existing property is not touched
                  propertyMap.put(property, (EdmProperty) edmEntityType.getProperty(property));
                  continue;
              } else {
                  // as of the OData spec, in case of PUT, the existing property is set to null (or to default value)
                  propertyMap.put(property, (EdmProperty) edmEntityType.getProperty(property));
                  newProperties.addValue(property, null);
                  continue;
              }
          }
          propertyMap.put(property, (EdmProperty) edmEntityType.getProperty(property));
          newProperties.addValue(property, readPrimitiveValueInString(propertyType, updateProperty.getValue()));
      }
      return this.dataHandler.updateEntityInTableTransactional(edmEntityType.getName(),
                                                               wrapPropertiesToDataEntry(edmEntityType, oldProperties,
                                                                                         propertyMap), newProperties);
  }
 
Example 3
Source File: ODataAdapter.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
/**
 * This method updates entity in tables where the request doesn't specify the odata e-tag.
 *
 * @param edmEntityType Entity type
 * @param entity        Entity
 * @param keys          Keys
 * @param merge         Merge
 * @throws DataServiceFault
 * @throws ODataApplicationException
 */
private void updateEntity(EdmEntityType edmEntityType, Entity entity, List<UriParameter> keys, boolean merge)
        throws DataServiceFault, ODataApplicationException {
    ODataEntry entry = new ODataEntry();
    for (UriParameter key : keys) {
        String value = key.getText();
        if (value.startsWith("'") && value.endsWith("'")) {
            value = value.substring(1, value.length() - 1);
        }
        entry.addValue(key.getName(), value);
    }
    for (String property : edmEntityType.getPropertyNames()) {
        Property updateProperty = entity.getProperty(property);
        if (isKey(edmEntityType, property)) {
            continue;
        }
        // the request payload might not consider ALL properties, so it can be null
        if (updateProperty == null) {
            // if a property has NOT been added to the request payload
            // depending on the HttpMethod, our behavior is different
            if (merge) {
                // as of the OData spec, in case of PATCH, the existing property is not touched
                continue;
            } else {
                // as of the OData spec, in case of PUT, the existing property is set to null (or to default value)
                entry.addValue(property, null);
                continue;
            }
        }
        EdmProperty propertyType = (EdmProperty) edmEntityType.getProperty(property);
        entry.addValue(property, readPrimitiveValueInString(propertyType, updateProperty.getValue()));
    }
    this.dataHandler.updateEntityInTable(edmEntityType.getName(), entry);
}
 
Example 4
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);
}