Example usage for com.liferay.portal.kernel.workflow WorkflowConstants ACTION_PUBLISH

List of usage examples for com.liferay.portal.kernel.workflow WorkflowConstants ACTION_PUBLISH

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.workflow WorkflowConstants ACTION_PUBLISH.

Prototype

int ACTION_PUBLISH

To view the source code for com.liferay.portal.kernel.workflow WorkflowConstants ACTION_PUBLISH.

Click Source Link

Usage

From source file:com.idetronic.subur.service.impl.SuburItemLocalServiceImpl.java

License:Open Source License

@Override
public SuburItem updateSuburItem(SuburItem suburItem, long userId, int newStatus, long[] itemTypeIds,
        long[] authorIds, ServiceContext serviceContext) throws PortalException, SystemException {

    long groupId = serviceContext.getScopeGroupId();
    suburItem.setStatusDate(new Date());
    if (Validator.isNull(suburItem.getPublishedDate())
            && suburItem.getStatus() == SuburConstant.STATUS_PUBLISHED_ITEM)
        suburItem.setPublishedDate(new Date());

    //only show item with published status
    boolean visible = false;
    String itemDescription = null;
    String summary = null;//from w  w w . j av a2 s .  c  o  m
    String url = null;
    String layoutUuid = null;
    Date publishedDate = suburItem.getPublishedDate();
    suburItem.getMetadataValue();

    itemDescription = suburItem.getTitle();
    AssetEntry assetEntry = assetEntryLocalService.updateEntry(userId, groupId, suburItem.getCreateDate(),
            suburItem.getModifiedDate(), SuburItem.class.getName(), suburItem.getItemId(), suburItem.getUuid(),
            0, serviceContext.getAssetCategoryIds(), serviceContext.getAssetTagNames(), visible, null, null,
            null, ContentTypes.TEXT_HTML, suburItem.getTitle(), itemDescription, summary, url, layoutUuid, 0, 0,
            null, false);

    if (suburItem.isDraft() || suburItem.isPending()) {

    } else {
        suburItem.setStatus(WorkflowConstants.STATUS_DRAFT);
    }

    //if status is published, ensure to update asset entry published date
    if (Validator.isNull(assetEntry.getPublishDate())
            && suburItem.getStatus() == WorkflowConstants.STATUS_APPROVED)
        assetEntryLocalService.updateEntry(SuburItem.class.getName(), suburItem.getItemId(),
                suburItem.getPublishedDate(), true);

    assetLinkLocalService.updateLinks(userId, assetEntry.getEntryId(), serviceContext.getAssetLinkEntryIds(),
            AssetLinkConstants.TYPE_RELATED);

    ItemAuthorLocalServiceUtil.setItemAuthor(suburItem.getItemId(), authorIds, suburItem.getStatus());
    //AuthorLocalServiceUtil.updateAuthorPosting(suburItem);

    resourceLocalService.addResources(serviceContext.getCompanyId(), groupId, userId, SuburItem.class.getName(),
            suburItem.getItemId(), false, true, true);

    ItemItemTypeLocalServiceUtil.updateItemItemType(suburItem.getItemId(), itemTypeIds);

    //workflow

    boolean workFlowEnable = SuburUtil.isWorkflowEnabled(serviceContext);

    serviceContext.setAttribute("trackbacks", null);

    if (workFlowEnable) {
        WorkflowHandlerRegistryUtil.startWorkflowInstance(suburItem.getCompanyId(), suburItem.getGroupId(),
                userId, SuburItem.class.getName(), suburItem.getItemId(), suburItem, serviceContext);

    }

    Indexer indexer = IndexerRegistryUtil.nullSafeGetIndexer(SuburItem.class);

    if (serviceContext.getWorkflowAction() == WorkflowConstants.ACTION_PUBLISH) {
        suburItem.setStatus(WorkflowConstants.STATUS_PENDING);
        JSONObject extraDataJSONObject = JSONFactoryUtil.createJSONObject();

        extraDataJSONObject.put("title", suburItem.getTitle());
        if (suburItem.getCompleted()) {
            SocialActivityLocalServiceUtil.addActivity(userId, suburItem.getGroupId(),
                    SuburItem.class.getName(), suburItem.getItemId(),
                    SuburActivityKeys.UPDATE_SUBUR_PUBLICATION, extraDataJSONObject.toString(), 0);

        } else {
            SocialActivityLocalServiceUtil.addActivity(userId, suburItem.getGroupId(),
                    SuburItem.class.getName(), suburItem.getItemId(), SuburActivityKeys.ADD_SUBUR_PUBLICATION,
                    extraDataJSONObject.toString(), 0);

            suburItem.setCompleted(true);
        }
    }

    indexer.reindex(suburItem);
    suburItem.setExpandoBridgeAttributes(serviceContext);

    //updateStatus(suburItem.getItemId(),userId,newStatus,serviceContext);
    return suburItemPersistence.update(suburItem);

}

From source file:com.liferay.akismet.hook.service.impl.AkismetMBMessageLocalServiceImpl.java

License:Open Source License

protected boolean isDiscussionsEnabled(long userId, ServiceContext serviceContext) throws PortalException {

    if (serviceContext.getWorkflowAction() != WorkflowConstants.ACTION_PUBLISH) {

        return false;
    }//  w  w w .j  a v a  2 s  .c om

    if (!AkismetUtil.hasRequiredInfo(serviceContext)) {
        return false;
    }

    User user = UserLocalServiceUtil.getUser(userId);

    if (AkismetUtil.isDiscussionsEnabled(user.getCompanyId())) {
        return true;
    } else {
        return false;
    }
}

From source file:com.liferay.akismet.hook.service.impl.AkismetMBMessageLocalServiceImpl.java

License:Open Source License

protected boolean isMessageBoardsEnabled(long userId, long groupId, ServiceContext serviceContext)
        throws PortalException {

    if (serviceContext.getWorkflowAction() != WorkflowConstants.ACTION_PUBLISH) {

        return false;
    }/*from ww w  .j a v  a  2s  .c o m*/

    if (!AkismetUtil.hasRequiredInfo(serviceContext)) {
        return false;
    }

    User user = UserLocalServiceUtil.getUser(userId);

    if (!AkismetUtil.isMessageBoardsEnabled(user.getCompanyId())) {
        return false;
    }

    int checkThreshold = PrefsPortletPropsUtil.getInteger(user.getCompanyId(),
            PortletPropsKeys.AKISMET_CHECK_THRESHOLD);

    if (checkThreshold > 0) {
        int count = super.getGroupMessagesCount(groupId, userId, WorkflowConstants.STATUS_APPROVED);

        if (count > checkThreshold) {
            return false;
        }
    }

    return true;
}

From source file:com.liferay.calendar.internal.exportimport.data.handler.CalendarBookingStagedModelDataHandler.java

License:Open Source License

@Override
protected void doImportStagedModel(PortletDataContext portletDataContext, CalendarBooking calendarBooking)
        throws Exception {

    long userId = portletDataContext.getUserId(calendarBooking.getUserUuid());

    Map<Long, Long> calendarIds = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(Calendar.class);

    long calendarId = MapUtil.getLong(calendarIds, calendarBooking.getCalendarId(),
            calendarBooking.getCalendarId());

    long parentCalendarBookingId = CalendarBookingConstants.PARENT_CALENDAR_BOOKING_ID_DEFAULT;

    if (!calendarBooking.isMasterBooking()) {
        Map<Long, Long> calendarBookingIds = (Map<Long, Long>) portletDataContext
                .getNewPrimaryKeysMap(CalendarBooking.class);

        parentCalendarBookingId = MapUtil.getLong(calendarBookingIds,
                calendarBooking.getParentCalendarBookingId(), calendarBooking.getParentCalendarBookingId());
    }//from   w w w . j  a  v  a 2 s.  co m

    long recurringCalendarBookingId = CalendarBookingConstants.RECURRING_CALENDAR_BOOKING_ID_DEFAULT;

    if (!calendarBooking.isMasterRecurringBooking()) {
        recurringCalendarBookingId = calendarBooking.getRecurringCalendarBookingId();
    }

    ServiceContext serviceContext = portletDataContext.createServiceContext(calendarBooking);

    CalendarBooking importedCalendarBooking = null;

    if (portletDataContext.isDataStrategyMirror()) {
        CalendarBooking existingCalendarBooking = fetchStagedModelByUuidAndGroupId(calendarBooking.getUuid(),
                portletDataContext.getScopeGroupId());

        if (existingCalendarBooking == null) {
            serviceContext.setUuid(calendarBooking.getUuid());

            importedCalendarBooking = _calendarBookingLocalService.addCalendarBooking(userId, calendarId,
                    new long[0], parentCalendarBookingId, recurringCalendarBookingId,
                    calendarBooking.getTitleMap(), calendarBooking.getDescriptionMap(),
                    calendarBooking.getLocation(), calendarBooking.getStartTime(), calendarBooking.getEndTime(),
                    calendarBooking.isAllDay(), calendarBooking.getRecurrence(),
                    calendarBooking.getFirstReminder(), calendarBooking.getFirstReminderType(),
                    calendarBooking.getSecondReminder(), calendarBooking.getSecondReminderType(),
                    serviceContext);
        } else {
            importedCalendarBooking = _calendarBookingLocalService.updateCalendarBooking(userId,
                    existingCalendarBooking.getCalendarBookingId(), calendarId, calendarBooking.getTitleMap(),
                    calendarBooking.getDescriptionMap(), calendarBooking.getLocation(),
                    calendarBooking.getStartTime(), calendarBooking.getEndTime(), calendarBooking.isAllDay(),
                    calendarBooking.getRecurrence(), calendarBooking.getFirstReminder(),
                    calendarBooking.getFirstReminderType(), calendarBooking.getSecondReminder(),
                    calendarBooking.getSecondReminderType(), serviceContext);
        }
    } else {
        importedCalendarBooking = _calendarBookingLocalService.addCalendarBooking(userId, calendarId,
                new long[0], parentCalendarBookingId, recurringCalendarBookingId, calendarBooking.getTitleMap(),
                calendarBooking.getDescriptionMap(), calendarBooking.getLocation(),
                calendarBooking.getStartTime(), calendarBooking.getEndTime(), calendarBooking.isAllDay(),
                calendarBooking.getRecurrence(), calendarBooking.getFirstReminder(),
                calendarBooking.getFirstReminderType(), calendarBooking.getSecondReminder(),
                calendarBooking.getSecondReminderType(), serviceContext);
    }

    // The root discussion message is not automatically imported when
    // importing a calendar booking

    List<Element> mbMessageElements = portletDataContext.getReferenceElements(calendarBooking, MBMessage.class);

    if (ListUtil.isNotEmpty(mbMessageElements)) {
        _mbMessageLocalService.addDiscussionMessage(userId, importedCalendarBooking.getUserName(),
                importedCalendarBooking.getGroupId(), CalendarBooking.class.getName(),
                importedCalendarBooking.getCalendarBookingId(), WorkflowConstants.ACTION_PUBLISH);
    }

    portletDataContext.importClassedModel(calendarBooking, importedCalendarBooking);
}

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

License:Open Source License

@Test
public void testAddCalendarBookingWorkflowActionPublish() throws PortalException {

    ServiceContext serviceContext = createServiceContext();

    CalendarResource calendarResource = CalendarResourceUtil.getUserCalendarResource(_user.getUserId(),
            serviceContext);/*  w  w  w.ja v a 2s .  co  m*/

    Calendar calendar = calendarResource.getDefaultCalendar();

    long startTime = DateUtil.newTime();

    serviceContext.setWorkflowAction(WorkflowConstants.ACTION_PUBLISH);

    CalendarBooking calendarBooking = CalendarBookingLocalServiceUtil.addCalendarBooking(_user.getUserId(),
            calendar.getCalendarId(), new long[0], CalendarBookingConstants.PARENT_CALENDAR_BOOKING_ID_DEFAULT,
            RandomTestUtil.randomLocaleStringMap(), RandomTestUtil.randomLocaleStringMap(),
            RandomTestUtil.randomString(), startTime, startTime + (Time.HOUR * 10), false, null, 0, null, 0,
            null, serviceContext);

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

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

License:Open Source License

@Test
public void testUpdateCalendarBookingWorkflowActionPublish() throws PortalException {

    ServiceContext serviceContext = createServiceContext();

    CalendarResource calendarResource = CalendarResourceUtil.getUserCalendarResource(_user.getUserId(),
            serviceContext);//from  www .  ja va2 s  . c  o m

    Calendar calendar = calendarResource.getDefaultCalendar();

    long startTime = DateUtil.newTime();

    serviceContext.setWorkflowAction(WorkflowConstants.ACTION_SAVE_DRAFT);

    CalendarBooking calendarBooking = CalendarBookingLocalServiceUtil.addCalendarBooking(_user.getUserId(),
            calendar.getCalendarId(), new long[0], CalendarBookingConstants.PARENT_CALENDAR_BOOKING_ID_DEFAULT,
            RandomTestUtil.randomLocaleStringMap(), RandomTestUtil.randomLocaleStringMap(),
            RandomTestUtil.randomString(), startTime, startTime + (Time.HOUR * 10), false, null, 0, null, 0,
            null, 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, RandomTestUtil.randomInt(), serviceContext);

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

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   ww w. j  a  va 2  s . c o  m

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

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 a  v  a 2s  . co 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  ww  w .j a  v a  2s.  c o m*/

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

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