@Override public MBThread moveThreadToTrash(long userId, MBThread thread) throws PortalException { // Thread if (thread.getCategoryId() == MBCategoryConstants.DISCUSSION_CATEGORY_ID) { return thread; } int oldStatus = thread.getStatus(); if (oldStatus == WorkflowConstants.STATUS_PENDING) { thread.setStatus(WorkflowConstants.STATUS_DRAFT); mbThreadPersistence.update(thread); } thread = updateStatus(userId, thread.getThreadId(), WorkflowConstants.STATUS_IN_TRASH); // Trash TrashEntry trashEntry = trashEntryLocalService.addTrashEntry( userId, thread.getGroupId(), MBThread.class.getName(), thread.getThreadId(), thread.getUuid(), null, oldStatus, null, null); // Messages moveDependentsToTrash(thread.getGroupId(), thread.getThreadId(), trashEntry.getEntryId()); // Social MBMessage message = mbMessageLocalService.getMBMessage(thread.getRootMessageId()); JSONObject extraDataJSONObject = JSONFactoryUtil.createJSONObject(); extraDataJSONObject.put("rootMessageId", thread.getRootMessageId()); extraDataJSONObject.put("title", message.getSubject()); SocialActivityManagerUtil.addActivity( userId, thread, SocialActivityConstants.TYPE_MOVE_TO_TRASH, extraDataJSONObject.toString(), 0); return thread; }
@Override public PortletURL getViewContentURL(HttpServletRequest request, String className, long classPK) throws PortalException { ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY); String portletId = PortletProviderUtil.getPortletId(TrashEntry.class.getName(), PortletProvider.Action.VIEW); if (!themeDisplay.isSignedIn() || !isTrashEnabled(themeDisplay.getScopeGroupId()) || !PortletPermissionUtil.hasControlPanelAccessPermission( themeDisplay.getPermissionChecker(), themeDisplay.getScopeGroupId(), portletId)) { return null; } TrashHandler trashHandler = TrashHandlerRegistryUtil.getTrashHandler(className); if (trashHandler.isInTrashContainer(classPK)) { TrashEntry trashEntry = trashHandler.getTrashEntry(classPK); className = trashEntry.getClassName(); classPK = trashEntry.getClassPK(); trashHandler = TrashHandlerRegistryUtil.getTrashHandler(className); } TrashRenderer trashRenderer = trashHandler.getTrashRenderer(classPK); if (trashRenderer == null) { return null; } PortletURL portletURL = PortalUtil.getControlPanelPortletURL(request, portletId, PortletRequest.RENDER_PHASE); portletURL.setParameter("mvcPath", "/view_content.jsp"); portletURL.setParameter("redirect", themeDisplay.getURLCurrent()); TrashEntry trashEntry = TrashEntryLocalServiceUtil.getEntry(className, classPK); if (trashEntry.getRootEntry() != null) { portletURL.setParameter("className", className); portletURL.setParameter("classPK", String.valueOf(classPK)); } else { portletURL.setParameter("trashEntryId", String.valueOf(trashEntry.getEntryId())); } portletURL.setParameter("showAssetMetadata", Boolean.TRUE.toString()); return portletURL; }
@Override public void addTrashSessionMessages( ActionRequest actionRequest, List<TrashedModel> trashedModels, String cmd) { ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY); List<String> classNames = new ArrayList<>(); List<Long> restoreTrashEntryIds = new ArrayList<>(); List<String> titles = new ArrayList<>(); for (int i = 0; i < trashedModels.size(); i++) { try { TrashedModel trashedModel = trashedModels.get(i); TrashEntry trashEntry = trashedModel.getTrashEntry(); TrashHandler trashHandler = trashedModel.getTrashHandler(); TrashRenderer trashRenderer = trashHandler.getTrashRenderer(trashedModel.getTrashEntryClassPK()); classNames.add(trashRenderer.getClassName()); restoreTrashEntryIds.add(trashEntry.getEntryId()); titles.add(trashRenderer.getTitle(themeDisplay.getLocale())); } catch (Exception e) { } } Map<String, String[]> data = new HashMap<>(); data.put(Constants.CMD, new String[] {cmd}); data.put("deleteEntryClassName", ArrayUtil.toStringArray(classNames.toArray())); data.put("deleteEntryTitle", ArrayUtil.toStringArray(titles.toArray())); data.put("restoreTrashEntryIds", ArrayUtil.toStringArray(restoreTrashEntryIds.toArray())); SessionMessages.add( actionRequest, PortalUtil.getPortletId(actionRequest) + SessionMessages.KEY_SUFFIX_DELETE_SUCCESS_DATA, data); }
@Override public void restoreThreadFromTrash(long userId, long threadId) throws PortalException { // Thread MBThread thread = getThread(threadId); if (thread.getCategoryId() == MBCategoryConstants.DISCUSSION_CATEGORY_ID) { return; } TrashEntry trashEntry = trashEntryLocalService.getEntry(MBThread.class.getName(), threadId); updateStatus(userId, threadId, trashEntry.getStatus()); // Messages restoreDependentsFromTrash(thread.getGroupId(), threadId); // Trash trashEntryLocalService.deleteEntry(trashEntry.getEntryId()); // Social MBMessage message = mbMessageLocalService.getMBMessage(thread.getRootMessageId()); JSONObject extraDataJSONObject = JSONFactoryUtil.createJSONObject(); extraDataJSONObject.put("rootMessageId", thread.getRootMessageId()); extraDataJSONObject.put("title", message.getSubject()); SocialActivityManagerUtil.addActivity( userId, thread, SocialActivityConstants.TYPE_RESTORE_FROM_TRASH, extraDataJSONObject.toString(), 0); }