Examples of ThoughtList


Examples of org.lexev.bestwisethoughts.client.data.ThoughtList

    SwingWorker<Thought, Void> swingWorker = new SwingWorker<Thought, Void>() {
            @Override
            public Thought doInBackground() throws IOException{
              Thought thoughtToShow = null;
        if (cachedReceivedThoughts.size() == 0){ 
          ThoughtList thoughtsFromServer = webServiceREST.getRandomThoughts();           
          cachedReceivedThoughts.addAll(thoughtsFromServer.getThoughtsList());       
        }
        thoughtToShow = cachedReceivedThoughts.poll();
        cachedLastThoughts.addAndSaveToFile(thoughtToShow.getID(), new Thought(thoughtToShow));
                return thoughtToShow;
            }
View Full Code Here

Examples of org.lexev.bestwisethoughts.client.data.ThoughtList

  @SuppressWarnings("rawtypes")
  public SwingWorker getFavoriteThoughts(final ThoughtLoadable thoughtLoadable) {
    SwingWorker<ThoughtList, Void> swingWorker = new SwingWorker<ThoughtList, Void>() {
            @Override
            public ThoughtList doInBackground() throws NotRegisteredException, IOException{
              ThoughtList thoughtList = new ThoughtList();
              if (webServiceREST.isUserRegistered()){
              // get list of favorite thought IDs for current registered user
              ListLong favoriteIDs = webServiceREST.getUserFavoriteIDs();
                // compare cached thoughts with received thought ids
                Set<Long> notFavoriteThoughtsLeft = new HashSet<Long>(cachedFavoriteThought.getMap().keySet());
                List<Long> favoriteThoughtsLeft = new ArrayList<Long>();
                for(Long id : favoriteIDs.getList()){
                  if(!cachedFavoriteThought.getMap().containsKey(id)){
                    favoriteThoughtsLeft.add(id);
                  }
                  notFavoriteThoughtsLeft.remove(id);
                }
                //remove thoughts, that are not favorite
                for (Long id:notFavoriteThoughtsLeft){
                  cachedFavoriteThought.getMap().remove(id);
                }
                //request from server favorite thoughts, that are left in saved favorite thoughts
                if (favoriteThoughtsLeft.size()!=0){
                  ThoughtList fetchedThoughts = webServiceREST.getThoughtsByIDs(favoriteThoughtsLeft);               
                  for (Thought thought:fetchedThoughts.getThoughtsList()){
                    cachedFavoriteThought.getMap().put(thought.getID(), thought);
                  }
                }
                cachedFavoriteThought.saveToFile();    
               
                //now favorite thoughts is synchronized with server
                //copy them to list, that will be returned
                for (Thought thought:cachedFavoriteThought.getMap().values()){
                  thoughtList.getThoughtsList().add(thought);
              }
              } else {
                throw new NotRegisteredException();    
              }
             
            return thoughtList;
            }

            @Override
            public void done() {       
                try {
                  ThoughtList favoriteThoughts = get();
                  thoughtLoadable.completeLoadingThoughts(Status.OK, favoriteThoughts.getThoughtsList(), null);
                } catch (InterruptedException ignore) {
                } catch (CancellationException ignore){
                } catch (ExecutionException e) {
                  if (e.getCause() != null){
                    if (e.getCause().getClass() == UniformInterfaceException.class){
View Full Code Here

Examples of org.lexev.bestwisethoughts.client.data.ThoughtList

  @SuppressWarnings("rawtypes")
  public SwingWorker getPopularThoughts(final ThoughtLoadable thoughtLoadable) {
    SwingWorker<ThoughtList, Void> swingWorker = new SwingWorker<ThoughtList, Void>() {     
            @Override
            public ThoughtList doInBackground() throws IOException{
              ThoughtList topThoughtList = new ThoughtList();
            topThoughtList = webServiceREST.getPopularThoughts();
            return topThoughtList;
            }
            @Override
            public void done() {       
                try {
                  ThoughtList topThoughtList = get();
                  thoughtLoadable.completeLoadingThoughts(Status.OK, topThoughtList.getThoughtsList(), null);
                } catch (InterruptedException ignore) {
                } catch (CancellationException ignore){
                } catch (ExecutionException e) {
                  if (e.getCause() != null){
                    if (e.getCause().getClass() == UniformInterfaceException.class){
View Full Code Here

Examples of org.lexev.bestwisethoughts.client.data.ThoughtList

   * @return fetched random thoughts
   * @throws UniformInterfaceException
   */
  public ThoughtList getRandomThoughts() throws UniformInterfaceException{
     
    ThoughtList thoughtList = getWebService()
      .path("thought/get/random")
      .queryParam("amount", Const.K_RANDOM_THOUGHT_AMOUNT.toString())
      .accept(MediaType.APPLICATION_XML)
      .get(ThoughtList.class);
      return thoughtList;
View Full Code Here

Examples of org.lexev.bestwisethoughts.client.data.ThoughtList

   * @param thoughtIDs
   * @return thoughts
   * @throws UniformInterfaceException
   */
  public ThoughtList getThoughtsByIDs(List<Long> thoughtIDs) throws UniformInterfaceException{
    ThoughtList fetchedThoughts = getWebService()
      .path("thought/get/byids")
      .type(MediaType.APPLICATION_XML).accept(MediaType.APPLICATION_XML)
      .post(ThoughtList.class, new ListLong(thoughtIDs));
    return fetchedThoughts;
  }
View Full Code Here

Examples of org.lexev.bestwisethoughts.client.data.ThoughtList

   *
   * @return popular thoughts
   * @throws UniformInterfaceException
   */
  public ThoughtList getPopularThoughts() throws UniformInterfaceException{
    ThoughtList topThoughtList = getWebService()
      .path("thought/get/top")
      .accept(MediaType.APPLICATION_XML)
      .get(ThoughtList.class);   
    return topThoughtList;
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.