Example usage for com.liferay.portal.kernel.service ServiceContext setWorkflowAction

List of usage examples for com.liferay.portal.kernel.service ServiceContext setWorkflowAction

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.service ServiceContext setWorkflowAction.

Prototype

public void setWorkflowAction(int workflowAction) 

Source Link

Document

Sets the workflow action to take if this service context is being passed as parameter to a method that processes a workflow action.

Usage

From source file:com.liferay.blogs.service.test.BlogsEntryLocalServiceTest.java

License:Open Source License

@Test
public void testURLTitleIsNotSavedWhenAddingDraftEntry() throws Exception {
    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group, _user.getUserId());

    serviceContext.setWorkflowAction(WorkflowConstants.STATUS_DRAFT);

    BlogsEntry entry = BlogsEntryLocalServiceUtil.addEntry(_user.getUserId(), RandomTestUtil.randomString(),
            RandomTestUtil.randomString(), serviceContext);

    Assert.assertTrue(Validator.isNull(entry.getUrlTitle()));
}

From source file:com.liferay.blogs.service.test.BlogsEntryLocalServiceTest.java

License:Open Source License

@Test
public void testURLTitleIsNotUpdatedWhenUpdatingEntryTitleToDraftEntry() throws Exception {

    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group, _user.getUserId());

    BlogsEntry entry = BlogsEntryLocalServiceUtil.addEntry(_user.getUserId(), RandomTestUtil.randomString(),
            RandomTestUtil.randomString(), serviceContext);

    String urlTitle = entry.getUrlTitle();

    serviceContext.setWorkflowAction(WorkflowConstants.STATUS_DRAFT);

    entry = BlogsEntryLocalServiceUtil.updateEntry(_user.getUserId(), entry.getEntryId(),
            RandomTestUtil.randomString(), RandomTestUtil.randomString(), serviceContext);

    Assert.assertEquals(urlTitle, entry.getUrlTitle());
}

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  ww  . j a  v a2s .  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 {/*from  w  w w. ja v  a 2s. 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.service.test.CalendarBookingLocalServiceTest.java

License:Open Source License

@Test
public void testAddCalendarBookingDoesNotNotifyCreatorTwice() throws Exception {

    ServiceContext serviceContext = createServiceContext();

    _invitingUser = UserTestUtil.addUser();

    Calendar calendar = CalendarTestUtil.addCalendar(_invitingUser, serviceContext);

    Calendar invitedCalendar = CalendarTestUtil.addCalendar(_user, serviceContext);

    long startTime = System.currentTimeMillis() + Time.MINUTE;

    long endTime = startTime + Time.HOUR;

    long firstReminder = Time.MINUTE;

    serviceContext.setWorkflowAction(WorkflowConstants.ACTION_PUBLISH);

    CalendarBooking calendarBooking = CalendarBookingTestUtil.addCalendarBooking(_invitingUser, calendar,
            new long[] { invitedCalendar.getCalendarId() }, RandomTestUtil.randomLocaleStringMap(),
            RandomTestUtil.randomLocaleStringMap(), startTime, endTime, null, (int) firstReminder,
            NotificationType.EMAIL, 0, NotificationType.EMAIL, serviceContext);

    CalendarBooking childCalendarBooking = getChildCalendarBooking(calendarBooking);

    CalendarBookingLocalServiceUtil.updateStatus(_user.getUserId(), childCalendarBooking,
            CalendarBookingWorkflowConstants.STATUS_APPROVED, serviceContext);

    CalendarBookingLocalServiceUtil.checkCalendarBookings();

    String mailMessageSubject = "Calendar: Event Reminder for " + StringPool.QUOTE
            + calendarBooking.getTitle(LocaleUtil.getDefault()) + StringPool.QUOTE;

    List<com.dumbster.smtp.MailMessage> mailMessages = MailServiceTestUtil.getMailMessages("Subject",
            mailMessageSubject);/*from   w ww  .j a va  2  s . com*/

    Assert.assertEquals(mailMessages.toString(), 2, mailMessages.size());
}

From source file:com.liferay.calendar.service.test.CalendarBookingLocalServiceTest.java

License:Open Source License

@Test
public void testInviteToDraftCalendarBookingResultsInMasterPendingChild() throws Exception {

    ServiceContext serviceContext = createServiceContext();

    Calendar calendar = CalendarTestUtil.addCalendar(_user, serviceContext);

    Calendar invitedCalendar = CalendarTestUtil.addCalendar(calendar.getCalendarResource(), serviceContext);

    long startTime = System.currentTimeMillis();

    serviceContext.setWorkflowAction(WorkflowConstants.ACTION_SAVE_DRAFT);

    CalendarBooking calendarBooking = CalendarBookingTestUtil.addMasterCalendarBooking(_user, calendar,
            new long[] { invitedCalendar.getCalendarId() }, startTime, startTime + (Time.HOUR * 10),
            serviceContext);//from   w  ww  . ja v a  2 s . c o m

    CalendarBooking childCalendarBooking = getChildCalendarBooking(calendarBooking);

    Assert.assertEquals(CalendarBookingWorkflowConstants.STATUS_MASTER_PENDING,
            childCalendarBooking.getStatus());
}

From source file:com.liferay.calendar.service.test.CalendarBookingLocalServiceTest.java

License:Open Source License

@Test
public void testInviteToPublishedCalendarBookingResultsInPendingChild() throws Exception {

    ServiceContext serviceContext = createServiceContext();

    Calendar calendar = CalendarTestUtil.addCalendar(_user, serviceContext);

    Calendar invitedCalendar = CalendarTestUtil.addCalendar(calendar.getCalendarResource(), serviceContext);

    long startTime = System.currentTimeMillis();

    serviceContext.setWorkflowAction(WorkflowConstants.ACTION_PUBLISH);

    CalendarBooking calendarBooking = CalendarBookingTestUtil.addMasterCalendarBooking(_user, calendar,
            new long[] { invitedCalendar.getCalendarId() }, startTime, startTime + (Time.HOUR * 10),
            serviceContext);// w  w  w.  j ava 2s. c  o  m

    CalendarBooking childCalendarBooking = getChildCalendarBooking(calendarBooking);

    Assert.assertEquals(WorkflowConstants.STATUS_PENDING, childCalendarBooking.getStatus());
}

From source file:com.liferay.calendar.service.test.CalendarBookingLocalServiceTest.java

License:Open Source License

@Test
public void testPublishCalendarBooking() throws Exception {
    ServiceContext serviceContext = createServiceContext();

    Calendar calendar = CalendarTestUtil.addCalendar(_user, serviceContext);

    long startTime = System.currentTimeMillis();

    serviceContext.setWorkflowAction(WorkflowConstants.ACTION_PUBLISH);

    CalendarBooking calendarBooking = CalendarBookingTestUtil.addRegularCalendarBooking(_user, calendar,
            startTime, startTime + (Time.HOUR * 10), serviceContext);

    calendarBooking = CalendarBookingLocalServiceUtil
            .fetchCalendarBooking(calendarBooking.getCalendarBookingId());

    Assert.assertEquals(WorkflowConstants.STATUS_APPROVED, calendarBooking.getStatus());
}

From source file:com.liferay.calendar.service.test.CalendarBookingLocalServiceTest.java

License:Open Source License

@Test
public void testPublishDraftCalendarBooking() throws Exception {
    ServiceContext serviceContext = createServiceContext();

    Calendar calendar = CalendarTestUtil.addCalendar(_user, serviceContext);

    long startTime = System.currentTimeMillis();

    serviceContext.setWorkflowAction(WorkflowConstants.ACTION_SAVE_DRAFT);

    CalendarBooking calendarBooking = CalendarBookingTestUtil.addRegularCalendarBooking(_user, calendar,
            startTime, startTime + (Time.HOUR * 10), serviceContext);

    serviceContext.setWorkflowAction(WorkflowConstants.ACTION_PUBLISH);

    calendarBooking = CalendarBookingLocalServiceUtil.updateCalendarBooking(_user.getUserId(),
            calendarBooking.getCalendarBookingId(), calendar.getCalendarId(), new long[0],
            RandomTestUtil.randomLocaleStringMap(), RandomTestUtil.randomLocaleStringMap(),
            RandomTestUtil.randomString(), startTime, startTime + (Time.HOUR * 10), false, null, 0, null, 0,
            null, serviceContext);/*from  w w w.  ja v a 2 s. c  o  m*/

    calendarBooking = CalendarBookingLocalServiceUtil
            .fetchCalendarBooking(calendarBooking.getCalendarBookingId());

    Assert.assertEquals(WorkflowConstants.STATUS_APPROVED, calendarBooking.getStatus());
}

From source file:com.liferay.calendar.service.test.CalendarBookingLocalServiceTest.java

License:Open Source License

@Test
public void testPublishDraftCalendarBookingResultsInPendingChild() throws Exception {

    ServiceContext serviceContext = createServiceContext();

    Calendar calendar = CalendarTestUtil.addCalendar(_user, serviceContext);

    Calendar invitedCalendar = CalendarTestUtil.addCalendar(calendar.getCalendarResource(), serviceContext);

    long startTime = System.currentTimeMillis();

    serviceContext.setWorkflowAction(WorkflowConstants.ACTION_SAVE_DRAFT);

    CalendarBooking calendarBooking = CalendarBookingTestUtil.addMasterCalendarBooking(_user, calendar,
            new long[] { invitedCalendar.getCalendarId() }, startTime, startTime + (Time.HOUR * 10),
            serviceContext);//  w ww .  j ava 2  s .com

    CalendarBooking childCalendarBooking = getChildCalendarBooking(calendarBooking);

    Assert.assertEquals(CalendarBookingWorkflowConstants.STATUS_MASTER_PENDING,
            childCalendarBooking.getStatus());

    serviceContext.setWorkflowAction(WorkflowConstants.ACTION_PUBLISH);

    calendarBooking = CalendarBookingLocalServiceUtil.updateCalendarBooking(_user.getUserId(),
            calendarBooking.getCalendarBookingId(), calendar.getCalendarId(),
            new long[] { invitedCalendar.getCalendarId() }, RandomTestUtil.randomLocaleStringMap(),
            RandomTestUtil.randomLocaleStringMap(), RandomTestUtil.randomString(), startTime,
            startTime + (Time.HOUR * 10), false, null, 0, null, 0, null, serviceContext);

    childCalendarBooking = getChildCalendarBooking(calendarBooking);

    Assert.assertEquals(CalendarBookingWorkflowConstants.STATUS_PENDING, childCalendarBooking.getStatus());
}