@Override protected void doExportStagedModel(PortletDataContext portletDataContext, MBThreadFlag threadFlag) throws Exception { MBThread thread = MBThreadLocalServiceUtil.getThread(threadFlag.getThreadId()); MBMessage rootMessage = MBMessageLocalServiceUtil.getMessage(thread.getRootMessageId()); if ((rootMessage.getStatus() != WorkflowConstants.STATUS_APPROVED) || (rootMessage.getCategoryId() == MBCategoryConstants.DISCUSSION_CATEGORY_ID)) { return; } StagedModelDataHandlerUtil.exportStagedModel(portletDataContext, rootMessage); Element threadFlagElement = portletDataContext.getExportDataElement(threadFlag); threadFlagElement.addAttribute("root-message-id", String.valueOf(rootMessage.getMessageId())); portletDataContext.addClassedModel( threadFlagElement, ExportImportPathUtil.getModelPath(threadFlag), threadFlag, MBPortletDataHandler.NAMESPACE); }
@Override protected void doImportStagedModel(PortletDataContext portletDataContext, MBThreadFlag threadFlag) throws Exception { Map<Long, Long> threadIds = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(MBThread.class); long threadId = MapUtil.getLong(threadIds, threadFlag.getThreadId(), threadFlag.getThreadId()); if (threadId == threadFlag.getThreadId()) { Element element = portletDataContext.getImportDataStagedModelElement(threadFlag); long rootMessageId = GetterUtil.getLong(element.attributeValue("root-message-id")); String rootMessagePath = ExportImportPathUtil.getModelPath( portletDataContext, MBMessage.class.getName(), rootMessageId); MBMessage rootMessage = (MBMessage) portletDataContext.getZipEntryAsObject(rootMessagePath); StagedModelDataHandlerUtil.importStagedModel(portletDataContext, rootMessage); threadId = MapUtil.getLong(threadIds, threadFlag.getThreadId(), threadFlag.getThreadId()); } MBThread thread = MBThreadLocalServiceUtil.fetchThread(threadId); if (thread == null) { return; } long userId = portletDataContext.getUserId(threadFlag.getUserUuid()); ServiceContext serviceContext = portletDataContext.createServiceContext(threadFlag, MBPortletDataHandler.NAMESPACE); MBThreadFlagLocalServiceUtil.addThreadFlag(userId, thread, serviceContext); }