Exemplo n.º 1
0
  public Post getPost(UUID id) {
    for (Post post : mPosts) {
      if (post.getId().equals(id)) return post;
    }

    return null;
  }
  @Test
  public void testFlushSQL() {
    doInJPA(
        entityManager -> {
          entityManager.createNativeQuery("delete from Post").executeUpdate();
        });
    doInJPA(
        entityManager -> {
          log.info("testFlushSQL");
          Post post = new Post("Hibernate");
          post.setId(1L);
          entityManager.persist(post);

          Session session = entityManager.unwrap(Session.class);
          session.setFlushMode(FlushMode.MANUAL);

          assertTrue(
              ((Number) entityManager.createQuery("select count(id) from Post").getSingleResult())
                      .intValue()
                  == 0);

          assertTrue(
              ((Number) session.createSQLQuery("select count(*) from Post").uniqueResult())
                      .intValue()
                  == 0);
        });
  }
Exemplo n.º 3
0
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
      View v = convertView;
      if (v == null) {
        LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        v = vi.inflate(R.layout.row, null);
      }
      Post o = items.get(position);
      if (o != null) {
        TextView tt = (TextView) v.findViewById(R.id.toptext);
        TextView bt = (TextView) v.findViewById(R.id.bottomtext);
        ImageView im = (ImageView) v.findViewById(R.id.icon);

        if (tt != null) {
          tt.setText(o.getUserName());
        }
        if (bt != null) {
          bt.setText(o.getTitle());
        }
        if (im != null) {
          im.setImageBitmap(o.getBitmap());
        }
      }
      return v;
    }
Exemplo n.º 4
0
 /**
  * Compares this posting with the given posting. <br>
  * If the id of this posting greater than the given one then 1. <br>
  * If the id of this posting equal the given one then 0. <br>
  * If the id of this posting less than the given one then -1.
  *
  * @param post Posting to be compare with this posting.
  * @return
  */
 @Override
 public int compareTo(Post post) {
   int result = 0;
   if (mPostId > post.getPostId()) result = 1;
   else if (mPostId < post.getPostId()) result = -1;
   return result;
 }
 @SuppressWarnings("unchecked")
 public void onClick_blockHost(View view) {
   Set<String> defaultSet = new HashSet<>();
   SharedPreferences blocked_hosts =
       Dynamo_Interface.application_context.getSharedPreferences(
           "blocked_hosts", Context.MODE_PRIVATE);
   ArrayList<String> host_list = new ArrayList<>(blocked_hosts.getStringSet("hosts", defaultSet));
   if (!host_list.contains(viewing_post.getHost())) {
     host_list.add(viewing_post.getHost());
     Set updated_List = new HashSet(host_list);
     SharedPreferences.Editor editor = blocked_hosts.edit();
     editor.putStringSet("hosts", updated_List);
     editor.commit();
     new AlertDialog.Builder(view_post_screen.this)
         .setTitle("Host Block")
         .setMessage(
             viewing_post.getHost()
                 + " is now blocked.  Check the ban list screen to undo this action")
         .setPositiveButton(
             "OK",
             new DialogInterface.OnClickListener() {
               public void onClick(DialogInterface dialog, int id) {
                 startActivity(new Intent(view_post_screen.this, view_post_list_screen.class));
               }
             })
         .show();
   } else {
     new AlertDialog.Builder(view_post_screen.this)
         .setTitle("Already Blocked")
         .setMessage("That host has already been blocked.")
         .setPositiveButton("OK", null)
         .show();
   }
 }
Exemplo n.º 6
0
  @Override
  public boolean onContextItemSelected(MenuItem item) {
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
    Post post = (Post) posts.get((int) info.id);

    switch (item.getItemId()) {
      case R.id.open:
        Intent myIntent = new Intent(Intent.ACTION_VIEW, post.getUrl());
        startActivity(myIntent);
        return true;
      case R.id.follow_forum:
        setURL(post, true, false, false);
        return true;
      case R.id.follow_all:
        setURL(null, false, false, false);
        return true;
      case R.id.follow_user:
        setURL(post, false, true, false);
        return true;
      case R.id.follow_thread:
        setURL(post, false, false, true);
        return false;
      default:
        return super.onContextItemSelected(item);
    }
  }
Exemplo n.º 7
0
 /** Get the date of the last modification of posts in the current topic. */
 public DateTime getLastModificationPostDate() {
   DateTime newTopicModificationDate = getFirstPost().getLastTouchedDate();
   for (Post post : posts) {
     if (post.getLastTouchedDate().isAfter(newTopicModificationDate.toInstant())) {
       newTopicModificationDate = post.getLastTouchedDate();
     }
   }
   return newTopicModificationDate;
 }
Exemplo n.º 8
0
 public String title(Post post) {
   if (post.getSeo() != null && post.getSeo().getTitle() != null) {
     return post.getSeo().getTitle();
   }
   Blog blog = blogService.readBlogById(Blog.DEFAULT_ID);
   return String.format(
       "%s | %s",
       post.getTitle(), blog.getTitle(processingContext.getContext().getLocale().getLanguage()));
 }
Exemplo n.º 9
0
  /**
   * Returns first post that is newer then give time
   *
   * @param time time to looking for newer post
   * @return first post that is newer then give time or first post if there is no post that is newer
   */
  private Post getFirstNewerPost(DateTime time) {
    for (Post post : getPosts()) {
      if (post.getCreationDate().isAfter(time)) {
        return post;
      }
    }

    return getFirstPost();
  }
Exemplo n.º 10
0
 /**
  * Calculates modification date of topic taking it as last post in topic creation date. Used after
  * deletion of the post. It is necessary to save the sort order of topics in the future.
  */
 public void recalculateModificationDate() {
   DateTime newTopicModificationDate = getFirstPost().getCreationDate();
   for (Post post : posts) {
     if (post.getCreationDate().isAfter(newTopicModificationDate.toInstant())) {
       newTopicModificationDate = post.getCreationDate();
     }
   }
   modificationDate = newTopicModificationDate;
 }
Exemplo n.º 11
0
  private String render(int n) {
    String result = "";

    for (Post p : this.posts) {
      result = result + p.render();
      if (--n < 0) break;
    }

    return result;
  }
Exemplo n.º 12
0
  private static void insertPosts(SessionWrapper sessionWrapper, UUID blogId, int numPosts) {
    for (int i = 0; i < numPosts; i++) {
      Post post = new Post();

      post.setId(getTimeUUID());
      post.setPostedOn(System.currentTimeMillis());
      post.setBlogId(blogId);
      post.setContent(getString(10, 50));
      post.setTitle(getString(2, 5));
      HashSet<String> tags = new HashSet<>();
      for (int j = 0; j < getInt(3, 10); j++) {
        tags.add(getTag());
      }
      post.setTags(tags);
      post.save(sessionWrapper);

      PostVotes votes = new PostVotes();
      votes.setPostId(post.getId());
      votes.setUpvotes(getInt(0, 100));
      votes.setDownvotes(getInt(0, 100));
      votes.save(sessionWrapper);

      insertComments(sessionWrapper, post, getInt(1, 10));
    }
  }
Exemplo n.º 13
0
  @Test
  public void shouldInjectCustomContentIntoJson() {
    deleteAndPopulateTable("posts");

    Post p = Post.findById(1);
    String json = p.toJson(true, "title");

    Map map = JsonHelper.toMap(json);
    Map injected = (Map) map.get("injected");
    a(injected.get("secret_name")).shouldBeEqual("Secret Name");
  }
Exemplo n.º 14
0
  public PostList changed(List<Question> compareTo) {

    PostList diff = new PostList();
    for (Post post : this) {
      int index = compareTo.indexOf(post);
      if (index == -1) continue;
      if (compareTo.get(index).getLastActivityDate() != post.getLastActivityDate()) {
        diff.add(compareTo.get(index));
      }
    }
    return diff;
  }
Exemplo n.º 15
0
 private boolean hasEmployees(Date date) {
   for (Post post : getPosts(date)) {
     if (!(post.getEmployees(date).isEmpty())) {
       return true;
     }
   }
   for (Organization child : getChildren(date)) {
     if (child.hasEmployees(date)) {
       return true;
     }
   }
   return false;
 }
Exemplo n.º 16
0
 private void cancelEditPost(HttpServletRequest req, HttpServletResponse resp) {
   ShubUser user = (ShubUser) req.getSession().getAttribute("user");
   String date = req.getParameter("hiddenDate").toString();
   Post post = user.getNewsfeed().getPost(date);
   post.setIsEditing(false);
   req.getSession().removeAttribute("deleteDate");
   req.getSession().setAttribute("user", user);
   try {
     resp.sendRedirect("/signedIn.jsp");
   } catch (IOException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
 }
Exemplo n.º 17
0
  public Topic parseThread(String text) throws ContentParseException {
    int omPosts = 0;
    Matcher mat = omPostsPattern.matcher(text);
    if (mat.find()) omPosts = Integer.parseInt(mat.group(1));

    int omImages = 0;
    mat = omImagesPattern.matcher(text);
    if (mat.find()) omImages = Integer.parseInt(mat.group(1));

    Post op = this.parsePost(text, 0);
    Topic thread = new Topic(op.getNum(), omPosts, omImages);
    thread.addPost(op);

    return thread;
  }
Exemplo n.º 18
0
  @Test
  public void test_Marshall_List() {
    Post post = new Post();
    post.setTags(list("tag1", "tag2", "tag3"));

    IdentityHashMap<Object, Entity> stack = testMarshaller.marshall(null, post);
    Entity e = stack.get(post);
    Object tags = e.getProperty("tags");

    assertNotNull(e);
    assertTrue(tags instanceof List);
    assertEquals("tag1", ((List) tags).get(0));
    assertEquals("tag2", ((List) tags).get(1));
    assertEquals("tag3", ((List) tags).get(2));
  }
Exemplo n.º 19
0
 /** 撤销机构 */
 @Override
 public void terminate(Date date) {
   if (getTopOrganization().equals(this)) {
     throw new TerminateRootOrganizationException();
   }
   if (hasEmployees(date)) {
     throw new TerminateNotEmptyOrganizationException();
   }
   for (Post post : getPosts(date)) {
     post.terminate(date);
   }
   for (Organization child : getChildren(date)) {
     child.terminate(date);
   }
   super.terminate(date);
 }
 /**
  * Gets the parameters of the GetCapabilities capability answer.
  *
  * @return The operation type representing the GetCapabilities operation.
  */
 private OperationType getCapOperation(WMSResponse wmsResponse) {
   OperationType opCap = new OperationType();
   opCap.getFormat().add("text/xml");
   Get getCap = new Get();
   getCap.setOnlineResource(
       buildOnlineResource(wmsResponse, WMSProperties.CAP_GET, "GetCapabilities"));
   Post postCap = new Post();
   postCap.setOnlineResource(
       buildOnlineResource(wmsResponse, WMSProperties.CAP_POST, "GetCapabilities"));
   HTTP httpCap = new HTTP();
   httpCap.setGet(getCap);
   httpCap.setPost(postCap);
   DCPType dcpTypeCap = new DCPType();
   dcpTypeCap.setHTTP(httpCap);
   opCap.getDCPType().add(dcpTypeCap);
   return opCap;
 }
Exemplo n.º 21
0
 public void handleMessage(Message msg) {
   super.handleMessage(msg);
   switch (msg.what) {
     case 1:
       try {
         Post post = (Post) msg.obj;
         Bitmap bitmap = (Bitmap) (msg.getData().getParcelable("bitmap"));
         bitmap = Bitmap.createScaledBitmap(bitmap, 50, 50, false);
         post.setBitmap(bitmap);
         runOnUiThread(postFetched);
       } catch (Exception e) {
         // Ignore errors
       }
       break;
   }
   // progressDialog.dismiss();
 }
  @Test
  public void test() {

    doInJPA(
        entityManager -> {
          Post post = new Post();
          post.setId(1L);
          post.setTitle("High-Performance Java Persistence");
          entityManager.persist(post);
        });
    doInJPA(
        entityManager -> {
          Post post = entityManager.find(Post.class, 1L);
          LOGGER.info("Fetched post: {}", post);
          post.setScore(12);
        });
  }
Exemplo n.º 23
0
  @Override
  public void onUpdate(SortedSet<Post> posts) {
    synchronized (cells) {
      boolean formCellAdded = false;
      long beforeFormCellId = Long.MAX_VALUE;
      if (!cells.get(cells.size() - 1).equals(formCell)) {
        final int currentPos = cells.indexOf(formCell);
        beforeFormCellId = cells.get(currentPos - 1).getItemId();
      }

      cells.clear();
      Date prevDate = null;
      Date lastSeparatorDate = null;
      ListCell prevCell = null;
      for (Post post : posts) {
        Date currentDate = Post.virtualTimestampToDate(post.getVirtualTimestamp());
        if (prevDate == null || !isSameDate(prevDate, currentDate)) {
          lastSeparatorDate = currentDate;
          prevCell = new DateSeparatorCell(currentDate);
          cells.add(prevCell);
          if (!formCellAdded && prevCell.getItemId() == beforeFormCellId) {
            cells.add(formCell);
            formCellAdded = true;
          }
        }
        prevDate = currentDate;

        prevCell = new PostCell(post);
        cells.add(prevCell);
        if (!formCellAdded && prevCell.getItemId() == beforeFormCellId) {
          cells.add(formCell);
          formCellAdded = true;
        }
      }

      if (lastSeparatorDate == null || !isSameDate(lastSeparatorDate, new Date())) {
        cells.add(new DateSeparatorCell(new Date()));
      }

      if (!formCellAdded) {
        cells.add(formCell);
      }
      observable.notifyChanged();
    }
  }
Exemplo n.º 24
0
      @Override
      public void onClick(View v) {
        final int currentPos = cells.indexOf(formCell);
        long prevVirtualTimestamp = -1;
        long nextVirtualTimestamp = -1;
        if (currentPos != cells.size() - 1) {
          // The form position is not the end of the list.
          if (currentPos == 0) {
            prevVirtualTimestamp = 0;
            nextVirtualTimestamp = cells.get(currentPos + 1).getVirtualTimestamp();
          } else {
            prevVirtualTimestamp = cells.get(currentPos - 1).getVirtualTimestamp();
            nextVirtualTimestamp = cells.get(currentPos + 1).getVirtualTimestamp();
          }
        }

        if (prevVirtualTimestamp != -1
            && nextVirtualTimestamp != -1
            && !isSameDate(
                Post.virtualTimestampToDate(prevVirtualTimestamp),
                Post.virtualTimestampToDate(nextVirtualTimestamp))) {
          // Make sure to make a post not to beyond a day.
          Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("Asia/Tokyo"));
          cal.setTime(Post.virtualTimestampToDate(prevVirtualTimestamp));
          cal.set(Calendar.HOUR_OF_DAY, 23);
          cal.set(Calendar.MINUTE, 59);
          cal.set(Calendar.SECOND, 59);
          cal.set(Calendar.MILLISECOND, 999);
          nextVirtualTimestamp = Post.dateToVirtualTimestamp(cal.getTime());
        }

        if (v.getId() == R.id.postButton) {
          Intent intent = new Intent(activity, PostTimelineActivity.class);
          intent.putExtra(PostTimelineActivity.LECTURE_ID, lectureId);
          intent.putExtra(PostTimelineActivity.PREV_VIRTUAL_TS, prevVirtualTimestamp);
          intent.putExtra(PostTimelineActivity.NEXT_VIRTUAL_TS, nextVirtualTimestamp);
          activity.startActivityForResult(intent, 0);
        } else if (v.getId() == R.id.postImageButton) {
          Intent intent = new Intent(activity, PostImageActivity.class);
          intent.putExtra(PostImageActivity.LECTURE_ID, lectureId);
          intent.putExtra(PostImageActivity.PREV_VIRTUAL_TS, prevVirtualTimestamp);
          intent.putExtra(PostImageActivity.NEXT_VIRTUAL_TS, nextVirtualTimestamp);
          activity.startActivityForResult(intent, 0);
        }
      }
Exemplo n.º 25
0
  @Test
  public void canQueryByEntityType() {
    try (IDocumentStore store = new DocumentStore(getDefaultUrl(), getDefaultDb()).initialize()) {
      try (IDocumentSession session = store.openSession()) {

        Post post = new Post();
        post.setTitle("test");
        post.setBody("casing");
        session.store(post);
        session.saveChanges();

        Post single =
            session.advanced().documentQuery(Post.class).waitForNonStaleResults().single();

        assertEquals("test", single.getTitle());
      }
    }
  }
 /**
  * Gets the parameters of the GetMap capability answer.
  *
  * @return The operation type representing the getMap operation.
  */
 private OperationType getMapOperation(WMSResponse wmsResponse) {
   OperationType opMap = new OperationType();
   for (ImageFormats im : ImageFormats.values()) {
     opMap.getFormat().add(im.toString());
   }
   Get get = new Get();
   get.setOnlineResource(buildOnlineResource(wmsResponse, WMSProperties.MAP_GET, "GetMap"));
   Post post = new Post();
   post.setOnlineResource(buildOnlineResource(wmsResponse, WMSProperties.MAP_POST, "GetMap"));
   // We feed the http object
   HTTP http = new HTTP();
   http.setGet(get);
   http.setPost(post);
   DCPType dcpType = new DCPType();
   dcpType.setHTTP(http);
   opMap.getDCPType().add(dcpType);
   return opMap;
 }
Exemplo n.º 27
0
  @Test
  public void unitOfWorkEvenWhenQuerying() {
    try (IDocumentStore store = new DocumentStore(getDefaultUrl(), getDefaultDb()).initialize()) {
      try (IDocumentSession session = store.openSession()) {

        Post post = new Post();
        post.setTitle("test");
        post.setBody("casing");
        session.store(post);
        session.saveChanges();

        Post single =
            session.advanced().documentQuery(Post.class).waitForNonStaleResults().single();

        assertSame(post, single);
      }
    }
  }
 private OperationType getFeatureOperation(WMSResponse wmsResponse) {
   OperationType opFeature = new OperationType();
   opFeature.getFormat().add("text/xml");
   // GET
   Get getFeature = new Get();
   getFeature.setOnlineResource(
       buildOnlineResource(wmsResponse, WMSProperties.FEATURE_GET, "GetFeatureInfo"));
   // POST
   Post postFeature = new Post();
   postFeature.setOnlineResource(
       buildOnlineResource(wmsResponse, WMSProperties.FEATURE_POST, "GetFeatureInfo"));
   // Both in HTTP
   HTTP httpFeature = new HTTP();
   httpFeature.setGet(getFeature);
   httpFeature.setPost(postFeature);
   DCPType dcpTypeFeature = new DCPType();
   dcpTypeFeature.setHTTP(httpFeature);
   opFeature.getDCPType().add(dcpTypeFeature);
   return opFeature;
 }
Exemplo n.º 29
0
 private static void handleNonDownloadPost(Post post) {
   for (Picture picture : post.pictures) {
     if (!Main.pic_pic_hash.containsKey(picture)) {
       Main.pic_pic_hash.put(picture, picture);
       Main.pic_post_hash.put(picture, post);
     } else {
       if (!post.equals(Main.pic_post_hash.get(picture))) {
         dup_post_list.put(post, Main.pic_post_hash.get(picture));
       }
     }
   }
 }
Exemplo n.º 30
0
  private void saveEditPost(HttpServletRequest req, HttpServletResponse resp) {
    ShubUser user = (ShubUser) req.getSession().getAttribute("user");

    String overallText = voidOverallChecking("");
    String fbText = voidFacebookChecking(req.getParameter("fbEditText"), overallText, req);
    String twitterText = voidTwitterChecking(req.getParameter("twitterEditText"), overallText, req);
    System.out.println(fbText + " twitter's is " + twitterText);
    req.getSession().removeAttribute("fbEditText");
    req.getSession().removeAttribute("twitterEditText");
    Blob blob = (Blob) req.getSession().getAttribute("curBlob");

    String date = req.getParameter("hiddenDate").toString();
    Post post = user.getNewsfeed().getPost(date);

    BlobKey key = post.getPicture();
    req.getSession().setAttribute("blobKey", key);
    req.getSession().setAttribute("editImageURL", post.getBlobURL());
    req.getSession().setAttribute("deleteDate", date);

    if (blob != null && req.getParameter("myPhoto") != null) {
      //	    	user.postWithMedia(overallText, fbText, twitterText, req, resp);
    } else {
      try {
        user.post(overallText, fbText, twitterText, req, resp);
      } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }

    // Delete the previous post

    //		Post post = user.getNewsfeed().getPost(date);
    //		try {
    //			user.deletePost(req, resp, post);
    //		} catch (IOException e) {
    //			// TODO Auto-generated catch block
    //			e.printStackTrace();
    //		}
  }