Package org.atomojo.app.db

Examples of org.atomojo.app.db.Entry


            }
            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


  
   public Representation getEntryRepresentation(String feedBaseURI,Feed feed, UUID id)
      throws AppException
   {
      try {
         Entry entry = feed.findEntry(id);
         if (entry==null) {
            throw new AppException(Status.CLIENT_ERROR_NOT_FOUND,"Entry "+id+" not found.");
         }
         return getEntryRepresentation(feedBaseURI,entry);
      } catch (SQLException ex) {
View Full Code Here

  
   public Entry updateEntry(User user,Feed feed, UUID entryId,Document doc)
      throws AppException
   {
      try {
         Entry entry = feed.findEntry(entryId);
         return updateEntry(user,feed,entry,doc);
      } catch (SQLException ex) {
         throw new AppException(Status.SERVER_ERROR_INTERNAL,"Cannot get entry "+entryId+" from feed "+feed.getUUID(),ex);
      }
     
View Full Code Here

  
   public void deleteEntry(Feed feed,UUID id)
      throws AppException
   {
      try {
         Entry entry = feed.findEntry(id);
         deleteEntry(feed,entry);
      } catch (SQLException ex) {
         throw new AppException(Status.SERVER_ERROR_INTERNAL,"Cannot get entry "+id,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) {
                     out.write("' media='");
                     out.write(media.getName());
                  }
View Full Code Here

         r.close();
        
         // Find the entry
        
         try {
            Entry entry = app.updateEntry(user,feed,entryId,doc);
            getResponse().setStatus(Status.SUCCESS_OK);
            String feedBaseURI = getRequest().getResourceRef().getParentRef().getParentRef().toString();
            Representation rep = app.getEntryRepresentation(feedBaseURI,entry);
            rep.setCharacterSet(CharacterSet.UTF_8);
            return rep;
View Full Code Here

  
   public Representation delete()
   {
      try {
        
         Entry entry = feed.findEntry(entryId);
         if (entry==null) {
            getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);
            return null;
         }
         try {
View Full Code Here

      }
   }
  
   public Representation head() {
      try {
         final Entry entry = feed.findEntry(entryId);
         getResponse().setStatus(Status.SUCCESS_NO_CONTENT);
         Representation rep = new StringRepresentation("",MediaType.APPLICATION_ATOM);
         rep.setModificationDate(entry.getEdited());
         rep.setTag(new Tag(Long.toString(entry.getEdited().getTime()),false));
         return rep;
      } catch (SQLException ex) {
         getContext().getLogger().log(Level.SEVERE,"Exception while deleting entry: "+ex.getMessage(),ex);
         getResponse().setStatus(Status.SERVER_ERROR_INTERNAL);
         return new StringRepresentation("Exception while deleting entry.");
View Full Code Here

      } else {
         index.setId(UUID.randomUUID());
      }

      // Create entry index
      Entry entry = null;
      try {
         entry = feed.createEntry(index.getId());
      } catch (SQLException ex) {
         throw new AppException(Status.SERVER_ERROR_INTERNAL,"Cannot create entry in database.",ex);
      }

      try {
         for (URI term : index.keySet()) {
            Object value = index.get(term);
            Term t = feed.getDB().createTerm(term);
            entry.categorize(t,value);
         }
      } catch (SQLException ex) {
         throw new AppException(Status.SERVER_ERROR_INTERNAL,"Cannot categorize entry due to SQL Exception.",ex);
      }

      // Get the identity's author
      String authorName = user.getName();

      // Store in XML DB
      AtomResource.mergeEntry(top,entry.getUUID(),entry.getCreated(),entry.getEdited(),authorName,null);

      try {
         Status status = storage.storeEntry(feed.getPath(),feed.getUUID(),entry.getUUID(),entryDoc);
         if (!status.isSuccess()) {
            String xml = null;
            try {
               StringWriter w = new StringWriter();
               XMLWriter.writeDocument(entryDoc,w);
               xml = w.toString();
               //log.info(xml);
            } catch (Exception ex) {
               // TODO: need to delete
               log.log(Level.SEVERE,"Cannot serialize entry for error message.",ex);
            }
            throw new AppException(Status.SERVER_ERROR_INTERNAL,"Cannot store entry, status="+status.getCode()+"\n"+xml);
         }
        
         storage.feedUpdated(feed.getPath(),feed.getUUID(),feed.getEdited());
        
      } catch (SQLException ex) {
         try {
            entry.delete(null);
         } catch (SQLException ox) {
            log.log(Level.SEVERE,"Cannot delete entry for exception cleanup.",ox);
         }
         throw new AppException(Status.SERVER_ERROR_INTERNAL,"Cannot store entry.",ex);
      } catch (IOException ex) {
         try {
            entry.delete(null);
         } catch (SQLException ox) {
            log.log(Level.SEVERE,"Cannot delete entry for exception cleanup.",ox);
         }
         throw new AppException(Status.SERVER_ERROR_INTERNAL,"Database error while storing entry.",ex);
      }
View Full Code Here

  
   public Entry createMediaEntry(User user,Feed feed, Representation entity, String slug, UUID id)
      throws AppException
   {
      // Create entry index
      Entry entry = null;
      try {
         entry = feed.createEntry(id);
      } catch (SQLException ex) {
         throw new AppException(Status.SERVER_ERROR_INTERNAL,"Cannot create entry in database.",ex);
      }

      String file = slug;
     
      try {
         InputStream is = entity.getStream();
         MediaType mediaType = entity.getMediaType();
         if (mediaType==null) {
            throw new AppException(Status.CLIENT_ERROR_BAD_REQUEST,"The media type is missing.");
         }
         MediaType baseMediaType = mediaType.valueOf(mediaType.getName());
        
         // Make sure we have a filename for the media resource
         if (file==null) {
            String ext = metaService.getExtension(baseMediaType);
            if (ext!=null) {
               file = entry.getUUID()+"."+ext;
            } else {
               file = entry.getUUID().toString();
            }
            slug = entry.getUUID().toString();
         } else if (file.indexOf('.')<0) {
            String ext = metaService.getExtension(baseMediaType);
            if (ext!=null) {
               file += "."+ext;
            }
         }
         EntryMedia media;
         try {
            media = entry.createResource(file,mediaType);
         } catch (SQLException ex) {
            try {
               entry.delete(null);
            } catch (SQLException ox) {
               log.log(Level.SEVERE,"Cannot delete entry for exception cleanup.",ox);
            }
            throw new AppException(Status.SERVER_ERROR_INTERNAL,"Cannot create entry media resource in database.",ex);
         }
         if (media==null) {
            throw new AppException(Status.CLIENT_ERROR_BAD_REQUEST,"Media entry name "+file+" refused.");
         }

         // Get author name for identity
         String authorName = user.getName();

         // Create entry document
         Document doc = null;
         try {
            String title = URLDecoder.decode(slug,"UTF-8");
            doc = AtomResource.createMediaEntryDocument(title,entry.getUUID(),entry.getCreated(),authorName,file,mediaType);
         } catch (XMLException ex) {
            try {
               entry.delete(null);
            } catch (SQLException ox) {
               log.log(Level.SEVERE,"Cannot delete entry for exception cleanup.",ox);
            }
            throw new AppException(Status.SERVER_ERROR_INTERNAL,"Cannot create media entry document.",ex);
         } catch (UnsupportedEncodingException ex) {
            try {
               entry.delete(null);
            } catch (SQLException ox) {
               log.log(Level.SEVERE,"Cannot delete entry for exception cleanup.",ox);
            }
            throw new AppException(Status.SERVER_ERROR_INTERNAL,"Cannot decode slug for media entry title.",ex);
         }

         try {
            String path = feed.getPath();
            Status entryStatus = storage.storeEntry(path,feed.getUUID(),entry.getUUID(),doc);
            if (entryStatus.isSuccess()) {
               Status mediaStatus = storage.storeMedia(path,feed.getUUID(),media.getName(),mediaType,is);
               // TODO: storage may change media type parameters and the entry needs to be updated
               if (!mediaStatus.isSuccess()) {
                  try {
                     entry.delete(null);
                  } catch (SQLException ox) {
                     log.log(Level.SEVERE,"Cannot delete entry for exception cleanup.",ox);
                  }
                  try {
                     storage.deleteEntry(path,feed.getUUID(),entry.getUUID());
                  } catch (IOException ex) {
                     log.log(Level.SEVERE,"Cannot delete entry storage for exception cleanup.",ex);
                  }
                  throw new AppException(mediaStatus,"Cannot store entry's media (refused)");
               } else {
                  storage.feedUpdated(feed.getPath(),feed.getUUID(),feed.getEdited());
               }
            } else {
               try {
                  entry.delete(null);
               } catch (SQLException ox) {
                  log.log(Level.SEVERE,"Cannot delete entry for exception cleanup.",ox);
               }
               throw new AppException(entryStatus,"Cannot store entry (refused)");
            }
         } catch (SQLException ex) {
            try {
               entry.delete(null);
            } catch (SQLException ox) {
               log.log(Level.SEVERE,"Cannot delete entry for exception cleanup.",ox);
            }
            throw new AppException(Status.SERVER_ERROR_INTERNAL,"Cannot store entry.",ex);
         }
      } catch (IOException ex) {
         try {
            entry.delete(null);
         } catch (SQLException ox) {
            log.log(Level.SEVERE,"Cannot delete entry for exception cleanup.",ox);
         }
         throw new AppException(Status.SERVER_ERROR_INTERNAL,"Cannot store entry due to request I/O exception.",ex);
      }
View Full Code Here

TOP

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

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.