Package org.atomojo.app.db

Examples of org.atomojo.app.db.Feed


         }
         int q = uriPath.indexOf('?');
         if (q>=0) {
            uriPath = uriPath.substring(0,q);
         }
         Feed f = app.getFeed(uriPath);
         if (f==null) {
            getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);
            return null;
         }
         Form parameters = getRequest().getResourceRef().getQueryAsForm();
         Map<String,String> queryParameters = null;
         if (parameters!=null && parameters.size()>0) {
            queryParameters = new TreeMap<String,String>();
            for (String name : parameters.getNames()) {
               queryParameters.put(name,parameters.getValues(name));
            }
         }
         Representation result = storage.queryCollection(uriPath, f.getUUID(), query, queryParameters);
         result.setMediaType(MediaType.APPLICATION_XML);
         getResponse().setStatus(Status.SUCCESS_OK);
         return result;
      } catch (AppException ex) {
         if (ex.getStatus()!=null && ex.getStatus().getCode()==404) {
View Full Code Here


         throw new XMLException("Exception while getting categorization.",ex);
        
      }
      try {
         List<Feed> ancestors = new ArrayList<Feed>();
         Feed parent = feed;
         do {
            parent = parent.getParent();
            if (parent!=null) {
               ancestors.add(parent);
            }
         } while (parent!=null);
         Collections.reverse(ancestors);
         for (Feed ancestor : ancestors) {
            org.atomojo.app.client.Feed feedRep = new org.atomojo.app.client.Feed(xmlParser.load(storage.getFeedHead(ancestor.getPath(), ancestor.getUUID())));
            dest.send(constructor.createElement(AtomResource.ENTRY_NAME));
            text(constructor,dest,AtomResource.ID_NAME,ancestor.getUUID().toString());
            text(constructor,dest,AtomResource.PUBLISHED_NAME,AtomResource.toXSDDate(ancestor.getCreated()));
            text(constructor,dest,AtomResource.UPDATED_NAME,AtomResource.toXSDDate(ancestor.getEdited()));
            text(constructor,dest,AtomResource.TITLE_NAME,feedRep.getTitle());
            String summary = feedRep.getSummary();
            if (summary!=null) {
               text(constructor,dest,AtomResource.SUMMARY_NAME,summary);
            }
            term(constructor,dest,Categorization.ANCESTOR_TERM,null);
            Iterator<TermInstance<Feed>> categorization = ancestor.getTerms();
            while (categorization.hasNext()) {
               TermInstance<Feed> category = categorization.next();
               term(constructor,dest,category.getTerm().getURI(),category.getValue());

            }
            link(constructor,dest,"related",resourceBase+ancestor.getPath());
            dest.send(constructor.createElementEnd(AtomResource.ENTRY_NAME));
         }
      } catch (Exception ex) {
         throw new XMLException("Exception while getting ancestors.",ex);
      }
      try {
         Term hidden = feed.getDB().findTerm(Categorization.HIDDEN_TYPE_TERM);
         if (hidden==null) {
            hidden = feed.getDB().createTerm(Categorization.HIDDEN_TYPE_TERM);
         }
         Iterator<Feed> children = feed.getChildren();
         while (children.hasNext()) {
            Feed child = children.next();
            if (child.getTerm(hidden)!=null) {
               continue;
            }
            org.atomojo.app.client.Feed feedRep = new org.atomojo.app.client.Feed(xmlParser.load(storage.getFeedHead(child.getPath(), child.getUUID())));
            dest.send(constructor.createElement(AtomResource.ENTRY_NAME));
            text(constructor,dest,AtomResource.ID_NAME,child.getUUID().toString());
            text(constructor,dest,AtomResource.PUBLISHED_NAME,AtomResource.toXSDDate(child.getCreated()));
            text(constructor,dest,AtomResource.UPDATED_NAME,AtomResource.toXSDDate(child.getEdited()));
            text(constructor,dest,AtomResource.TITLE_NAME,feedRep.getTitle());
            String summary = feedRep.getSummary();
            if (summary!=null) {
               text(constructor,dest,AtomResource.SUMMARY_NAME,summary);
            }
            term(constructor,dest,Categorization.CHILD_TERM,null);
            Iterator<TermInstance<Feed>> categorization = child.getTerms();
            while (categorization.hasNext()) {
               TermInstance<Feed> category = categorization.next();
               term(constructor,dest,category.getTerm().getURI(),category.getValue());

            }
            link(constructor,dest,"related",feedRef.toString()+child.getName()+"/");
            dest.send(constructor.createElementEnd(AtomResource.ENTRY_NAME));
         }
        
      } catch (Exception ex) {
         throw new XMLException("Exception while getting feed children.",ex);
View Full Code Here

            // The form /I/{feed-id}/_/{entry-id}
            if (!segments[1].equals("_")) {
               return null;
            }
            UUID feedId = UUID.fromString(segments[0]);
            Feed f = atomDB.findFeed(feedId);
            if (f==null) {
               return null;
            }
            UUID entryId = UUID.fromString(segments[2]);
            if (feedRoot.isAbsolute()) {
               ref = new Reference(feedRoot+f.getPath()+"_/"+entryId);
            } else {
               ref = new Reference(request.getRootRef().toString()+feedRoot+f.getPath()+"_/"+entryId);
            }
         } else if (segments.length==2) {
            // The form /I/{feed-id}/{resource}
            if (segments[1].equals("_")) {
               return null;
            }
            UUID feedId = UUID.fromString(segments[0]);
            Feed f = atomDB.findFeed(feedId);
            if (f==null) {
               return null;
            }
            if (feedRoot.isAbsolute()) {
               ref = new Reference(feedRoot+f.getPath()+segments[1]);
            } else {
               ref = new Reference(request.getRootRef().toString()+feedRoot+f.getPath()+segments[1]);
            }
         } else if (segments.length==1) {
            UUID feedId = UUID.fromString(segments[0]);
            // The form /I/{feed-id}
            Feed f = atomDB.findFeed(feedId);
            if (f==null) {
               return null;
            }
            if (feedRoot.isAbsolute()) {
               ref = new Reference(feedRoot+f.getPath());
            } else {
               ref = new Reference(request.getRootRef().toString()+feedRoot+f.getPath());
            }
         }
         getContext().getLogger().info("Redirect to: "+ref);
         return ref;
      } catch (SQLException ex) {
View Full Code Here

                        }
                     }

                     public void onEntry(Entry entry) throws QueryException {
                        try {
                           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();

                           // TODO: optimize by giving item destination to storage
                           loader.generate(new StringReader(sw.toString()), new RemoveDocumentFilter(dest));
                        } catch (Exception ex) {
                           throw new QueryException("Exception during feed entry generation.",ex);
                        }
                     }

                     public void onFeed(Feed feed) throws QueryException {
                        try {
                           org.atomojo.app.client.Feed feedRep = new org.atomojo.app.client.Feed(xmlParser.load(app.getStorage().getFeedHead(feed.getPath(), feed.getUUID())));
                           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,feedRep.getTitle());
                           String summary = feedRep.getSummary();
                           text(constructor,dest,AtomResource.SUMMARY_NAME,summary);
                           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));
                        } catch (Exception ex) {
                           throw new QueryException("Exception during feed entry generation.",ex);
                        }
                     }
View Full Code Here

      try {
         if (found) {
            Iterator<TermInstance<Feed>> feeds = app.getDB().getFeedsByTerm(key.dbTerm,key.value);
            while (feeds.hasNext()) {
               TermInstance<Feed> termValue = feeds.next();
               Feed feed = termValue.getTarget();
               boolean ok = true;
               for (URI otherTerm : termSet.keySet()) {
                  TermQuery other = termSet.get(otherTerm);
                  ok = feed.hasTerm(other.dbTerm, other.value);
                  if (!ok) {
                     break;
                  }
               }
               if (ok) {
                  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(key.dbTerm,key.value);
            while (entries.hasNext()) {
               TermInstance<Entry> termValue = entries.next();
               Entry entry = termValue.getTarget();
               boolean ok = true;
               for (URI otherTerm : termSet.keySet()) {
                  TermQuery other = termSet.get(otherTerm);
                  ok = entry.hasTerm(other.dbTerm, other.value);
                  if (!ok) {
                     break;
                  }
               }
               if (ok) {
                  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

      String [] segments = feedPath.split("/");

      FeedIndex index = AtomResource.indexFeed(log,feedDoc.getDocumentElement());

      // Find the existing paths
      Feed parent = null;
      try {
         parent = db.getRoot();
      } catch (SQLException ex) {
         throw new AppException(Status.SERVER_ERROR_INTERNAL,"Failed to get root feed  due to exception.",ex);
      }
     
      if (parent==null && feedPath.length()==0) {
         try {
            parent = db.createRoot();
           
            // This is the actual feed we're creating, so massage the
            // document
            AtomResource.mergeFeedDocument(feedDoc,parent.getUUID(),parent.getCreated(),parent.getEdited());
            log.fine("Creating root...");
           
            Status status = storage.storeFeed(parent.getPath(),parent.getUUID(),feedDoc);
            if (!status.isSuccess()) {
               throw new AppException(status,"Failed to create root feed.");
            }
         } catch (IOException ex) {
            throw new AppException(Status.SERVER_ERROR_INTERNAL,"Failed to create root feed  due to exception.",ex);
         } catch (SQLException ex) {
            throw new AppException(Status.SERVER_ERROR_INTERNAL,"Failed to create root feed  due to exception.",ex);
         }
      } else {
     
         if (parent==null) {
           
            try {
               parent = db.createRoot();
            } catch (SQLException ex) {
               throw new AppException(Status.SERVER_ERROR_INTERNAL,"Failed to get root feed  due to exception.",ex);
            }
           
            log.fine("Creating root feed.");
            try {
               Status status = storage.storeFeed(parent.getPath(),parent.getUUID(),AtomResource.createFeedDocument("",parent.getUUID(),parent.getCreated()));
               if (!status.isSuccess()) {
                  throw new AppException(status,"Failed to create root feed");
               }
            } catch (XMLException ex) {
               throw new AppException(Status.SERVER_ERROR_INTERNAL,"Failed to create root feed due to exception.",ex);
            } catch (IOException ex) {
               throw new AppException(Status.SERVER_ERROR_INTERNAL,"Failed to create root feed due to exception.",ex);
            } catch (SQLException ex) {
               throw new AppException(Status.SERVER_ERROR_INTERNAL,"Failed to create root feed due to exception.",ex);
            }
         }
        
         if (feedPath.length()==0) {
            throw new AppException(Status.CLIENT_ERROR_CONFLICT,"The root feed already exists.");
         }
        
         int current = 0;
         for (; current<segments.length; current++) {
            try {
               Feed next = parent.getChild(segments[current]);
               if (next==null) {
                  break;
               } else {
                  parent = next;
               }
            } catch (SQLException ex) {
               throw new AppException(Status.SERVER_ERROR_INTERNAL,"Cannot get segment "+segments[current]+" from database due to exception.",ex);
            }
         }

         // If we found the whole path, the feed alreayd exists
         if (current==segments.length) {
            throw new AppException(Status.CLIENT_ERROR_CONFLICT,"Feed already exists at path: "+feedPath);
         }

         if (log.isLoggable(Level.FINE)) {
            log.fine("Parentage '"+join(segments,0,current,'/')+"' already exists...");
         }

         // Create all the path segments
         for (int i=current; i<segments.length; i++) {
            String path = join(segments,0,i+1,'/');
            if (log.isLoggable(Level.FINE)) {
               log.fine("Creating path: "+path);
            }
            boolean last = i==(segments.length-1);
            boolean created = false;
            try {
               Feed next = parent.getChild(segments[i]);
               if (next!=null && last) {
                  // This shouldn't happen
                  throw new AppException(Status.CLIENT_ERROR_CONFLICT,"Collection already exists at "+path);
               }
               if (next==null) {
View Full Code Here

   public Feed getFeed(String path)
      throws AppException
   {
      String [] segments = path.split("/");
      try {
         Feed f = db.findFeedByPath(segments);
         if (f==null) {
            throw new AppException(Status.CLIENT_ERROR_NOT_FOUND,"Feed at path '"+path+"' cannot be found.");
         }
         return f;
      } catch (SQLException ex) {
View Full Code Here

  
   public Representation getEntryRepresentation(String feedBaseURI,Entry entry)
      throws AppException
   {
      try {
         Feed feed = entry.getFeed();
         return storage.getEntry(feedBaseURI,feed.getPath(),feed.getUUID(),entry.getUUID());
      } catch (IOException ex) {
         throw new AppException(Status.SERVER_ERROR_INTERNAL,"Cannot get entry XML.",ex);
      } catch (SQLException ex) {
         throw new AppException(Status.SERVER_ERROR_INTERNAL,"Cannot get entry XML.",ex);
      }
View Full Code Here

               }
               entries = db.getJournal().getUpdates();
               while (entries.hasNext()) {
                  Journal.UpdatedEntry updated = (Journal.UpdatedEntry)entries.next();
                  String name = updated.getOperation()==Journal.CREATE_OPERATION ? "created" : "updated";
                  Feed feed = updated.getFeed();
                  Entry entry = updated.getEntry();
                  EntryMedia media = updated.getResource();
                  out.write('<');
                  out.write(name);
                  out.write(" at='");
                  out.write(AtomResource.toXSDDate(updated.getOccurredOn()));
                  out.write("' feed='");
                  out.write(feed.getUUID().toString());
                  if (entry!=null) {
                     out.write("' entry='");
                     out.write(entry.getUUID().toString());
                  }
                  if (media!=null) {
View Full Code Here

        
         // test to make sure it isn't an entry path
         if (!(segments.length>=2 && segments[last-1].equals("_"))) {
            try {

               Feed f = app.getFeed(uriPath);
               if (uriPath.length()>0 && !uriPath.endsWith("/")) {
                  uriPath += "/";
               }
               Reference feedResourceRef = new Reference(request.getRootRef().toString()+resourceBase.toString()+uriPath);
               Reference metadataResourceRef = new Reference(request.getRootRef().toString()+metadataBase.toString()+uriPath);
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.