Java Code Examples for org.apache.olingo.odata2.api.edm.EdmProperty#getName()

The following examples show how to use org.apache.olingo.odata2.api.edm.EdmProperty#getName() . 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 6 votes vote down vote up
/**
 * Does the navigation and calls {@link AbstractEntity#getProperty(String)}.
 * @param uri_info contains the navigation segments and the name of the property to get.
 * @return the value of requested property (may be null).
 * @throws ODataException
 */
public Object readPropertyValue(GetSimplePropertyUriInfo uri_info)
      throws ODataException
{
   KeyPredicate startKP = uri_info.getKeyPredicates().get(0);
   EdmProperty target
         = uri_info.getPropertyPath()
         .get(uri_info.getPropertyPath().size() - 1);

   T t = Navigator.<T>navigate(uri_info.getStartEntitySet(), startKP,
         uri_info.getNavigationSegments(), null);

   // Case of complex property
   String propName = target.getName();
   if (uri_info.getPropertyPath().size() > 1)
   {
      return t.getComplexProperty(
            uri_info.getPropertyPath().get(0).getName()).get(propName);
   }
   return t.getProperty(propName);
}
 
Example 2
Source File: ODataExpressionParser.java    From olingo-odata2 with Apache License 2.0 6 votes vote down vote up
public static String parseKeyPropertiesToJPAOrderByExpression(
    final List<EdmProperty> edmPropertylist, final String tableAlias) throws ODataJPARuntimeException {
  String propertyName = null;
  String orderExpression = "";
  if (edmPropertylist == null) {
    return orderExpression;
  }
  for (EdmProperty edmProperty : edmPropertylist) {
    try {
      EdmMapping mapping = edmProperty.getMapping();
      if (mapping != null && mapping.getInternalName() != null) {
        propertyName = mapping.getInternalName();// For embedded/complex keys
      } else {
        propertyName = edmProperty.getName();
      }
    } catch (EdmException e) {
      throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
    }
    orderExpression += tableAlias + JPQLStatement.DELIMITER.PERIOD + propertyName + " , ";
  }
  return normalizeOrderByExpression(orderExpression);
}
 
Example 3
Source File: ODataClient.java    From DataHubSystem with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Makes the key predicate for the given Entity and EntitySet.
 * 
 * @param entity_set the EntitySet
 * @param entity an entity whose key property values will be used to make
 *    the key predicate.
 * @return a comma separated list of key=value couples.
 * @throws EdmException not likely to happen.
 */
public String makeKeyPredicate(EdmEntitySet entity_set, ODataEntry entity)
   throws EdmException
{
   if (entity_set == null)
      throw new IllegalArgumentException ("entity_set must not be null.");

   if (entity == null)
      throw new IllegalArgumentException ("entity must not be null.");
   
   List<EdmProperty> edm_props = entity_set.getEntityType ()
      .getKeyProperties ();
   
   StringBuilder sb = new StringBuilder ();
   
   for (EdmProperty edm_prop: edm_props)
   {
      String key_prop_name = edm_prop.getName ();
      Object key_prop_val = entity.getProperties ().get (key_prop_name);
      
      if (sb.length () > 0) sb.append(',');
      
      sb.append (key_prop_name).append ('=');
      
      if (key_prop_val instanceof String)
         sb.append ('\'').append (key_prop_val).append ('\'');
      else
         sb.append (key_prop_val);
   }
   
   return sb.toString ();
}
 
Example 4
Source File: EntityPropertyInfo.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
static EntityPropertyInfo create(final EdmProperty property) throws EdmException {
  return new EntityPropertyInfo(
      property.getName(),
      property.getType(),
      property.getFacets(),
      property.getCustomizableFeedMappings(),
      property.getMimeType(),
      property.getMapping());
}
 
Example 5
Source File: EntityComplexPropertyInfo.java    From olingo-odata2 with Apache License 2.0 5 votes vote down vote up
static EntityComplexPropertyInfo create(final EdmProperty property, final List<String> propertyNames,
    final Map<String, EntityPropertyInfo> childEntityInfos) throws EdmException {
  List<EntityPropertyInfo> childEntityInfoList = new ArrayList<EntityPropertyInfo>(childEntityInfos.size());
  for (String name : propertyNames) {
    childEntityInfoList.add(childEntityInfos.get(name));
  }

  EntityComplexPropertyInfo info = new EntityComplexPropertyInfo(
      property.getName(),
      property.getType(),
      property.getFacets(),
      property.getCustomizableFeedMappings(),
      childEntityInfoList);
  return info;
}
 
Example 6
Source File: BeanPropertyAccess.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
private String getGetterMethodName(final EdmProperty property) throws EdmException {
  final String prefix = isBooleanProperty(property) ? "is" : "get";
  final String defaultMethodName = prefix + property.getName();
  return property.getMapping() == null || property.getMapping().getInternalName() == null ?
      defaultMethodName : property.getMapping().getInternalName();
}
 
Example 7
Source File: JPAEntity.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
protected void setEmbeddableKeyProperty(final HashMap<String, String> embeddableKeys,
    final List<EdmProperty> oDataEntryKeyProperties,
    final Map<String, Object> oDataEntryProperties, final Object entity)
    throws ODataJPARuntimeException, EdmException, IllegalAccessException, IllegalArgumentException,
    InvocationTargetException, InstantiationException {

  HashMap<String, Object> embeddableObjMap = new HashMap<String, Object>();
  List<EdmProperty> leftODataEntryKeyProperties = new ArrayList<EdmProperty>();
  HashMap<String, String> leftEmbeddableKeys = new HashMap<String, String>();

  for (EdmProperty edmProperty : oDataEntryKeyProperties) {
    if (oDataEntryProperties.containsKey(edmProperty.getName()) == false) {
      continue;
    }

    String edmPropertyName = edmProperty.getName();
    String embeddableKeyNameComposite = embeddableKeys.get(edmPropertyName);
    if (embeddableKeyNameComposite == null) {
      continue;
    }
    String embeddableKeyNameSplit[] = embeddableKeyNameComposite.split("\\.");
    String methodPartName = null;
    Method method = null;
    Object embeddableObj = null;

    if (embeddableObjMap.containsKey(embeddableKeyNameSplit[0]) == false) {
      methodPartName = embeddableKeyNameSplit[0];
      method = jpaEntityParser.getAccessModifierSet(entity, methodPartName);
      embeddableObj = method.getParameterTypes()[0].newInstance();
      method.invoke(entity, embeddableObj);
      embeddableObjMap.put(embeddableKeyNameSplit[0], embeddableObj);
    } else {
      embeddableObj = embeddableObjMap.get(embeddableKeyNameSplit[0]);
    }

    if (embeddableKeyNameSplit.length == 2) {
      methodPartName = embeddableKeyNameSplit[1];
      method = jpaEntityParser.getAccessModifierSet(embeddableObj, methodPartName);
      Object simpleObj = oDataEntryProperties.get(edmProperty.getName());
      method.invoke(embeddableObj, simpleObj);
    } else if (embeddableKeyNameSplit.length > 2) { // Deeply nested
      leftODataEntryKeyProperties.add(edmProperty);
      leftEmbeddableKeys
          .put(edmPropertyName, embeddableKeyNameComposite.split(embeddableKeyNameSplit[0] + ".", 2)[1]);
    }
  }
}
 
Example 8
Source File: BeanPropertyAccess.java    From olingo-odata2 with Apache License 2.0 4 votes vote down vote up
private String getGetterMethodName(final EdmProperty property) throws EdmException {
  final String prefix = isBooleanProperty(property) ? "is" : "get";
  final String defaultMethodName = prefix + property.getName();
  return property.getMapping() == null || property.getMapping().getInternalName() == null ?
      defaultMethodName : property.getMapping().getInternalName();
}