Пример #1
0
 public ServiceResult<Page> findPage(Long id, boolean isIncreaseView) {
   ServiceResult<Page> result = new ServiceResult<Page>();
   Page page = null;
   PersistenceManager pm = null;
   try {
     pm = PMF.get().getPersistenceManager();
     page = pm.getObjectById(Page.class, id);
     if (page == null) {
       result.setOK(false);
       result.setMessage(Global.messages.getString("no_page_found"));
     } else {
       result.setMessage(Global.messages.getString("page_found"));
       result.setOK(true);
       result.setResult(page);
       if (isIncreaseView) {
         page.setPage_view(page.getPage_view() + 1);
       }
     }
   } catch (Exception e) {
     e.printStackTrace();
     result.setMessage(Global.messages.getString("find_page_fail"));
   } finally {
     try {
       pm.close();
     } catch (Exception e) {
       e.printStackTrace();
     }
   }
   return result;
 }
Пример #2
0
 public ServiceResult<Long> insertPage(Page page) {
   // updateFTSStuffForPage(page);
   page.updateFTS();
   ServiceResult<Long> result = new ServiceResult<Long>();
   PersistenceManager pm = PMF.get().getPersistenceManager();
   try {
     page = pm.makePersistent(page);
     if (page == null) {
       result.setMessage(Global.messages.getString("insert_page_fail"));
     } else {
       result.setResult(page.getId());
       result.setMessage(Global.messages.getString("insert_page_successfully"));
       result.setOK(true);
     }
   } catch (Exception e) {
     e.printStackTrace();
     result.setMessage(Global.messages.getString("insert_page_fail"));
   } finally {
     try {
       pm.close();
     } catch (Exception e) {
       e.printStackTrace();
     }
   }
   return result;
 }
Пример #3
0
 public ServiceResult<Void> untagProductToPage(Long pageID, Long productID) {
   ServiceResult<Void> result = new ServiceResult<Void>();
   Page page = null;
   Product product = null;
   PersistenceManager pm = PMF.get().getPersistenceManager();
   try {
     page = pm.getObjectById(Page.class, pageID);
     product = pm.getObjectById(Product.class, productID);
     if (page == null || product == null) {
       result.setMessage(Global.messages.getString("no_page_or_product"));
     } else {
       page.getSetProduct().remove(productID);
       product.getSetPagesID().remove(pageID);
       result.setOK(true);
       result.setMessage(Global.messages.getString("untag_product_into_page_successfully"));
     }
   } catch (Exception e) {
     e.printStackTrace();
     result.setMessage(Global.messages.getString("untag_product_into_page_fail"));
   } finally {
     try {
       pm.close();
     } catch (Exception e) {
       e.printStackTrace();
     }
   }
   if (result.isOK()) {
     ServiceResult<Void> notiResult =
         dbNoti.insertWhenUserTagProductToPage(pageID, productID, false);
     if (notiResult.isOK() == false) {
       result.setMessage(
           result.getMessage() + ";Notification Exception:" + notiResult.getMessage());
     }
   }
   return result;
 }
Пример #4
0
 public ServiceResult<Set<String>> tagFriendToPage(
     long pageID, String[] usernames, String username) {
   ServiceResult<Set<String>> result = new ServiceResult<Set<String>>();
   result.setOK(true);
   PersistenceManager pm = null;
   UserInfo user = null;
   Page page = null;
   try {
     pm = PMF.get().getPersistenceManager();
     page = pm.getObjectById(Page.class, pageID);
     if (page == null) {
       result.setOK(false);
       result.setMessage(Global.messages.getString("no_page_found"));
     } else {
       if (!page.getUsername().equals(username)) {
         result.setOK(false);
         result.setMessage(
             String.format(Global.messages.getString("no_permission_to_tag_to_page"), username));
       } else {
         ServiceResult<Void> notiResult = null;
         for (String user2Tag : usernames) {
           try {
             if (page.getSetFriendsTaggedID().contains(user2Tag)) {
               result.setOK(false);
               result.setMessage(
                   result.getMessage()
                       + ";"
                       + String.format(
                           Global.messages.getString("already_tag_user_to_page"),
                           user2Tag,
                           pageID));
             } else {
               user = pm.getObjectById(UserInfo.class, user2Tag);
               page.getSetFriendsTaggedID().add(user2Tag);
               user.getSetPageTaggedID().add(pageID);
               result.setMessage(
                   result.getMessage()
                       + ";"
                       + String.format(
                           Global.messages.getString("tag_user_to_page_successfully"),
                           user2Tag,
                           pageID));
               // notification
               notiResult = dbNoti.insertWhenTagUserToPage(pageID, user2Tag, true);
               if (notiResult.isOK() == false) {
                 result.setMessage(
                     result.getMessage() + ";Notification Exception:" + notiResult.getMessage());
               }
             }
           } catch (Exception e) {
             e.printStackTrace();
             result.setOK(false);
             result.setMessage(
                 result.getMessage()
                     + ";"
                     + String.format(
                         Global.messages.getString("tag_user_to_page_fail"), user2Tag, pageID));
           }
         }
         // if (result.isOK()) {
         // result.setMessage("Tag friends thanh cong");
         // }
       }
     }
   } catch (Exception e) {
     e.printStackTrace();
     result.setMessage(Global.messages.getString("tag_friend_to_page_fail"));
   } finally {
     try {
       pm.close();
     } catch (Exception e) {
       e.printStackTrace();
     }
   }
   if (result.isOK()) {
     result.setResult(page.getSetFriendsTaggedID());
   }
   return result;
 }
Пример #5
0
 public static void preventSQLInjPage(Page page) {
   page.setName(DatabaseUtils.preventSQLInjection(page.getName()));
   page.setContent(DatabaseUtils.preventSQLInjection(page.getContent()));
 }
Пример #6
0
 public ServiceResult<Void> updatePage(Page editPage) {
   ServiceResult<Void> result = new ServiceResult<Void>();
   Page page = null;
   PersistenceManager pm = null;
   try {
     pm = PMF.get().getPersistenceManager();
     page = pm.getObjectById(Page.class, editPage.getId());
     if (page == null) {
       result.setOK(false);
       result.setMessage(Global.messages.getString("no_page_found"));
     } else {
       page.setContent(editPage.getContent());
       page.setDate_post(editPage.getDate_post());
       page.setLast_modified(editPage.getLast_modified());
       page.setLink_thumbnail(editPage.getLink_thumbnail());
       page.setName(editPage.getName());
       page.setPage_view(editPage.getPage_view());
       page.setSetCategoryKeys(editPage.getSetCategoryKeys());
       page.setSetProduct(editPage.getSetProduct());
       result.setOK(true);
       result.setMessage(Global.messages.getString("update_page_successfully"));
     }
   } catch (Exception e) {
     result.setMessage(Global.messages.getString("update_page_fail"));
     result.setOK(false);
     e.printStackTrace();
   } finally {
     try {
       pm.close();
     } catch (Exception e) {
       e.printStackTrace();
     }
   }
   return result;
 }