Package org.atomojo.app.db

Examples of org.atomojo.app.db.Feed


      loadedAt = System.currentTimeMillis();
      Iterator<TermInstance<Entry>> entries = atomDB.getEntriesByTerm(queryTerm);
      while (entries.hasNext()) {
         Entry entry = entries.next().getTarget();
         getContext().getLogger().info("Query entry: "+entry.getUUID());
         Feed feed = entry.getFeed();
         Iterator<EntryMedia> media = entry.getResources();
         if (media.hasNext()) {
            Storage.Query query = storage.getQuery(feed.getPath(),feed.getUUID(),media.next().getName());
            if (query!=null) {
               getContext().getLogger().info("Query found...");
               TermInstance<Entry> nameT = entry.getTerm(nameTerm);
               TermInstance<Entry> useCollectionT = entry.getTerm(collectionTerm);
               TermInstance<Entry> mediaTypeT = entry.getTerm(mediaTypeTerm);
View Full Code Here


         }
      } else {
         String [] segments = uriPath.split("/");
         String queryName = segments[0];
         try {
            Feed feed = atomDB.findFeedByPath(segments,1,segments.length-1);
            if (feed==null) {
               return null;
            }
            if (loadedAt<0 || System.currentTimeMillis()>(loadedAt+expiration)) {
               loadQueries();
View Full Code Here

         }
      };
     
      Iterator<Feed> roots = db.getRootFeeds();
      while (roots.hasNext()) {
         Feed root = roots.next();
         backup(context,root);
      }
   }
View Full Code Here

            zipStream.closeEntry();
         }
      };
      Iterator<Feed> roots = db.getRootFeeds();
      while (roots.hasNext()) {
         Feed root = roots.next();
         backup(context,root);
      }
      zipStream.close();
   }
View Full Code Here

            }
         }
        
         Iterator<Feed> children = feed.getChildren();
         while (children.hasNext()) {
            Feed child = children.next();
            backup(context,child);
         }
      } else {
         throw new IOException("Cannot get feed representation for path "+fpath);
      }
View Full Code Here

         Term dbTerm = app.getDB().findTerm(term);
         if (dbTerm!=null) {
            Iterator<TermInstance<Feed>> feeds = app.getDB().getFeedsByTerm(dbTerm,value);
            while (feeds.hasNext()) {
               TermInstance<Feed> termValue = feeds.next();
               Feed feed = termValue.getTarget();
               dest.send(constructor.createCharacters("\n"));
               dest.send(constructor.createElement(AtomResource.ENTRY_NAME));
               text(constructor,dest,AtomResource.ID_NAME,feed.getUUID().toString());
               text(constructor,dest,AtomResource.PUBLISHED_NAME,AtomResource.toXSDDate(feed.getCreated()));
               text(constructor,dest,AtomResource.UPDATED_NAME,AtomResource.toXSDDate(feed.getEdited()));
               text(constructor,dest,AtomResource.TITLE_NAME,app.getStorage().getFeedTitle(feed.getPath(),feed.getUUID()));
               term(constructor,dest,Categorization.FEED_TYPE_TERM,null);
               Iterator<TermInstance<Feed>> terms = feed.getTerms();
               while (terms.hasNext()) {
                  TermInstance<Feed> fterm = terms.next();
                  term(constructor,dest,fterm.getTerm().getURI(),fterm.getValue());
               }
               link(constructor,dest,"related",resourceBase+feed.getPath());
               dest.send(constructor.createElementEnd(AtomResource.ENTRY_NAME));
            }
            DocumentLoader loader = new SAXDocumentLoader();
            Iterator<TermInstance<Entry>> entries = app.getDB().getEntriesByTerm(dbTerm,value);
            while (entries.hasNext()) {
               TermInstance<Entry> termValue = entries.next();
               Entry entry = termValue.getTarget();
               Feed feed = entry.getFeed();
               String feedPath = feed.getPath();
               String feedBaseURI = resourceBase.toString()+feedPath;
               dest.send(constructor.createCharacters("\n"));

               // get the entry representation
               Representation rep = app.getStorage().getEntry(feedBaseURI,feedPath,feed.getUUID(),entry.getUUID());
              
               // avoid thread creation because reading an output representation requires a thread
               StringWriter sw = new StringWriter();
               rep.write(sw);
               rep.release();
View Full Code Here

            public void onEndWorkspace() {
               log.info("Workspace ended.");
               if (!additive) {
                  log.info("Removing extra feeds.");
                  try {
                     Feed root = db.getRoot();
                     if (root!=null) {
                        checkFeedInSync(root,paths);
                     }
                  } catch (Exception ex) {
                     log.log(Level.SEVERE,"Error while processing additive=false check.",ex);
View Full Code Here

            entries = db.getJournal().getUpdatesSince(lastSync,syncTime);
            while (entries.hasNext()) {

               Journal.UpdatedEntry updateEntry = (Journal.UpdatedEntry)entries.next();

               Feed feed = updateEntry.getFeed();
               Entry entry = updateEntry.getEntry();
               String path = feed.getPath();
               if (path.length()>0 && !path.endsWith("/")) {
                  path += "/";
               }
               URI feedURI = proc.getRemoteApp().getRoot().resolve(path);
               FeedClient appClient = new FeedClient(feedURI);
               if (auth!=null) {
                  appClient.setIdentity(auth.getName(),auth.getPassword());
               }


               if (updateEntry.getOperation()==Journal.CREATE_OPERATION) {
                  // Create feed or entry
                  if (entry==null) {
                     // Create feed
                     log.info("Creating feed "+feedURI);
                     try {
                        Representation feedRep = storage.getFeed(path,feed.getUUID(),feed.getEntries());
                        // Now, create the feed with the XML
                        try {
                           String xml = feedRep.getText();
                           if (!appClient.create(xml).isSuccess()) {
                              errorCount++;
                              log.severe("Cannot create feed on target for path "+path);
                              throw new SyncException("Synchronization was incomplete.  Stopped due to failure to create feed: "+path);
                           }
                        } catch (IOException ex) {
                           errorCount++;
                           log.log(Level.SEVERE,"Cannot get xml serialization of feed document for path "+path,ex);
                           throw new SyncException("Synchronization was incomplete.  Stopped due to failure of serialization at path "+path);
                        }
                     } catch (IOException ex) {
                        errorCount++;
                        log.log(Level.SEVERE,"Cannot get feed document for path "+path,ex);
                        throw new SyncException("Synchronization was incomplete.  Stopped due failure to get feed at "+path);
                     }
                  } else {
                     // Create entry

                     log.info("Creating entry "+entry.getUUID()+" for feed "+feedURI);

                     // Check for media entries
                     Iterator<EntryMedia> media = entry.getResources();
                     if (media.hasNext()) {

                        // We have a media entry and so we post the media first
                        EntryMedia resource = media.next();
                        if (media.hasNext()) {
                           while (media.hasNext()) {
                              media.next();
                           }
                           errorCount++;
                           log.severe("Media entries with more than one resource is not supported.");
                           throw new SyncException("Synchronization was incomplete.  Media entry for entry "+entry.getUUID()+" has more than one resource.");
                        }

                        // Get the media from the XML DB
                        try {
                           Representation rep = storage.getMedia(path,feed.getUUID(),resource.getName());
                           // Send the media to the server
                           rep.setMediaType(resource.getMediaType());
                           appClient.createMedia(entry.getUUID(),resource.getName(),rep);
                        } catch (StatusException ex) {
                           errorCount++;
                           log.severe("Cannot update media "+resource.getName()+" on target for path "+path+", status="+ex.getStatus().getCode());
                           throw new SyncException("Synchronization was incomplete.  Failure to update media "+resource.getName()+" for entry "+entry.getUUID()+", status="+ex.getStatus().getCode());
                        } catch (Exception ex) {
                           errorCount++;
                           log.log(Level.SEVERE,"Cannot get media "+resource.getName()+" for path "+path+" and id "+entry.getUUID().toString(),ex);
                           throw new SyncException("Synchronization was incomplete.  Failure to get media "+resource.getName()+" for entry "+entry.getUUID());
                        }
                     } else {

                        String xml = null;
                        // Get the entry document from the XML DB
                        try {
                           Representation entryRep = storage.getEntry(".",path,feed.getUUID(),entry.getUUID());

                           // Now, create the feed with the XML
                           try {
                              xml = entryRep.getText();
                           } catch (IOException ex) {
                              errorCount++;
                              log.log(Level.SEVERE,"Cannot get xml serialization of entry document for path "+path,ex);
                              throw new SyncException("Synchronization was incomplete.  Failure to get serialization of entry "+entry.getUUID());
                           }
                        } catch (IOException ex) {
                           errorCount++;
                           log.log(Level.SEVERE,"Cannot get entry document for path "+path+" and id "+entry.getUUID().toString(),ex);
                           throw new SyncException("Synchronization was incomplete.  Failure to get entry "+entry.getUUID());
                        }

                        // This is a regular entry
                        try {
                           appClient.createEntry(xml);
                        } catch (Exception ex) {
                           errorCount++;
                           log.severe("Cannot create entry on target for path "+path);
                           throw new SyncException("Synchronization was incomplete.  Failure to create entry "+entry.getUUID()+" for path "+path);
                        }
                     }
                  }
               } else {
                  EntryMedia resource = updateEntry.getResource();
                  if (entry==null) {
                     // Modify feed
                     log.info("Updating feed "+feedURI);
                     // Get the feed document from the XML DB
                     try {
                        Representation feedRep = storage.getFeed(path,feed.getUUID(),feed.getEntries());

                        // Now, create the feed with the XML
                        try {
                           String xml = feedRep.getText();
                           if (!appClient.update(xml).isSuccess()) {
                              errorCount++;
                              log.severe("Cannot update feed on target for path "+path);
                              throw new SyncException("Synchronization was incomplete.  Cannot update feed for path "+path);
                           }
                        } catch (IOException ex) {
                           errorCount++;
                           log.log(Level.SEVERE,"Cannot get xml serialization of feed document for path "+path,ex);
                           throw new SyncException("Synchronization was incomplete.  Cannot get serialization of feed for path "+path);
                        }
                     } catch (IOException ex) {
                        errorCount++;
                        log.log(Level.SEVERE,"Cannot get feed document for path "+path,ex);
                        throw new SyncException("Synchronization was incomplete.  Cannot get feed for path "+path);
                     }
                  } else if (resource==null) {
                     // Modify entry
                     log.info("Updating entry "+entry.getUUID()+" for feed "+feedURI);

                     // Get the entry document from the XML DB
                     try {
                        Representation entryRep = storage.getEntry(".",path,feed.getUUID(),entry.getUUID());

                        // Now, create the feed with the XML
                        try {
                           String xml = entryRep.getText();
                           if (!appClient.updateEntry(entry.getUUID(),xml).isSuccess()) {
                              errorCount++;
                              log.severe("Cannot update entry on target for path "+path);
                              throw new SyncException("Synchronization was incomplete.  Cannot update entry "+entry.getUUID()+" for path"+path);
                           }
                        } catch (IOException ex) {
                           errorCount++;
                           log.log(Level.SEVERE,"Cannot get xml serialization of entry document for path "+path,ex);
                           throw new SyncException("Synchronization was incomplete.  Cannot serialization of entry "+entry.getUUID()+" for path"+path);
                        }
                     } catch (IOException ex) {
                        errorCount++;
                        log.log(Level.SEVERE,"Cannot get entry document for path "+path+" and id "+entry.getUUID().toString(),ex);
                        throw new SyncException("Synchronization was incomplete.  Cannot get entry "+entry.getUUID()+" for path"+path);
                     }
                  } else {
                     // Modify resource
                     log.info("Updating resource "+resource.getName()+" for entry "+entry.getUUID()+" for feed "+feedURI);

                     // Get the media from the XML DB
                     try {
                        Representation mediaRep = storage.getMedia(path,feed.getUUID(),resource.getName());
                        mediaRep.setMediaType(resource.getMediaType());
                        if (!appClient.updateMedia(resource.getName(),mediaRep).isSuccess()) {
                           errorCount++;
                           log.severe("Cannot update media "+resource.getName()+" on target for path "+path);
                           throw new SyncException("Synchronization was incomplete.  Cannot update media "+resource.getName()+" for entry "+entry.getUUID()+" for path"+path);
View Full Code Here

      try {
         // get the feed document without the entries
         Document feedDoc = parser.load(app.getStorage().getFeedHead(source.getPath(), source.getUUID()));

         // Create the feed.  The ID will be changed since the feed exits
         Feed newFeed = app.createFeed(parent.getPath()+name, feedDoc);
        
         // copy the entries
         Iterator<Entry> entries = source.getEntries();
         while (entries.hasNext()) {
            Entry entry = entries.next();
            Document entryDoc = parser.load(app.getEntryRepresentation("", entry));
            Iterator<EntryMedia> mediaResources = entry.getResources();
            if (mediaResources.hasNext()) {
               // we have a media entry and so copy the media
               EntryMedia media = mediaResources.next();
               Representation mediaRep = app.getStorage().getMedia(source.getPath(), source.getUUID(), media.getName());
               Entry newEntry = app.createMediaEntry(user,newFeed,mediaRep,media.getName(),UUID.randomUUID());
               app.updateEntry(user,newFeed,newEntry,entryDoc);
               // TODO: copy multiple media ?
            } else {
               // Just copy the entry.  The ID will be changed since the entry exists
               app.createEntry(user, newFeed, entryDoc);
            }
         }
        
         // copy the sub feeds
         Iterator<Feed> children = source.getChildren();
         while (children.hasNext()) {
            Feed child = children.next();
            copy(child,newFeed,child.getName());
         }
      } catch (SQLException ex) {
         errors.add(ex.getMessage());
      } catch (IOException ex) {
         errors.add(ex.getMessage());
View Full Code Here

         int h = path.indexOf('#');
         if (h>=0) {
            path = path.substring(0,h);
         }
         final DB atomDB = (DB)getContext().getAttributes().get(AtomApplication.DB_ATTR);
         Feed feed = null;
         if (path.length()>0) {
            String [] segments = path.split("/");
            feed = atomDB.findFeedByPath(segments);
            if (feed==null) {
               getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);
               return new StringRepresentation("No feed found at path: "+path);
            }
         }
         Form form = getRequest().getResourceRef().getQueryAsForm();
         String sinceS = form.getFirstValue("since");
         Date since = null;
         if (sinceS!=null && sinceS.length()>0) {
            try {
               since = AtomResource.fromXSDDate(sinceS);
            } catch (ParseException ex) {
               getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
               return new StringRepresentation("Bad since value '"+sinceS+"': "+ex.getMessage());
            }
         }
         String limitS = form.getFirstValue("limit");
         int limit = 100;
         if (limitS!=null && limitS.length()>0) {
            try {
               limit = Integer.parseInt(limitS);
            } catch (NumberFormatException  ex) {
               getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
               return new StringRepresentation("Bad limit value '"+limitS+"': "+ex.getMessage());
            }
         }
         String startS = form.getFirstValue("start");
         int start = 1;
         if (startS!=null && startS.length()>0) {
            try {
               start = Integer.parseInt(startS);
            } catch (NumberFormatException  ex) {
               getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
               return new StringRepresentation("Bad start value '"+startS+"': "+ex.getMessage());
            }
         }
         final int startRow = start;
         final int limitCount = limit;
         final Date sinceMarker = since==null ? new Date() : since;
         final Feed target = feed;
         return new OutputRepresentation(MediaType.APPLICATION_ATOM) {
            public void write(OutputStream os)
               throws IOException
            {
               setCharacterSet(CharacterSet.UTF_8);
View Full Code Here

TOP

Related Classes of org.atomojo.app.db.Feed

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.