Package org.atomojo.app.db

Examples of org.atomojo.app.db.Feed


      Reference resourceBase = (Reference)getContext().getAttributes().get(AtomApplication.RESOURCE_BASE_ATTR);
      App app = (App)getContext().getAttributes().get(AtomApplication.APP_ATTR);
      try {
         while (entries.hasNext()) {
            Entry entry = entries.next();
            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


         URI root = URI.create(ref.toString());
         String path = null;
         try {
            path = root.relativize(new URI(dest)).toString();
            String [] segments = path.split("/");
            Feed targetParent = feed.getDB().findFeedByPath(segments, 0, segments.length-1);
            if (targetParent==null) {
               getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
               return new StringRepresentation("Cannot find parent of destination "+dest);
            }
            getLogger().info("Copy from "+feed.getPath()+" to "+targetParent.getPath()+"/"+segments[segments.length-1]);
            CopyFeedTask task = new CopyFeedTask(app,user,feed,targetParent,segments[segments.length-1]);
            task.run();
            if (task.getErrors().size()>0) {
               StringBuilder builder = new StringBuilder();
               for (String error : task.getErrors()) {
View Full Code Here

            System.arraycopy(segments,0,path,0,segments.length-2);
            UUID entryId = UUID.fromString(segments[last]);

            String feedPath = App.join(path,0,path.length,'/')+'/';
            try {
               Feed f = app.getFeed(feedPath);
               if (f!=null) {
                  try {
                     Entry entry = f.findEntry(entryId);
                     if (entry!=null) {
                        EntryResource r = new EntryResource(theApp,f,entry,storage);
                        return r;
                     }
                  } catch (SQLException ex) {
                     getContext().getLogger().log(Level.SEVERE,"Failed to retrieve entry at "+entryId+" from the database.",ex);
                     return new ErrorResource(theApp.getStatusService().getRepresentation(Status.SERVER_ERROR_INTERNAL,request,response));
                  }
               }
               return null;
            } catch (AppException ex) {
               if (ex.getStatus().getCode()==Status.CLIENT_ERROR_NOT_FOUND.getCode()) {
                  return null;
               } else {
                  getContext().getLogger().log(Level.SEVERE,"Failed to retrieve feed at "+feedPath+" from the database.",ex);
                  return new ErrorResource(theApp.getStatusService().getRepresentation(Status.SERVER_ERROR_INTERNAL,request,response));
               }
            }
         } else {
            try {

               Feed f = app.getFeed(uriPath);
               if (uriPath.length()>0 && !uriPath.endsWith("/")) {
                  uriPath += "/";
               }
               Reference feedResourceRef = new Reference(request.getRootRef().toString()+resourceBase.toString()+uriPath);
               FeedResource r = new FeedResource(theApp,f,feedResourceRef,storage);
               return r;
            } catch (AppException ex) {
               if (ex.getStatus().getCode()==Status.CLIENT_ERROR_NOT_FOUND.getCode()) {
                  // It is possible we have a media entry with no '.' in the name, so test for a media entry
                  if (segments.length>0) {
                     String [] path = new String[segments.length-1];
                     System.arraycopy(segments,0,path,0,segments.length-1);
                     String feedPath = App.join(path,0,path.length,'/');
                     file = segments[segments.length-1];
                     try {
                        Feed f = app.getFeed(feedPath);
                        EntryMedia media = f.findEntryResource(file);
                        if (media!=null) {
                           MediaResource r = new MediaResource(theApp,f,media,storage);
                           return r;
                        } else {
                           //getLogger().warning("No media resource "+file);
                           return null;
                        }
                     } catch (AppException nex) {
                        if (ex.getStatus().getCode()==Status.CLIENT_ERROR_NOT_FOUND.getCode()) {
                           return null;
                        } else {
                           getContext().getLogger().log(Level.SEVERE,"Failed to retrieve feed at "+feedPath+" from the database.",nex);
                           return new ErrorResource(theApp.getStatusService().getRepresentation(Status.SERVER_ERROR_INTERNAL,request,response));
                        }

                     } catch (SQLException nex) {
                        getContext().getLogger().log(Level.SEVERE,"Failed to retrieve entry media "+file+" from feed at "+feedPath+" from the database.",nex);
                        return new ErrorResource(theApp.getStatusService().getRepresentation(Status.SERVER_ERROR_INTERNAL,request,response));
                     }
                  }
                  return null;
               } else {
                  getContext().getLogger().log(Level.SEVERE,"Failed to retrieve feed at "+uriPath+" from the database.",ex);
                  return new ErrorResource(theApp.getStatusService().getRepresentation(Status.SERVER_ERROR_INTERNAL,request,response));
               }
            }
         }
      } else {
         String [] path = new String[segments.length-1];
         System.arraycopy(segments,0,path,0,segments.length-1);
         String feedPath = App.join(path,0,path.length,'/');
         if (file.startsWith("_entry_.")) {
            try {
               Feed f = app.getFeed(feedPath);
               if (f!=null) {
                  String entryIdS = file.substring(8);
                  int end = entryIdS.indexOf(".");
                  if (end<0) {
                     return null;
                  }
                  if (!entryIdS.substring(end).equals(".atom")) {
                     return null;
                  }
                  entryIdS = entryIdS.substring(0,end);
                  try {
                     UUID entryId = UUID.fromString(entryIdS);
                     Entry entry = f.findEntry(entryId);
                     if (entry!=null) {
                        EntryResource r = new EntryResource(theApp,f,entry,storage);
                        return r;
                     }
                  } catch (SQLException ex) {
                     getContext().getLogger().log(Level.SEVERE,"Failed to retrieve entry at "+entryIdS+" from the database.",ex);
                     return new ErrorResource(theApp.getStatusService().getRepresentation(Status.SERVER_ERROR_INTERNAL,request,response));
                  } catch (IllegalArgumentException ex) {
                     return new ErrorResource(theApp.getStatusService().getRepresentation(Status.CLIENT_ERROR_BAD_REQUEST,request,response));
                  }
               }
               return null;
            } catch (AppException ex) {
               if (ex.getStatus().getCode()==Status.CLIENT_ERROR_NOT_FOUND.getCode()) {
                  return null;
               } else {
                  getContext().getLogger().log(Level.SEVERE,"Failed to retrieve feed at "+feedPath+" from the database.",ex);
                  return new ErrorResource(theApp.getStatusService().getRepresentation(Status.SERVER_ERROR_INTERNAL,request,response));
               }
            }
         } else if (file.charAt(0)=='.' && file.endsWith(".atom")) {
            return new ErrorResource(theApp.getStatusService().getRepresentation(Status.CLIENT_ERROR_BAD_REQUEST,request,response));
         } else {
            try {
               // The media name is already encoded
               file = URLDecoder.decode(file,"UTF-8");
               file = URLEncoder.encode(file,"UTF-8");
               Feed f = app.getFeed(feedPath);
               EntryMedia media = f.findEntryResource(file);
               if (media!=null) {
                  MediaResource r = new MediaResource(theApp,f,media,storage);
                  return r;
               } else {
                  //getLogger().warning("No media resource "+file);
View Full Code Here

                     getLogger().fine("Creating feed at '"+requestPath+"'");
                  }
                 

                  try {
                     Feed f = app.createFeed(requestPath,doc);
                     response.setStatus(Status.SUCCESS_CREATED);
                     Representation rep = storage.getFeed(f.getPath(),f.getUUID(),f.getEntries());
                     if (rep!=null) {
                        rep.setTag(new Tag(Long.toString(f.getEdited().getTime()),false));
                     }
                     response.setEntity(rep);
                  } catch (AppException ex) {
                     if (ex.getStatus().equals(Status.SERVER_ERROR_INTERNAL)) {
                        getLogger().log(Level.SEVERE,ex.getMessage(),ex);
View Full Code Here

                        TermInstance<Feed> termValue = feeds.next();
                        // need to compare if nil
                        if (pivotValue==Nil.getInstance() && termValue.getValue()!=Nil.getInstance()) {
                           continue;
                        }
                        Feed feed = termValue.getTarget();
                        Map<String,Object> variables = new TreeMap<String,Object>();
                        boolean ok = true;
                        // match values
                        for (Triple triple : query.getWhereClause().getClauses()) {
                           if (triple==pivot) {
                              continue;
                           }
                           for (Value value : comparisons) {
                              TermInstance<Feed> boundValue = feed.getTerm(value.term);
                              if (boundValue==null) {
                                 ok = false;
                                 break;
                              } else if (value.value==null && boundValue.getValue()!=null) {
                                 ok = false;
                                 break;
                              } else if (value.value!=null && !value.value.equals(boundValue.getValue())) {
                                 ok = false;
                                 break;
                              }
                           }
                           if (!ok) {
                              break;
                           }
                           for (String name : bindings.keySet()) {
                              Term t = bindings.get(name);
                              TermInstance<Feed> boundValue = feed.getTerm(t);
                              if (boundValue!=null && boundValue.getValue()!=null) {
                                 variables.put(name,boundValue.getValue());
                              }
                           }
                        }
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.