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; }
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; }