Example usage for com.liferay.portal.kernel.util CalendarFactoryUtil getCalendar

List of usage examples for com.liferay.portal.kernel.util CalendarFactoryUtil getCalendar

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util CalendarFactoryUtil getCalendar.

Prototype

public static Calendar getCalendar(TimeZone timeZone) 

Source Link

Usage

From source file:com.liferay.calendar.recurrence.RecurrenceSerializer.java

License:Open Source License

private static Calendar _toJCalendar(DateValue dateValue) {
    Calendar jCalendar = CalendarFactoryUtil.getCalendar(TimeZone.getTimeZone(StringPool.UTC));

    jCalendar.set(Calendar.DATE, dateValue.day());
    jCalendar.set(Calendar.MONTH, dateValue.month() - 1);
    jCalendar.set(Calendar.YEAR, dateValue.year());

    if (dateValue instanceof DateTimeValue) {
        DateTimeValue dateTimeValue = (DateTimeValue) dateValue;

        jCalendar.set(Calendar.HOUR_OF_DAY, dateTimeValue.hour());
        jCalendar.set(Calendar.MINUTE, dateTimeValue.minute());
        jCalendar.set(Calendar.SECOND, dateTimeValue.second());
    }/* w  w  w  .ja  v  a2s  .  c  om*/

    return jCalendar;
}

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

License:Open Source License

@Test(expected = CalendarBookingRecurrenceException.class)
public void testStartDateBeforeUntilDateThrowsRecurrenceException() throws Exception {

    ServiceContext serviceContext = createServiceContext();

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

    long startTime = System.currentTimeMillis();

    java.util.Calendar untilJCalendar = CalendarFactoryUtil.getCalendar(startTime);

    untilJCalendar.add(java.util.Calendar.DAY_OF_MONTH, -2);

    Recurrence recurrence = RecurrenceTestUtil.getDailyRecurrence(untilJCalendar);

    CalendarBookingTestUtil.addRecurringCalendarBooking(_user, calendar, startTime,
            startTime + (Time.HOUR * 10), recurrence, serviceContext);
}

From source file:com.liferay.calendar.util.JCalendarUtil.java

License:Open Source License

public static Calendar getJCalendar(int year, int month, int day, int hour, int minutes, int seconds,
        int milliseconds, TimeZone timeZone) {

    Calendar jCalendar = CalendarFactoryUtil.getCalendar(timeZone);

    jCalendar.set(Calendar.YEAR, year);
    jCalendar.set(Calendar.MONTH, month);
    jCalendar.set(Calendar.DATE, day);
    jCalendar.set(Calendar.HOUR_OF_DAY, hour);
    jCalendar.set(Calendar.MINUTE, minutes);
    jCalendar.set(Calendar.SECOND, seconds);
    jCalendar.set(Calendar.MILLISECOND, milliseconds);

    return jCalendar;
}

From source file:com.liferay.calendar.util.JCalendarUtil.java

License:Open Source License

public static Calendar getJCalendar(long time, TimeZone timeZone) {
    Calendar jCalendar = CalendarFactoryUtil.getCalendar(timeZone);

    jCalendar.setTimeInMillis(time);//from w w w.java2s .c  o m

    return jCalendar;
}

From source file:com.liferay.calendar.web.internal.portlet.CalendarPortlet.java

License:Open Source License

protected void serveCurrentTime(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
        throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) resourceRequest.getAttribute(WebKeys.THEME_DISPLAY);

    PortletPreferences portletPreferences = resourceRequest.getPreferences();

    User user = themeDisplay.getUser();/*from www .j  av a2  s .c  o  m*/

    String timeZoneId = portletPreferences.getValue("timeZoneId", user.getTimeZoneId());

    boolean usePortalTimeZone = GetterUtil
            .getBoolean(portletPreferences.getValue("usePortalTimeZone", Boolean.TRUE.toString()));

    if (usePortalTimeZone) {
        timeZoneId = user.getTimeZoneId();
    }

    TimeZone timeZone = TimeZone.getTimeZone(timeZoneId);

    java.util.Calendar nowCalendar = CalendarFactoryUtil.getCalendar(timeZone);

    JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

    jsonObject.put("day", nowCalendar.get(java.util.Calendar.DAY_OF_MONTH));
    jsonObject.put("hour", nowCalendar.get(java.util.Calendar.HOUR_OF_DAY));
    jsonObject.put("minute", nowCalendar.get(java.util.Calendar.MINUTE));
    jsonObject.put("month", nowCalendar.get(java.util.Calendar.MONTH));
    jsonObject.put("year", nowCalendar.get(java.util.Calendar.YEAR));

    writeJSON(resourceRequest, resourceResponse, jsonObject);
}

From source file:com.liferay.docs.eventlisting.service.impl.EventLocalServiceImpl.java

License:Open Source License

public Event addEvent(long userId, long groupId, String name, String description, int month, int day, int year,
        int hour, int minute, long locationId, ServiceContext serviceContext)
        throws PortalException, SystemException {

    User user = userPersistence.findByPrimaryKey(userId);

    Date now = new Date();

    long eventId = counterLocalService.increment(Event.class.getName());

    Event event = eventPersistence.create(eventId);

    event.setName(name);// ww  w. j a  v a  2 s  . c om
    event.setDescription(description);

    Calendar dateCal = CalendarFactoryUtil.getCalendar(user.getTimeZone());
    dateCal.set(year, month, day, hour, minute);
    Date date = dateCal.getTime();
    event.setDate(date);

    event.setLocationId(locationId);

    event.setGroupId(groupId);
    event.setCompanyId(user.getCompanyId());
    event.setUserId(user.getUserId());
    event.setCreateDate(serviceContext.getCreateDate(now));
    event.setModifiedDate(serviceContext.getModifiedDate(now));

    super.addEvent(event);

    // Resources

    if (serviceContext.isAddGroupPermissions() || serviceContext.isAddGuestPermissions()) {

        addEventResources(event, serviceContext.isAddGroupPermissions(),
                serviceContext.isAddGuestPermissions());
    } else {
        addEventResources(event, serviceContext.getGroupPermissions(), serviceContext.getGuestPermissions());
    }

    return event;
}

From source file:com.liferay.docs.eventlisting.service.impl.EventLocalServiceImpl.java

License:Open Source License

public Event updateEvent(long userId, long eventId, String name, String description, int month, int day,
        int year, int hour, int minute, long locationId, ServiceContext serviceContext)
        throws PortalException, SystemException {

    User user = userPersistence.findByPrimaryKey(userId);

    Date now = new Date();

    Event event = EventLocalServiceUtil.fetchEvent(eventId);

    event.setModifiedDate(serviceContext.getModifiedDate(now));
    event.setName(name);/*from  w w w.j  a  v a2s. c om*/
    event.setDescription(description);

    Calendar dateCal = CalendarFactoryUtil.getCalendar(user.getTimeZone());
    dateCal.set(year, month, day, hour, minute);
    Date date = dateCal.getTime();
    event.setDate(date);

    event.setLocationId(locationId);

    super.updateEvent(event);

    return event;
}

From source file:com.liferay.journal.exportimport.data.handler.JournalArticleStagedModelDataHandler.java

License:Open Source License

@Override
protected void doImportStagedModel(PortletDataContext portletDataContext, JournalArticle article)
        throws Exception {

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

    long authorId = _journalCreationStrategy.getAuthorUserId(portletDataContext, article);

    if (authorId != JournalCreationStrategy.USE_DEFAULT_USER_ID_STRATEGY) {
        userId = authorId;/*from ww w  .  j ava  2  s .c  om*/
    }

    User user = _userLocalService.getUser(userId);

    Map<Long, Long> folderIds = (Map<Long, Long>) portletDataContext.getNewPrimaryKeysMap(JournalFolder.class);

    long folderId = MapUtil.getLong(folderIds, article.getFolderId(), article.getFolderId());

    String articleId = article.getArticleId();

    boolean autoArticleId = false;

    if (Validator.isNumber(articleId)
            || (_journalArticleLocalService.fetchArticle(portletDataContext.getScopeGroupId(), articleId,
                    JournalArticleConstants.VERSION_DEFAULT) != null)) {

        autoArticleId = true;
    }

    Map<String, String> articleIds = (Map<String, String>) portletDataContext
            .getNewPrimaryKeysMap(JournalArticle.class + ".articleId");

    String newArticleId = articleIds.get(articleId);

    if (Validator.isNotNull(newArticleId)) {

        // A sibling of a different version was already assigned a new
        // article id

        articleId = newArticleId;
        autoArticleId = false;
    }

    String content = article.getContent();

    content = _journalArticleExportImportContentProcessor.replaceImportContentReferences(portletDataContext,
            article, content);

    article.setContent(content);

    String newContent = _journalCreationStrategy.getTransformedContent(portletDataContext, article);

    if (newContent != JournalCreationStrategy.ARTICLE_CONTENT_UNCHANGED) {
        article.setContent(newContent);
    }

    Date displayDate = article.getDisplayDate();

    int displayDateMonth = 0;
    int displayDateDay = 0;
    int displayDateYear = 0;
    int displayDateHour = 0;
    int displayDateMinute = 0;

    if (displayDate != null) {
        Calendar displayCal = CalendarFactoryUtil.getCalendar(user.getTimeZone());

        displayCal.setTime(displayDate);

        displayDateMonth = displayCal.get(Calendar.MONTH);
        displayDateDay = displayCal.get(Calendar.DATE);
        displayDateYear = displayCal.get(Calendar.YEAR);
        displayDateHour = displayCal.get(Calendar.HOUR);
        displayDateMinute = displayCal.get(Calendar.MINUTE);

        if (displayCal.get(Calendar.AM_PM) == Calendar.PM) {
            displayDateHour += 12;
        }
    }

    Date expirationDate = article.getExpirationDate();

    int expirationDateMonth = 0;
    int expirationDateDay = 0;
    int expirationDateYear = 0;
    int expirationDateHour = 0;
    int expirationDateMinute = 0;
    boolean neverExpire = true;

    if (expirationDate != null) {
        Calendar expirationCal = CalendarFactoryUtil.getCalendar(user.getTimeZone());

        expirationCal.setTime(expirationDate);

        expirationDateMonth = expirationCal.get(Calendar.MONTH);
        expirationDateDay = expirationCal.get(Calendar.DATE);
        expirationDateYear = expirationCal.get(Calendar.YEAR);
        expirationDateHour = expirationCal.get(Calendar.HOUR);
        expirationDateMinute = expirationCal.get(Calendar.MINUTE);

        neverExpire = false;

        if (expirationCal.get(Calendar.AM_PM) == Calendar.PM) {
            expirationDateHour += 12;
        }
    }

    Date reviewDate = article.getReviewDate();

    int reviewDateMonth = 0;
    int reviewDateDay = 0;
    int reviewDateYear = 0;
    int reviewDateHour = 0;
    int reviewDateMinute = 0;
    boolean neverReview = true;

    if (reviewDate != null) {
        Calendar reviewCal = CalendarFactoryUtil.getCalendar(user.getTimeZone());

        reviewCal.setTime(reviewDate);

        reviewDateMonth = reviewCal.get(Calendar.MONTH);
        reviewDateDay = reviewCal.get(Calendar.DATE);
        reviewDateYear = reviewCal.get(Calendar.YEAR);
        reviewDateHour = reviewCal.get(Calendar.HOUR);
        reviewDateMinute = reviewCal.get(Calendar.MINUTE);

        neverReview = false;

        if (reviewCal.get(Calendar.AM_PM) == Calendar.PM) {
            reviewDateHour += 12;
        }
    }

    Map<String, String> ddmStructureKeys = (Map<String, String>) portletDataContext
            .getNewPrimaryKeysMap(DDMStructure.class + ".ddmStructureKey");

    String parentDDMStructureKey = MapUtil.getString(ddmStructureKeys, article.getDDMStructureKey(),
            article.getDDMStructureKey());

    Map<String, Long> ddmStructureIds = (Map<String, Long>) portletDataContext
            .getNewPrimaryKeysMap(DDMStructure.class);

    long ddmStructureId = 0;

    if (article.getClassNameId() != 0) {
        ddmStructureId = ddmStructureIds.get(article.getClassPK());
    }

    Map<String, String> ddmTemplateKeys = (Map<String, String>) portletDataContext
            .getNewPrimaryKeysMap(DDMTemplate.class + ".ddmTemplateKey");

    String parentDDMTemplateKey = MapUtil.getString(ddmTemplateKeys, article.getDDMTemplateKey(),
            article.getDDMTemplateKey());

    File smallFile = null;

    try {
        Element articleElement = portletDataContext.getImportDataStagedModelElement(article);

        if (article.isSmallImage()) {
            String smallImagePath = articleElement.attributeValue("small-image-path");

            if (Validator.isNotNull(article.getSmallImageURL())) {
                String smallImageURL = _journalArticleExportImportContentProcessor
                        .replaceImportContentReferences(portletDataContext, article,
                                article.getSmallImageURL());

                article.setSmallImageURL(smallImageURL);
            } else if (Validator.isNotNull(smallImagePath)) {
                byte[] bytes = portletDataContext.getZipEntryAsByteArray(smallImagePath);

                if (bytes != null) {
                    smallFile = FileUtil.createTempFile(article.getSmallImageType());

                    FileUtil.write(smallFile, bytes);
                }
            }
        }

        JournalArticle latestArticle = _journalArticleLocalService
                .fetchLatestArticle(article.getResourcePrimKey());

        if ((latestArticle != null) && (latestArticle.getId() == article.getId())) {

            List<Element> attachmentElements = portletDataContext.getReferenceDataElements(article,
                    DLFileEntry.class, PortletDataContext.REFERENCE_TYPE_WEAK);

            for (Element attachmentElement : attachmentElements) {
                String path = attachmentElement.attributeValue("path");

                FileEntry fileEntry = (FileEntry) portletDataContext.getZipEntryAsObject(path);

                InputStream inputStream = null;

                try {
                    String binPath = attachmentElement.attributeValue("bin-path");

                    if (Validator.isNull(binPath) && portletDataContext.isPerformDirectBinaryImport()) {

                        try {
                            inputStream = FileEntryUtil.getContentStream(fileEntry);
                        } catch (NoSuchFileException nsfe) {
                        }
                    } else {
                        inputStream = portletDataContext.getZipEntryAsInputStream(binPath);
                    }

                    if (inputStream == null) {
                        if (_log.isWarnEnabled()) {
                            _log.warn("Unable to import attachment for file " + "entry "
                                    + fileEntry.getFileEntryId());
                        }

                        continue;
                    }

                    TempFileEntryUtil.addTempFileEntry(portletDataContext.getScopeGroupId(), userId,
                            JournalArticleStagedModelDataHandler.class.getName(), fileEntry.getFileName(),
                            inputStream, fileEntry.getMimeType());
                } finally {
                    StreamUtil.cleanUp(inputStream);
                }
            }
        }

        String articleURL = null;

        boolean addGroupPermissions = _journalCreationStrategy.addGroupPermissions(portletDataContext, article);
        boolean addGuestPermissions = _journalCreationStrategy.addGuestPermissions(portletDataContext, article);

        ServiceContext serviceContext = portletDataContext.createServiceContext(article);

        serviceContext.setAddGroupPermissions(addGroupPermissions);
        serviceContext.setAddGuestPermissions(addGuestPermissions);

        if ((expirationDate != null) && expirationDate.before(new Date())) {
            article.setStatus(WorkflowConstants.STATUS_EXPIRED);
        }

        if ((article.getStatus() != WorkflowConstants.STATUS_APPROVED)
                && (article.getStatus() != WorkflowConstants.STATUS_SCHEDULED)) {

            serviceContext.setWorkflowAction(WorkflowConstants.ACTION_SAVE_DRAFT);
        }

        JournalArticle importedArticle = null;

        String articleResourceUuid = articleElement.attributeValue("article-resource-uuid");

        // Used when importing LARs with journal schemas under 1.1.0

        _setLegacyValues(article);

        if (portletDataContext.isDataStrategyMirror()) {
            serviceContext.setUuid(article.getUuid());
            serviceContext.setAttribute("articleResourceUuid", articleResourceUuid);
            serviceContext.setAttribute("urlTitle", article.getUrlTitle());

            boolean preloaded = GetterUtil.getBoolean(articleElement.attributeValue("preloaded"));

            JournalArticle existingArticle = fetchExistingArticle(articleResourceUuid,
                    portletDataContext.getScopeGroupId(), articleId, newArticleId, preloaded);

            JournalArticle existingArticleVersion = null;

            if (existingArticle != null) {
                existingArticleVersion = fetchExistingArticleVersion(article.getUuid(),
                        portletDataContext.getScopeGroupId(), existingArticle.getArticleId(),
                        article.getVersion());
            }

            if ((existingArticle != null) && (existingArticleVersion == null)) {

                autoArticleId = false;
                articleId = existingArticle.getArticleId();
            }

            if (existingArticleVersion == null) {
                importedArticle = _journalArticleLocalService.addArticle(userId,
                        portletDataContext.getScopeGroupId(), folderId, article.getClassNameId(),
                        ddmStructureId, articleId, autoArticleId, article.getVersion(), article.getTitleMap(),
                        article.getDescriptionMap(), article.getContent(), parentDDMStructureKey,
                        parentDDMTemplateKey, article.getLayoutUuid(), displayDateMonth, displayDateDay,
                        displayDateYear, displayDateHour, displayDateMinute, expirationDateMonth,
                        expirationDateDay, expirationDateYear, expirationDateHour, expirationDateMinute,
                        neverExpire, reviewDateMonth, reviewDateDay, reviewDateYear, reviewDateHour,
                        reviewDateMinute, neverReview, article.isIndexable(), article.isSmallImage(),
                        article.getSmallImageURL(), smallFile, null, articleURL, serviceContext);
            } else {
                importedArticle = _journalArticleLocalService.updateArticle(userId,
                        existingArticle.getGroupId(), folderId, existingArticle.getArticleId(),
                        article.getVersion(), article.getTitleMap(), article.getDescriptionMap(),
                        article.getContent(), parentDDMStructureKey, parentDDMTemplateKey,
                        article.getLayoutUuid(), displayDateMonth, displayDateDay, displayDateYear,
                        displayDateHour, displayDateMinute, expirationDateMonth, expirationDateDay,
                        expirationDateYear, expirationDateHour, expirationDateMinute, neverExpire,
                        reviewDateMonth, reviewDateDay, reviewDateYear, reviewDateHour, reviewDateMinute,
                        neverReview, article.isIndexable(), article.isSmallImage(), article.getSmallImageURL(),
                        smallFile, null, articleURL, serviceContext);

                String articleUuid = article.getUuid();
                String importedArticleUuid = importedArticle.getUuid();

                if (!articleUuid.equals(importedArticleUuid)) {
                    importedArticle.setUuid(articleUuid);

                    _journalArticleLocalService.updateJournalArticle(importedArticle);
                }
            }
        } else {
            importedArticle = _journalArticleLocalService.addArticle(userId,
                    portletDataContext.getScopeGroupId(), folderId, article.getClassNameId(), ddmStructureId,
                    articleId, autoArticleId, article.getVersion(), article.getTitleMap(),
                    article.getDescriptionMap(), article.getContent(), parentDDMStructureKey,
                    parentDDMTemplateKey, article.getLayoutUuid(), displayDateMonth, displayDateDay,
                    displayDateYear, displayDateHour, displayDateMinute, expirationDateMonth, expirationDateDay,
                    expirationDateYear, expirationDateHour, expirationDateMinute, neverExpire, reviewDateMonth,
                    reviewDateDay, reviewDateYear, reviewDateHour, reviewDateMinute, neverReview,
                    article.isIndexable(), article.isSmallImage(), article.getSmallImageURL(), smallFile, null,
                    articleURL, serviceContext);
        }

        portletDataContext.importClassedModel(article, importedArticle);

        if (Validator.isNull(newArticleId)) {
            articleIds.put(article.getArticleId(), importedArticle.getArticleId());
        }

        Map<Long, Long> articlePrimaryKeys = (Map<Long, Long>) portletDataContext
                .getNewPrimaryKeysMap(JournalArticle.class + ".primaryKey");

        articlePrimaryKeys.put(article.getPrimaryKey(), importedArticle.getPrimaryKey());
    } finally {
        if (smallFile != null) {
            smallFile.delete();
        }
    }
}

From source file:com.liferay.journal.service.impl.JournalArticleLocalServiceImpl.java

License:Open Source License

/**
 * Adds a web content article.//from  w  w  w .ja v a  2  s.c  om
 *
 * @param  userId the primary key of the web content article's creator/owner
 * @param  groupId the primary key of the web content article's group
 * @param  folderId the primary key of the web content article folder
 * @param  titleMap the web content article's locales and localized titles
 * @param  descriptionMap the web content article's locales and localized
 *         descriptions
 * @param  content the HTML content wrapped in XML. For more information,
 *         see the content example in the {@link #addArticle(long, long,
 *         long, long, long, String, boolean, double, Map, Map, String,
 *         String, String, String, int, int, int, int, int, int, int, int,
 *         int, int, boolean, int, int, int, int, int, boolean, boolean,
 *         boolean, String, File, Map, String, ServiceContext)} description.
 * @param  ddmStructureKey the primary key of the web content article's DDM
 *         structure, if the article is related to a DDM structure, or
 *         <code>null</code> otherwise
 * @param  ddmTemplateKey the primary key of the web content article's DDM
 *         template
 * @param  serviceContext the service context to be applied. Can set the
 *         UUID, creation date, modification date, expando bridge
 *         attributes, guest permissions, group permissions, asset category
 *         IDs, asset tag names, asset link entry IDs, asset priority, URL
 *         title, and workflow actions for the web content article. Can also
 *         set whether to add the default guest and group permissions.
 * @return the web content article
 */
@Override
public JournalArticle addArticle(long userId, long groupId, long folderId, Map<Locale, String> titleMap,
        Map<Locale, String> descriptionMap, String content, String ddmStructureKey, String ddmTemplateKey,
        ServiceContext serviceContext) throws PortalException {

    User user = userLocalService.getUser(userId);

    Calendar calendar = CalendarFactoryUtil.getCalendar(user.getTimeZone());

    int displayDateMonth = calendar.get(Calendar.MONTH);
    int displayDateDay = calendar.get(Calendar.DAY_OF_MONTH);
    int displayDateYear = calendar.get(Calendar.YEAR);
    int displayDateHour = calendar.get(Calendar.HOUR_OF_DAY);
    int displayDateMinute = calendar.get(Calendar.MINUTE);

    return journalArticleLocalService.addArticle(userId, groupId, folderId,
            JournalArticleConstants.CLASSNAME_ID_DEFAULT, 0, StringPool.BLANK, true, 1, titleMap,
            descriptionMap, content, ddmStructureKey, ddmTemplateKey, null, displayDateMonth, displayDateDay,
            displayDateYear, displayDateHour, displayDateMinute, 0, 0, 0, 0, 0, true, 0, 0, 0, 0, 0, true, true,
            false, null, null, null, null, serviceContext);
}

From source file:com.liferay.journal.service.impl.JournalArticleLocalServiceImpl.java

License:Open Source License

/**
 * Updates the web content article matching the version, replacing its
 * folder, title, description, content, and layout UUID.
 *
 * @param  userId the primary key of the user updating the web content
 *         article/*  www .  j  a  v a  2 s.c  o  m*/
 * @param  groupId the primary key of the web content article's group
 * @param  folderId the primary key of the web content article folder
 * @param  articleId the primary key of the web content article
 * @param  version the web content article's version
 * @param  titleMap the web content article's locales and localized titles
 * @param  descriptionMap the web content article's locales and localized
 *         descriptions
 * @param  content the HTML content wrapped in XML. For more information,
 *         see the content example in the {@link #addArticle(long, long,
 *         long, long, long, String, boolean, double, Map, Map, String,
 *         String, String, String, int, int, int, int, int, int, int, int,
 *         int, int, boolean, int, int, int, int, int, boolean, boolean,
 *         boolean, String, File, Map, String, ServiceContext)} description.
 * @param  layoutUuid the unique string identifying the web content
 *         article's display page
 * @param  serviceContext the service context to be applied. Can set the
 *         modification date, expando bridge attributes, asset category IDs,
 *         asset tag names, asset link entry IDs, asset priority, workflow
 *         actions, URL title, and can set whether to add the default
 *         command update for the web content article. With respect to
 *         social activities, by setting the service context's command to
 *         {@link Constants#UPDATE}, the invocation is considered a web
 *         content update activity; otherwise it is considered a web content
 *         add activity.
 * @return the updated web content article
 */
@Override
public JournalArticle updateArticle(long userId, long groupId, long folderId, String articleId, double version,
        Map<Locale, String> titleMap, Map<Locale, String> descriptionMap, String content, String layoutUuid,
        ServiceContext serviceContext) throws PortalException {

    User user = userLocalService.getUser(userId);

    JournalArticle article = journalArticlePersistence.findByG_A_V(groupId, articleId, version);

    Date displayDate = article.getDisplayDate();

    int displayDateMonth = 0;
    int displayDateDay = 0;
    int displayDateYear = 0;
    int displayDateHour = 0;
    int displayDateMinute = 0;

    if (displayDate != null) {
        Calendar displayCal = CalendarFactoryUtil.getCalendar(user.getTimeZone());

        displayCal.setTime(displayDate);

        displayDateMonth = displayCal.get(Calendar.MONTH);
        displayDateDay = displayCal.get(Calendar.DATE);
        displayDateYear = displayCal.get(Calendar.YEAR);
        displayDateHour = displayCal.get(Calendar.HOUR);
        displayDateMinute = displayCal.get(Calendar.MINUTE);

        if (displayCal.get(Calendar.AM_PM) == Calendar.PM) {
            displayDateHour += 12;
        }
    }

    Date expirationDate = article.getExpirationDate();

    int expirationDateMonth = 0;
    int expirationDateDay = 0;
    int expirationDateYear = 0;
    int expirationDateHour = 0;
    int expirationDateMinute = 0;
    boolean neverExpire = true;

    if (expirationDate != null) {
        Calendar expirationCal = CalendarFactoryUtil.getCalendar(user.getTimeZone());

        expirationCal.setTime(expirationDate);

        expirationDateMonth = expirationCal.get(Calendar.MONTH);
        expirationDateDay = expirationCal.get(Calendar.DATE);
        expirationDateYear = expirationCal.get(Calendar.YEAR);
        expirationDateHour = expirationCal.get(Calendar.HOUR);
        expirationDateMinute = expirationCal.get(Calendar.MINUTE);

        neverExpire = false;

        if (expirationCal.get(Calendar.AM_PM) == Calendar.PM) {
            expirationDateHour += 12;
        }
    }

    Date reviewDate = article.getReviewDate();

    int reviewDateMonth = 0;
    int reviewDateDay = 0;
    int reviewDateYear = 0;
    int reviewDateHour = 0;
    int reviewDateMinute = 0;
    boolean neverReview = true;

    if (reviewDate != null) {
        Calendar reviewCal = CalendarFactoryUtil.getCalendar(user.getTimeZone());

        reviewCal.setTime(reviewDate);

        reviewDateMonth = reviewCal.get(Calendar.MONTH);
        reviewDateDay = reviewCal.get(Calendar.DATE);
        reviewDateYear = reviewCal.get(Calendar.YEAR);
        reviewDateHour = reviewCal.get(Calendar.HOUR);
        reviewDateMinute = reviewCal.get(Calendar.MINUTE);

        neverReview = false;

        if (reviewCal.get(Calendar.AM_PM) == Calendar.PM) {
            reviewDateHour += 12;
        }
    }

    return journalArticleLocalService.updateArticle(userId, groupId, folderId, articleId, version, titleMap,
            descriptionMap, content, article.getDDMStructureKey(), article.getDDMTemplateKey(), layoutUuid,
            displayDateMonth, displayDateDay, displayDateYear, displayDateHour, displayDateMinute,
            expirationDateMonth, expirationDateDay, expirationDateYear, expirationDateHour,
            expirationDateMinute, neverExpire, reviewDateMonth, reviewDateDay, reviewDateYear, reviewDateHour,
            reviewDateMinute, neverReview, article.getIndexable(), article.isSmallImage(),
            article.getSmallImageURL(), null, null, null, serviceContext);
}