Package org.atomojo.app.db

Examples of org.atomojo.app.db.Entry


      text(constructor,dest,AtomResource.UPDATED_NAME,AtomResource.toXSDDate(new Date()));
      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


            }
         }
        
         User user = (User)getRequest().getAttributes().get(App.USER_ATTR);
         try {
            Entry entry = app.createEntry(user,feed,doc);
           
            getResponse().setStatus(Status.SUCCESS_CREATED);
            Form headers = new Form();
            getResponse().getAttributes().put("org.restlet.http.headers",headers);
            Reference ref = new Reference(myself+"_/"+entry.getUUID().toString());
            getResponse().setLocationRef(ref);
            Representation rep = new InfosetRepresentation(MediaType.APPLICATION_ATOM,doc);
            rep.setCharacterSet(CharacterSet.UTF_8);
            rep.setTag(new Tag(Long.toString(entry.getEdited().getTime()),false));
            MediaType entryType = new MediaType(rep.getMediaType().getName(),rep.getMediaType().getParameters().createSeries(EntryResource.entryParameters));
            rep.setMediaType(entryType);
            return rep;
           
         } catch (AppException ex) {
            getContext().getLogger().log(Level.SEVERE,ex.getMessage(),ex.getCause());
            getResponse().setStatus(ex.getStatus());
            return new StringRepresentation(ex.getMessage());
         }
        
      } else {
         // Get the slug for the resource & entry
         Form headers = (Form)getRequest().getAttributes().get("org.restlet.http.headers");
         String slug = headers.getValues("slug");
         if (slug==null) {
            slug = headers.getValues("Slug");
         }
         if (slug!=null) {
            try {
               // Decode the precent encoding of the UTF-8 values
               slug = URLDecoder.decode(slug,"UTF-8");
               // Encode the slug as a URL encoding
               slug = URLEncoder.encode(slug,"UTF-8");
            } catch (UnsupportedEncodingException ex) {
               getLogger().log(Level.SEVERE,"Cannot decode slug value: "+slug,ex);
            }
            getContext().getLogger().info("Slug="+slug);
         }
         String idS = headers.getValues("id");
         UUID id = null;
         if (idS!=null) {
            try {
               id = UUID.fromString(idS);
            } catch (Exception ex) {
            }
         } else {
            id = UUID.randomUUID();
         }
        
         try {

            // Get author name for identity
            User user = (User)getRequest().getAttributes().get(App.USER_ATTR);
            Entry entry = app.createMediaEntry(user,feed,entity,slug,id);
           
            getResponse().setStatus(Status.SUCCESS_CREATED);
            headers = new Form();
            getResponse().getAttributes().put("org.restlet.http.headers",headers);
            Reference ref = new Reference(myself+"_/"+entry.getUUID().toString());
            getResponse().setLocationRef(ref);
            Representation rep = app.getEntryRepresentation(myself.toString(),entry);
            rep.setCharacterSet(CharacterSet.UTF_8);
            rep.setTag(new Tag(Long.toString(entry.getEdited().getTime()),false));
            return rep;
         } catch (AppException ex) {
            if (ex.getStatus().getCode()==Status.SERVER_ERROR_INTERNAL.getCode()) {
               getContext().getLogger().log(Level.SEVERE,ex.getMessage(),ex.getCause());
            }
View Full Code Here

            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) {
View Full Code Here

                  break;
               case ElementEndItem:
                  level--;
                  if (level==0) {
                     while (entries.hasNext()) {
                        Entry entry = entries.next();
                        Reference entryRef = storage.makeEntryReference(path, entry.getUUID());
                        dest.send(constructor.createCharacters("\n"));
                        Response response = client.handle(new Request(Method.GET,entryRef));
                        if (response.getStatus().isSuccess()) {
                           try {
                              Reader r = response.getEntity().getReader();
View Full Code Here

                        TermInstance<Entry> termValue = entries.next();
                        // need to compare if nil
                        if (pivotValue==Nil.getInstance() && termValue.getValue()!=Nil.getInstance()) {
                           continue;
                        }
                        Entry entry = 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<Entry> boundValue = entry.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<Entry> boundValue = entry.getTerm(t);
                              if (boundValue!=null && boundValue.getValue()!=null) {
                                 variables.put(name,boundValue.getValue());
                              }
                           }
                        }
View Full Code Here

            return new StringRepresentation("Cannot store media.");
         }
         media.touch();
        
         // get the media resoruce's entry
         Entry entry = media.getEntry();
        
         // Get the entry's representation
         String feedBaseURI = getRequest().getResourceRef().getParentRef().getPath();
         Representation entryRep = app.getEntryRepresentation(feedBaseURI,feed,entry.getUUID());
         // avoid a thread with the entry's output representation
         StringWriter sw = new StringWriter();
         entryRep.write(sw);
         entryRep.release();
         DocumentLoader loader = new SAXDocumentLoader();
         Document doc = loader.load(new StringReader(sw.toString()));
        
         // mark the entry as edited
         Date date = media.getEntry().edited();
        
         // change the entry's edited element
         Element edited = doc.getDocumentElement().getFirstElementNamed(AtomResource.EDITED_NAME);
         if (edited!=null) {
            edited.clear();
            edited.addCharacters(toXSDDate(date));
         }
        
         // store the change.
         status = storage.storeEntry(feed.getPath(),feed.getUUID(),entry.getUUID(),doc);
         if (status.isSuccess()) {
            getResponse().setStatus(Status.SUCCESS_NO_CONTENT);
            return null;
         } else {
            getResponse().setStatus(status);
View Full Code Here

  
   public Representation delete()
   {
      try {
         final String fpath = feed.getPath();
         Entry entry = media.getEntry();
         entry.delete(new MediaEntryListener() {
            public void onDelete(EntryMedia resource) {
               try {
                  storage.deleteMedia(fpath,feed.getUUID(),resource.getName());
               } catch (IOException ex) {
                  getContext().getLogger().log(Level.SEVERE,"Cannot delete media: "+ex.getMessage(),ex);
               }
            }
         });
         if (storage.deleteEntry(fpath,feed.getUUID(),entry.getUUID())) {
            getResponse().setStatus(Status.SUCCESS_NO_CONTENT);
            return null;
         } else {
            getResponse().setStatus(Status.SERVER_ERROR_INTERNAL);
            return new StringRepresentation("Cannot delete entry document.");
View Full Code Here

         media.setName(slug);
         media.touch();
        
        
         // get the media resoruce's entry
         Entry entry = media.getEntry();
        
         // Get the entry's representation
         String feedBaseURI = getRequest().getResourceRef().getParentRef().getPath();
         Representation entryRep = app.getEntryRepresentation(feedBaseURI,feed,entry.getUUID());
         // avoid a thread with the entry's output representation
         StringWriter sw = new StringWriter();
         entryRep.write(sw);
         entryRep.release();
         DocumentLoader loader = new SAXDocumentLoader();
         Document doc = loader.load(new StringReader(sw.toString()));
        
         // mark the entry as edited
         Date date = media.getEntry().edited();
        
         // change the entry's edited element
         Element edited = doc.getDocumentElement().getFirstElementNamed(AtomResource.EDITED_NAME);
         if (edited!=null) {
            edited.clear();
            edited.addCharacters(toXSDDate(date));
         }
         Element content = doc.getDocumentElement().getFirstElementNamed(AtomResource.CONTENT_NAME);
         content.setAttributeValue("src",slug);
        
         Iterator<Element> links = doc.getDocumentElement().getElementsByName(AtomResource.LINK_NAME);
         while (links.hasNext()) {
            Element link = links.next();
            if ("edit-media".equals(link.getAttributeValue("rel"))) {
               link.setAttributeValue("href", slug);
            }
         }
        
         // store the change.
         status = storage.storeEntry(feed.getPath(),feed.getUUID(),entry.getUUID(),doc);
         if (status.isSuccess()) {
            getResponse().setStatus(Status.SUCCESS_OK);
            Form returnHeaders = new Form();
            getResponse().getAttributes().put("org.restlet.http.headers",returnHeaders);
            Reference ref = new Reference(getRequest().getResourceRef().getParentRef()+"_/"+entry.getUUID().toString());
            getResponse().setLocationRef(ref);
            Representation rep = app.getEntryRepresentation(getRequest().getResourceRef().getParentRef().toString(),entry);
            rep.setCharacterSet(CharacterSet.UTF_8);
            rep.setTag(new Tag(Long.toString(entry.getEdited().getTime()),false));
            return rep;
         } else {
            getResponse().setStatus(status);
            return new StringRepresentation("Cannot update entry for media.");
         }
View Full Code Here

         Representation entity = storage.getMedia(feed.getPath(),feed.getUUID(),media.getName());
         entity.setMediaType(media.getMediaType());
        
         UUID id = UUID.randomUUID();
        
         Entry entry = app.createMediaEntry(user,feed,entity,slug,id);

         getResponse().setStatus(Status.SUCCESS_CREATED);
         headers = new Form();
         getResponse().getAttributes().put("org.restlet.http.headers",headers);
         Reference ref = new Reference(getRequest().getResourceRef().getParentRef()+"_/"+entry.getUUID().toString());
         getResponse().setLocationRef(ref);
         Representation rep = app.getEntryRepresentation(getRequest().getResourceRef().getParentRef().toString(),entry);
         rep.setCharacterSet(CharacterSet.UTF_8);
         rep.setTag(new Tag(Long.toString(entry.getEdited().getTime()),false));
         return rep;
      } catch (AppException ex) {
         getResponse().setStatus(ex.getStatus());
         if (ex.getStatus().getCode()==Status.SERVER_ERROR_INTERNAL.getCode()) {
            getContext().getLogger().log(Level.SEVERE,ex.getMessage(),ex.getCause());
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.