List of usage examples for com.liferay.portal.kernel.workflow WorkflowThreadLocal isEnabled
public static boolean isEnabled()
From source file:com.liferay.blogs.test.util.BlogsTestUtil.java
License:Open Source License
public static BlogsEntry addEntryWithWorkflow(long userId, String title, boolean approved, ServiceContext serviceContext) throws Exception { boolean workflowEnabled = WorkflowThreadLocal.isEnabled(); try {/*from w w w . j a v a 2 s . c o m*/ WorkflowThreadLocal.setEnabled(true); Calendar displayCalendar = CalendarFactoryUtil.getCalendar(2012, 1, 1); serviceContext = (ServiceContext) serviceContext.clone(); serviceContext.setWorkflowAction(WorkflowConstants.ACTION_SAVE_DRAFT); BlogsEntry entry = BlogsEntryLocalServiceUtil.addEntry(userId, title, RandomTestUtil.randomString(), RandomTestUtil.randomString(), RandomTestUtil.randomString(), displayCalendar.getTime(), true, true, new String[0], StringPool.BLANK, null, null, serviceContext); if (approved) { return updateStatus(entry, serviceContext); } return entry; } finally { WorkflowThreadLocal.setEnabled(workflowEnabled); } }
From source file:com.liferay.bookmarks.util.test.BookmarksTestUtil.java
License:Open Source License
public static BookmarksEntry addEntry(String name, long folderId, boolean approved, ServiceContext serviceContext) throws Exception { boolean workflowEnabled = WorkflowThreadLocal.isEnabled(); try {/* ww w. j a v a 2 s. c o m*/ WorkflowThreadLocal.setEnabled(true); String url = "http://www.liferay.com"; String description = "This is a test entry."; serviceContext = (ServiceContext) serviceContext.clone(); serviceContext.setWorkflowAction(WorkflowConstants.ACTION_SAVE_DRAFT); BookmarksEntry entry = BookmarksEntryServiceUtil.addEntry(serviceContext.getScopeGroupId(), folderId, name, url, description, serviceContext); serviceContext.setCommand(Constants.ADD); serviceContext.setLayoutFullURL("http://localhost"); if (approved) { entry.setStatus(WorkflowConstants.STATUS_APPROVED); entry = BookmarksEntryServiceUtil.updateEntry(entry.getEntryId(), serviceContext.getScopeGroupId(), entry.getFolderId(), entry.getName(), entry.getUrl(), entry.getUrl(), serviceContext); } return entry; } finally { WorkflowThreadLocal.setEnabled(workflowEnabled); } }
From source file:com.liferay.calendar.test.util.CalendarBookingTestUtil.java
License:Open Source License
public static CalendarBooking addRegularCalendarBookingWithWorkflow(User user, Calendar calendar, ServiceContext serviceContext) throws PortalException { boolean workflowEnabled = WorkflowThreadLocal.isEnabled(); try {/*from w w w.ja va 2 s. c o m*/ WorkflowThreadLocal.setEnabled(true); serviceContext = (ServiceContext) serviceContext.clone(); serviceContext.setWorkflowAction(WorkflowConstants.ACTION_SAVE_DRAFT); return addRegularCalendarBooking(user, calendar, serviceContext); } finally { WorkflowThreadLocal.setEnabled(workflowEnabled); } }
From source file:com.liferay.document.library.file.rank.trash.test.DLFileRankTrashHandlerTest.java
License:Open Source License
protected void trashDLFileRank() throws Exception { Group group = GroupTestUtil.addGroup(); ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(group.getGroupId()); Folder folder = addFolder(group, DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, serviceContext); TrashHandler trashHandler = TrashHandlerRegistryUtil.getTrashHandler(DLFileEntry.class.getName()); FileEntry fileEntry = null;//from w ww .j a v a2 s . co m try { boolean workflowEnabled = WorkflowThreadLocal.isEnabled(); try { WorkflowThreadLocal.setEnabled(true); fileEntry = addFileEntry(folder, serviceContext); } finally { WorkflowThreadLocal.setEnabled(workflowEnabled); } DLAppLocalServiceUtil.addFileRank(group.getGroupId(), TestPropsValues.getCompanyId(), TestPropsValues.getUserId(), fileEntry.getFileEntryId(), serviceContext); Assert.assertEquals(1, getActiveDLFileRanksCount(group.getGroupId(), fileEntry.getFileEntryId())); DLTrashServiceUtil.moveFileEntryToTrash(fileEntry.getFileEntryId()); Assert.assertEquals(0, getActiveDLFileRanksCount(group.getGroupId(), fileEntry.getFileEntryId())); trashHandler.restoreTrashEntry(TestPropsValues.getUserId(), fileEntry.getFileEntryId()); Assert.assertEquals(1, getActiveDLFileRanksCount(group.getGroupId(), fileEntry.getFileEntryId())); } finally { trashHandler.deleteTrashEntry(fileEntry.getFileEntryId()); } }
From source file:com.liferay.document.library.internal.repository.capabilities.LiferayWorkflowCapability.java
License:Open Source License
@Override public void addFileEntry(long userId, FileEntry fileEntry, ServiceContext serviceContext) throws PortalException { boolean previousEnabled = WorkflowThreadLocal.isEnabled(); if (!DLAppHelperThreadLocal.isEnabled()) { WorkflowThreadLocal.setEnabled(false); }// w ww .ja va 2s . c om try { FileVersion fileVersion = fileEntry.getFileVersion(); DLUtil.startWorkflowInstance(userId, (DLFileVersion) fileVersion.getModel(), DLSyncConstants.EVENT_ADD, serviceContext); } finally { if (!DLAppHelperThreadLocal.isEnabled()) { WorkflowThreadLocal.setEnabled(previousEnabled); } } }
From source file:com.liferay.exportimport.test.util.lar.BaseWorkflowedStagedModelDataHandlerTestCase.java
License:Open Source License
@Test public void testExportWorkflowedStagedModels() throws Exception { initExport();//w w w . j a v a 2 s. c om List<StagedModel> stagedModels = null; boolean workflowEnabled = WorkflowThreadLocal.isEnabled(); try { WorkflowThreadLocal.setEnabled(true); stagedModels = addWorkflowedStagedModels(stagingGroup); } finally { WorkflowThreadLocal.setEnabled(workflowEnabled); } for (StagedModel stagedModel : stagedModels) { Assert.assertTrue("Staged model is not a workflowed model", stagedModel instanceof WorkflowedModel); try { StagedModelDataHandlerUtil.exportStagedModel(portletDataContext, stagedModel); } catch (PortletDataException pde) { Assert.assertEquals("An unexpected error occurred during the export", PortletDataException.STATUS_UNAVAILABLE, pde.getType()); } validateWorkflowedExport(portletDataContext, stagedModel); } }
From source file:com.liferay.message.boards.internal.service.MBDiscussionMBMessageLocalServiceWrapper.java
License:Open Source License
@Override public MBMessage addDiscussionMessage(long userId, String userName, long groupId, String className, long classPK, int workflowAction) throws PortalException { super.addDiscussionMessage(userId, userName, groupId, className, classPK, workflowAction); long threadId = 0; long parentMessageId = MBMessageConstants.DEFAULT_PARENT_MESSAGE_ID; String subject = String.valueOf(classPK); String body = subject;// w ww.j a va2s. c o m ServiceContext serviceContext = new ServiceContext(); serviceContext.setWorkflowAction(workflowAction); boolean workflowEnabled = WorkflowThreadLocal.isEnabled(); WorkflowThreadLocal.setEnabled(false); try { return addDiscussionMessage(userId, userName, groupId, className, classPK, threadId, parentMessageId, subject, body, serviceContext); } finally { WorkflowThreadLocal.setEnabled(workflowEnabled); } }
From source file:com.liferay.message.boards.internal.service.MBDiscussionMBMessageLocalServiceWrapper.java
License:Open Source License
@Override public MBMessageDisplay getDiscussionMessageDisplay(long userId, long groupId, String className, long classPK, int status, Comparator<MBMessage> comparator) throws PortalException { super.getDiscussionMessageDisplay(userId, groupId, className, classPK, status, comparator); MBMessage message = null;/* ww w. j a va2 s . c o m*/ MBDiscussion discussion = _mbDiscussionLocalService.fetchDiscussion(className, classPK); if (discussion != null) { message = _mbMessageLocalService.getFirstMessage(discussion.getThreadId(), MBMessageConstants.DEFAULT_PARENT_MESSAGE_ID); } else { boolean workflowEnabled = WorkflowThreadLocal.isEnabled(); WorkflowThreadLocal.setEnabled(false); try { String subject = String.valueOf(classPK); //String body = subject; message = addDiscussionMessage(userId, null, groupId, className, classPK, 0, MBMessageConstants.DEFAULT_PARENT_MESSAGE_ID, subject, subject, new ServiceContext()); } catch (SystemException se) { if (_log.isWarnEnabled()) { _log.warn("Add failed, fetch {threadId=0, parentMessageId=" + MBMessageConstants.DEFAULT_PARENT_MESSAGE_ID + "}"); } message = _mbMessageLocalService.fetchFirstMessage(0, MBMessageConstants.DEFAULT_PARENT_MESSAGE_ID); if (message == null) { throw se; } } finally { WorkflowThreadLocal.setEnabled(workflowEnabled); } } return getMessageDisplay(userId, message, status, comparator); }
From source file:com.liferay.message.boards.test.util.MBTestUtil.java
License:Open Source License
public static MBMessage addMessageWithWorkflow(long groupId, long categoryId, String subject, String body, boolean approved, ServiceContext serviceContext) throws Exception { boolean workflowEnabled = WorkflowThreadLocal.isEnabled(); try {// w w w . j a va 2s . c o m WorkflowThreadLocal.setEnabled(true); serviceContext = (ServiceContext) serviceContext.clone(); serviceContext.setWorkflowAction(WorkflowConstants.ACTION_SAVE_DRAFT); MBMessage message = MBMessageLocalServiceUtil.addMessage(serviceContext.getUserId(), RandomTestUtil.randomString(), groupId, categoryId, subject, body, serviceContext); if (approved) { return updateStatus(message, serviceContext); } return message; } finally { WorkflowThreadLocal.setEnabled(workflowEnabled); } }
From source file:com.liferay.portlet.messageboards.service.impl.MBMessageLocalServiceImpl.java
License:Open Source License
public MBMessage addDiscussionMessage(long userId, String userName, long groupId, String className, long classPK, int workflowAction) throws PortalException, SystemException { long threadId = 0; long parentMessageId = 0; String subject = String.valueOf(classPK); String body = subject;// w ww . j a va2s .com ServiceContext serviceContext = new ServiceContext(); serviceContext.setWorkflowAction(workflowAction); boolean workflowEnabled = WorkflowThreadLocal.isEnabled(); WorkflowThreadLocal.setEnabled(false); try { return addDiscussionMessage(userId, userName, groupId, className, classPK, threadId, parentMessageId, subject, body, serviceContext); } finally { WorkflowThreadLocal.setEnabled(workflowEnabled); } }