Java Code Examples for org.apache.olingo.odata2.api.uri.KeyPredicate#getLiteral()

The following examples show how to use org.apache.olingo.odata2.api.uri.KeyPredicate#getLiteral() . 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: Ingest.java    From DataHubSystem with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public Object navigate(NavigationSegment ns) throws ODataException
{
   Object res;

   EdmEntitySet es = ns.getEntitySet();
   if (es.getName().equals(Model.USER.getName()))
   {
      res = new User(uploader); // one to one
   }
   else if (es.getName().equals(Model.COLLECTION.getName()))
   {
      if (ns.getKeyPredicates().isEmpty())
      {
         res = Collections.unmodifiableMap(targetCollections);
      }
      else
      {
         KeyPredicate kp = ns.getKeyPredicates().get(0);
         res = this.targetCollections.get(kp.getLiteral());
         if (res == null)
         {
            throw new InvalidKeyException(kp.getLiteral(), ns.getEntitySet().getName());
         }
      }
   }
   else
   {
      throw new InvalidTargetException(this.getClass().getSimpleName(), ns.getEntitySet().getName());
   }
   return res;
}
 
Example 2
Source File: Navigator.java    From DataHubSystem with GNU Affero General Public License v3.0 4 votes vote down vote up
/**
 * Reads the navigation segments and recursively digs deeper in the data. Can
 * return a Map<Key, Product|Collection|Node|Attribute> for EntitySets, a
 * Product, Collection, Node, Attribute for Entities, a Int, Long, String,
 * Date, Float, Double, ... for Properties.
 *
 * @param <E> return type.
 *
 * @param collection the first segment (as defined in the OData v2 spec).
 * @param collec_kp the KeyPredicate for the collection param.
 * @param nav_segments A list of NavigationSegment.
 * @param return_type the type of returned object (may be null).
 *
 * @return a non-null instance of the returnType.
 *
 * @throws IllegalArgumentException if one or more arg is null.
 * @throws ODataException if not able to return an instance.
 */
@SuppressWarnings("unchecked")
public static <E> E navigate(EdmEntitySet collection, KeyPredicate collec_kp,
      List<NavigationSegment> nav_segments, Class<? extends E> return_type) throws ODataException
{
   Object result;

   AbstractEntitySet entity_set = Model.getEntitySet(collection.getName());
   if (collec_kp != null) // Start is an Entity
   {
      AbstractEntity entity = entity_set.getEntity(collec_kp);
      if (entity == null)
      {
         throw new InvalidKeyException(collec_kp.getLiteral(), entity_set.getName());
      }

      result = entity;
      Iterator<NavigationSegment> it = nav_segments.iterator();
      while (it.hasNext())
      {
         result = entity.navigate(it.next());
         if (result instanceof AbstractEntity)
         {
            entity = AbstractEntity.class.cast(result);
         }
         else if (it.hasNext())
         {
            throw new ExpectedException("Unexpected nav segment " + it.next().toString());
         }
      }
   }
   else // Start is an EntitySet (no further navigation required)
   {
      result = entity_set.getEntities();
   }

   // Returns the result casted into a returnType object
   if (result == null)
   {
      throw new ExpectedException("Navigation failed (result is null)");
   }

   try
   {
      if (return_type != null)
      {
         return return_type.cast(result);
      }
      return (E) result;
   }
   catch (ClassCastException e)
   {
      throw new ODataException(e);
   }

}
 
Example 3
Source File: ClassEntitySet.java    From DataHubSystem with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public AbstractEntity getEntity(KeyPredicate kp)
{
   String key = kp.getLiteral();
   return (new ClassMap()).get(key);
}