Java Code Examples for org.apache.olingo.odata2.api.uri.UriInfo#getStartEntitySet()

The following examples show how to use org.apache.olingo.odata2.api.uri.UriInfo#getStartEntitySet() . 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: Processor.java    From DataHubSystem with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Extract the 'From' ES of an EntityLink.
 * @param uri_info path to resource, eg: /Collections(10)/$links/Products
 * @returns the EntitySet of the nav segment before the "$link" segment.
 */
private EdmEntitySet getLinkFromES(UriInfo uri_info)
{
   EdmEntitySet res;
   /* `uri_info`:
    * StartEntitySet/Foo/bar/baz/$links/TargetEntitySet
    *               \__________/       \______________/
    *                      Navigation Segments          */

   List<NavigationSegment> navsegs = uri_info.getNavigationSegments();

   if (navsegs.size() >= 2) // `navsegs` contains at least the target segment
   {
       res = navsegs.get(navsegs.size()-1).getEntitySet();
   }
   else
   {
      res = uri_info.getStartEntitySet();
   }
   return res;
}
 
Example 2
Source File: Ingest.java    From DataHubSystem with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void updateFromEntry(ODataEntry entry) throws ODataException
{
   Map<String, Object> props = entry.getProperties();

   String fname = (String)props.remove(FILENAME);
   if (this.filename == null && (fname == null || fname.isEmpty()))
   {
      throw new IncompleteDocException("Property filename required");
   }
   this.filename = fname;

   for (Map.Entry<String, Object> unkn: props.entrySet())
   {
      switch (unkn.getKey())
      {
         case ID:
         case STATUS:
         case STATUS_DATE:
         case STATUS_MESSAGE:
            LOGGER.warn("Property " + unkn.getKey() + " is read-only");
            break;
         default:
            LOGGER.warn("Unknown property " + unkn.getKey());
      }
   }

   List<String> target_collections = entry.getMetadata().getAssociationUris(TARGET_COLLECTIONS);
   if (target_collections.size() > 0)
   {
      Edm edm = RuntimeDelegate.createEdm(new Model());
      UriParser urip = RuntimeDelegate.getUriParser(edm);

      for (String target_collection: target_collections)
      {
         List<PathSegment> path_segments = new ArrayList<>();
         StringTokenizer st = new StringTokenizer(target_collection, "/");
         while (st.hasMoreTokens ())
         {
            path_segments.add(UriParser.createPathSegment(st.nextToken(), null));
         }
         UriInfo uinfo = urip.parse(path_segments, Collections.EMPTY_MAP);

         EdmEntitySet sync_ees = uinfo.getStartEntitySet();
         KeyPredicate kp = uinfo.getKeyPredicates().get(0);
         List<NavigationSegment> ns_l = uinfo.getNavigationSegments();

         Collection coll = Navigator.<Collection>navigate(sync_ees, kp, ns_l, Collection.class);
         if (coll == null)
         {
            throw new ODataException("Target collection not found: " + target_collection);
         }

         targetCollections.put(coll.getName(), coll);
      }
   }

   // Ingesting ...
   LOGGER.info(String.format("Ingesting product %s (IngestId=%d md5=%s) uploaded by %s",
         filename, id, md5, uploader.getUsername()));

   List<fr.gael.dhus.database.object.Collection> collections =
         new ArrayList<>(targetCollections.size());
   for (Collection c: targetCollections.values())
   {
      collections.add(COLLECTION_SERVICE.getCollection(c.getUUID()));
   }

   Path pname = temp_file.resolveSibling(filename);
   try
   {
      Files.move(temp_file, pname);
      temp_file = pname;
      URL purl = pname.toUri().toURL();
      fr.gael.dhus.database.object.Product p = PRODUCT_SERVICE.addProduct (
            purl, uploader, purl.toString ());
      PRODUCT_SERVICE.processProduct (p, uploader, collections, null, null);
   }
   catch (IOException ex)
   {
      LOGGER.error("Cannot ingest product", ex);
      status = Status.ERROR;
      statusMessage = ex.getMessage();
      throw new ODataException("Cannot ingest product", ex);
   }
   setStatus(Status.INGESTED);
}
 
Example 3
Source File: Synchronizer.java    From DataHubSystem with GNU Affero General Public License v3.0 4 votes vote down vote up
private static Collection getTargetCollection(ODataEntry entry)
   throws ODataException
{
   String navLinkName = SynchronizerEntitySet.TARGET_COLLECTION;
   List<String> nll = entry.getMetadata ().getAssociationUris (navLinkName);

   if (nll != null && !nll.isEmpty ())
   {
      if (nll.size () > 1)
      {
         throw new ODataException (
            "A synchronizer accepts only one collection");
      }
      String uri = nll.get(0);
      // Nullifying
      if (uri == null || uri.isEmpty())
      {
         return null;
      }

      Edm edm = RuntimeDelegate.createEdm(new Model());
      UriParser urip = RuntimeDelegate.getUriParser (edm);

      List<PathSegment> path_segments = new ArrayList<> ();

      StringTokenizer st = new StringTokenizer (uri, "/");

      while (st.hasMoreTokens ())
      {
         path_segments.add (UriParser.createPathSegment (st.nextToken (),
            null));
      }

      UriInfo uinfo =
         urip
            .parse (path_segments, Collections.<String, String> emptyMap ());

      EdmEntitySet sync_ees = uinfo.getStartEntitySet ();
      KeyPredicate kp = uinfo.getKeyPredicates ().get (0);
      List<NavigationSegment> ns_l = uinfo.getNavigationSegments ();

      Collection c = Navigator.<Collection>navigate(sync_ees, kp, ns_l, Collection.class);

      return c;
   }

   return null;
}