Example usage for java.util Calendar AM_PM

List of usage examples for java.util Calendar AM_PM

Introduction

In this page you can find the example usage for java.util Calendar AM_PM.

Prototype

int AM_PM

To view the source code for java.util Calendar AM_PM.

Click Source Link

Document

Field number for get and set indicating whether the HOUR is before or after noon.

Usage

From source file:org.betaconceptframework.astroboa.portal.utility.CalendarUtils.java

public void clearTimeFromCalendar(Calendar calendar) {
    if (calendar != null) {
        calendar.set(Calendar.HOUR, 0);
        calendar.clear(Calendar.AM_PM); //ALWAYS clear AM_PM before HOUR_OF_DAY
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        calendar.clear(Calendar.DST_OFFSET);
        calendar.clear(Calendar.ZONE_OFFSET);
    }//from   w ww.  j  ava  2 s .c  o  m

}

From source file:com.panet.imeta.job.entries.special.JobEntrySpecial.java

private long getNextWeeklyExecutionTime() {
    Calendar calendar = Calendar.getInstance();

    long nowMillis = calendar.getTimeInMillis();
    int amHour = hour;
    if (amHour > 12) {
        amHour = amHour - 12;//from   ww w .  ja v a2 s  .  com
        calendar.set(Calendar.AM_PM, Calendar.PM);
    } else {
        calendar.set(Calendar.AM_PM, Calendar.AM);
    }
    calendar.set(Calendar.HOUR, amHour);
    calendar.set(Calendar.MINUTE, minutes);
    calendar.set(Calendar.DAY_OF_WEEK, weekDay + 1);
    if (calendar.getTimeInMillis() <= nowMillis) {
        calendar.add(Calendar.WEEK_OF_YEAR, 1);
    }
    return calendar.getTimeInMillis() - nowMillis;
}

From source file:com.application.utils.FastDateParser.java

private static String[] getDisplayNameArray(int field, boolean isLong, Locale locale) {
    DateFormatSymbols dfs = new DateFormatSymbols(locale);
    switch (field) {
    case Calendar.AM_PM:
        return dfs.getAmPmStrings();
    case Calendar.DAY_OF_WEEK:
        return isLong ? dfs.getWeekdays() : dfs.getShortWeekdays();
    case Calendar.ERA:
        return dfs.getEras();
    case Calendar.MONTH:
        return isLong ? dfs.getMonths() : dfs.getShortMonths();
    }/*w ww  . java2 s.c  o  m*/
    return null;
}

From source file:org.kuali.ole.sys.batch.service.impl.SchedulerServiceImpl.java

protected boolean isPastScheduleCutoffTime(Calendar dateTime, boolean log) {
    try {//w  ww .  j a va 2 s. co  m
        Date scheduleCutoffTimeTemp = scheduler.getTriggersOfJob(SCHEDULE_JOB_NAME, SCHEDULED_GROUP)[0]
                .getPreviousFireTime();
        Calendar scheduleCutoffTime;
        if (scheduleCutoffTimeTemp == null) {
            scheduleCutoffTime = dateTimeService.getCurrentCalendar();
        } else {
            scheduleCutoffTime = dateTimeService.getCalendar(scheduleCutoffTimeTemp);
        }
        String cutoffParameter = parameterService.getParameterValueAsString(ScheduleStep.class,
                OLEConstants.SystemGroupParameterNames.BATCH_SCHEDULE_CUTOFF_TIME);
        String[] scheduleStepCutoffTime = StringUtils.split(cutoffParameter, ":");
        if (scheduleStepCutoffTime.length != 3 && scheduleStepCutoffTime.length != 4) {
            throw new IllegalArgumentException(
                    "Error! The " + OLEConstants.SystemGroupParameterNames.BATCH_SCHEDULE_CUTOFF_TIME
                            + " parameter had an invalid value: " + cutoffParameter);
        }
        // if there are 4 components, then we have an AM/PM delimiter
        // otherwise, assume 24-hour time
        if (scheduleStepCutoffTime.length == 4) {
            int hour = Integer.parseInt(scheduleStepCutoffTime[0]);
            // need to adjust for meaning of hour
            if (hour == 12) {
                hour = 0;
            } else {
                hour--;
            }
            scheduleCutoffTime.set(Calendar.HOUR, hour);
            if (StringUtils.containsIgnoreCase(scheduleStepCutoffTime[3], "AM")) {
                scheduleCutoffTime.set(Calendar.AM_PM, Calendar.AM);
            } else {
                scheduleCutoffTime.set(Calendar.AM_PM, Calendar.PM);
            }
        } else {
            scheduleCutoffTime.set(Calendar.HOUR_OF_DAY, Integer.parseInt(scheduleStepCutoffTime[0]));
        }
        scheduleCutoffTime.set(Calendar.MINUTE, Integer.parseInt(scheduleStepCutoffTime[1]));
        scheduleCutoffTime.set(Calendar.SECOND, Integer.parseInt(scheduleStepCutoffTime[2]));
        if (parameterService.getParameterValueAsBoolean(ScheduleStep.class,
                OLEConstants.SystemGroupParameterNames.BATCH_SCHEDULE_CUTOFF_TIME_IS_NEXT_DAY)) {
            scheduleCutoffTime.add(Calendar.DAY_OF_YEAR, 1);
        }
        boolean isPastScheduleCutoffTime = dateTime.after(scheduleCutoffTime);
        if (log) {
            LOG.info(new StringBuilder("isPastScheduleCutoffTime=").append(isPastScheduleCutoffTime)
                    .append(" : ").append(dateTimeService.toDateTimeString(dateTime.getTime())).append(" / ")
                    .append(dateTimeService.toDateTimeString(scheduleCutoffTime.getTime())));
        }
        return isPastScheduleCutoffTime;
    } catch (NumberFormatException e) {
        throw new RuntimeException(
                "Caught exception while checking whether we've exceeded the schedule cutoff time", e);
    } catch (SchedulerException e) {
        throw new RuntimeException(
                "Caught exception while checking whether we've exceeded the schedule cutoff time", e);
    }
}

From source file:amhamogus.com.daysoff.fragments.AddEventFragment.java

@Override
public void onTimeSet(TimePicker timePicker, int pickerHour, int pickerMinute) {

    String displayHour;// w  w  w.  ja  v a  2s . c  om
    String displayMinute;

    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.MINUTE, pickerMinute);
    calendar.set(Calendar.HOUR_OF_DAY, pickerHour);

    hour = pickerHour;
    minute = pickerMinute;

    if (hour == 0) {
        displayHour = "12";
        noonOrNight = "AM";
    } else if (hour > 12) {
        displayHour = (hour - 12) + "";
        noonOrNight = "PM";
    } else {
        noonOrNight = "AM";
        displayHour = hour + "";
    }

    if (minute < 10) {
        displayMinute = "0" + minute;
    } else {
        displayMinute = minute + "";
    }
    // Add AM or PM to the user selected time range
    String amOrPm = ((calendar.get(Calendar.AM_PM)) == Calendar.AM) ? "am" : "pm";
    timeLabel.setText(displayHour + ":" + displayMinute + " " + amOrPm);
}

From source file:org.kuali.kfs.sys.batch.service.impl.SchedulerServiceImpl.java

protected boolean isPastScheduleCutoffTime(Calendar dateTime, boolean log) {
    try {/*from  w  ww  . j  a va2s.  c  om*/
        Date scheduleCutoffTimeTemp = scheduler.getTriggersOfJob(SCHEDULE_JOB_NAME, SCHEDULED_GROUP)[0]
                .getPreviousFireTime();
        Calendar scheduleCutoffTime;
        if (scheduleCutoffTimeTemp == null) {
            scheduleCutoffTime = dateTimeService.getCurrentCalendar();
        } else {
            scheduleCutoffTime = dateTimeService.getCalendar(scheduleCutoffTimeTemp);
        }
        String cutoffParameter = parameterService.getParameterValueAsString(ScheduleStep.class,
                KFSConstants.SystemGroupParameterNames.BATCH_SCHEDULE_CUTOFF_TIME);
        String[] scheduleStepCutoffTime = StringUtils.split(cutoffParameter, ":");
        if (scheduleStepCutoffTime.length != 3 && scheduleStepCutoffTime.length != 4) {
            throw new IllegalArgumentException(
                    "Error! The " + KFSConstants.SystemGroupParameterNames.BATCH_SCHEDULE_CUTOFF_TIME
                            + " parameter had an invalid value: " + cutoffParameter);
        }
        // if there are 4 components, then we have an AM/PM delimiter
        // otherwise, assume 24-hour time
        if (scheduleStepCutoffTime.length == 4) {
            int hour = Integer.parseInt(scheduleStepCutoffTime[0]);
            // need to adjust for meaning of hour
            if (hour == 12) {
                hour = 0;
            } else {
                hour--;
            }
            scheduleCutoffTime.set(Calendar.HOUR, hour);
            if (StringUtils.containsIgnoreCase(scheduleStepCutoffTime[3], "AM")) {
                scheduleCutoffTime.set(Calendar.AM_PM, Calendar.AM);
            } else {
                scheduleCutoffTime.set(Calendar.AM_PM, Calendar.PM);
            }
        } else {
            scheduleCutoffTime.set(Calendar.HOUR_OF_DAY, Integer.parseInt(scheduleStepCutoffTime[0]));
        }
        scheduleCutoffTime.set(Calendar.MINUTE, Integer.parseInt(scheduleStepCutoffTime[1]));
        scheduleCutoffTime.set(Calendar.SECOND, Integer.parseInt(scheduleStepCutoffTime[2]));
        if (parameterService.getParameterValueAsBoolean(ScheduleStep.class,
                KFSConstants.SystemGroupParameterNames.BATCH_SCHEDULE_CUTOFF_TIME_IS_NEXT_DAY)) {
            scheduleCutoffTime.add(Calendar.DAY_OF_YEAR, 1);
        }
        boolean isPastScheduleCutoffTime = dateTime.after(scheduleCutoffTime);
        if (log) {
            LOG.info(new StringBuilder("isPastScheduleCutoffTime=").append(isPastScheduleCutoffTime)
                    .append(" : ").append(dateTimeService.toDateTimeString(dateTime.getTime())).append(" / ")
                    .append(dateTimeService.toDateTimeString(scheduleCutoffTime.getTime())));
        }
        return isPastScheduleCutoffTime;
    } catch (NumberFormatException e) {
        throw new RuntimeException(
                "Caught exception while checking whether we've exceeded the schedule cutoff time", e);
    } catch (SchedulerException e) {
        throw new RuntimeException(
                "Caught exception while checking whether we've exceeded the schedule cutoff time", e);
    }
}

From source file:com.panet.imeta.job.entries.special.JobEntrySpecial.java

private long getNextDailyExecutionTime() {
    Calendar calendar = Calendar.getInstance();

    long nowMillis = calendar.getTimeInMillis();
    int amHour = hour;
    if (amHour > 12) {
        amHour = amHour - 12;/*from  w  ww  .j  ava 2s  .  c  o m*/
        calendar.set(Calendar.AM_PM, Calendar.PM);
    } else {
        calendar.set(Calendar.AM_PM, Calendar.AM);
    }
    calendar.set(Calendar.HOUR, amHour);
    calendar.set(Calendar.MINUTE, minutes);
    if (calendar.getTimeInMillis() <= nowMillis) {
        calendar.add(Calendar.DAY_OF_MONTH, 1);
    }
    return calendar.getTimeInMillis() - nowMillis;
}

From source file:org.broadleafcommerce.cms.web.BroadleafProcessURLFilter.java

private SandBox determineSandbox(HttpServletRequest request, Site site) {
    SandBox currentSandbox = null;//  w w  w  .j av a  2  s  .c o  m
    if (!sandBoxPreviewEnabled) {
        if (LOG.isTraceEnabled()) {
            LOG.trace("Sandbox preview disabled. Setting sandbox to production");
        }
        request.setAttribute(SANDBOX_VAR, currentSandbox);
    } else {
        Long sandboxId = null;
        if (request.getParameter("blSandboxDateTimeRibbonProduction") == null) {
            sandboxId = lookupSandboxId(request);
        } else {
            request.getSession().removeAttribute(SANDBOX_DATE_TIME_VAR);
            request.getSession().removeAttribute(SANDBOX_ID_VAR);
        }
        if (sandboxId != null) {
            currentSandbox = sandBoxService.retrieveSandBoxById(sandboxId);
            request.setAttribute(SANDBOX_VAR, currentSandbox);
            if (currentSandbox != null && !SandBoxType.PRODUCTION.equals(currentSandbox.getSandBoxType())) {
                setContentTime(request);
            }
        }

        //            if (currentSandbox == null && site != null) {
        //                currentSandbox = site.getProductionSandbox();
        //            }
    }

    if (LOG.isTraceEnabled()) {
        LOG.trace("Serving request using sandbox: " + currentSandbox);
    }

    Date currentSystemDateTime = SystemTime.asDate(true);
    Calendar sandboxDateTimeCalendar = Calendar.getInstance();
    sandboxDateTimeCalendar.setTime(currentSystemDateTime);
    request.setAttribute(SANDBOX_DISPLAY_DATE_TIME_DATE_PARAM,
            CONTENT_DATE_DISPLAY_FORMATTER.format(currentSystemDateTime));
    request.setAttribute(SANDBOX_DISPLAY_DATE_TIME_HOURS_PARAM,
            CONTENT_DATE_DISPLAY_HOURS_FORMATTER.format(currentSystemDateTime));
    request.setAttribute(SANDBOX_DISPLAY_DATE_TIME_MINUTES_PARAM,
            CONTENT_DATE_DISPLAY_MINUTES_FORMATTER.format(currentSystemDateTime));
    request.setAttribute(SANDBOX_DISPLAY_DATE_TIME_AMPM_PARAM, sandboxDateTimeCalendar.get(Calendar.AM_PM));
    return currentSandbox;
}

From source file:MailDateFormatter.java

private static String getAMPM(Calendar cal) {
    return (cal.get(Calendar.AM_PM) == Calendar.AM) ? "a" : "p";
}

From source file:com.liferay.portlet.journal.lar.JournalPortletDataHandlerImpl.java

public static void importArticle(PortletDataContext portletDataContext, Element articleElement)
        throws Exception {

    String path = articleElement.attributeValue("path");

    if (!portletDataContext.isPathNotProcessed(path)) {
        return;//from w w  w. j  a  va  2s . c  o  m
    }

    JournalArticle article = (JournalArticle) portletDataContext.getZipEntryAsObject(path);

    prepareLanguagesForImport(article);

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

    JournalCreationStrategy creationStrategy = JournalCreationStrategyFactory.getInstance();

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

    if (authorId != JournalCreationStrategy.USE_DEFAULT_USER_ID_STRATEGY) {
        userId = authorId;
    }

    User user = UserLocalServiceUtil.getUser(userId);

    String articleId = article.getArticleId();
    boolean autoArticleId = false;

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

    String newArticleId = articleIds.get(articleId);

    // ======= Start of change ============
    if (Validator.isNotNull(newArticleId)) {

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

        articleId = newArticleId;
    }
    // =======end of change================

    String content = article.getContent();

    content = importDLFileEntries(portletDataContext, articleElement, content);

    Group group = GroupLocalServiceUtil.getGroup(portletDataContext.getScopeGroupId());

    content = StringUtil.replace(content, "@data_handler_group_friendly_url@", group.getFriendlyURL());

    content = importLinksToLayout(portletDataContext, content);

    article.setContent(content);

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

    if (!StringUtils.equals(JournalCreationStrategy.ARTICLE_CONTENT_UNCHANGED, newContent)) {
        article.setContent(newContent);
    }

    Map<String, String> structureIds = (Map<String, String>) portletDataContext
            .getNewPrimaryKeysMap(JournalStructure.class);

    String parentStructureId = MapUtil.getString(structureIds, article.getStructureId(),
            article.getStructureId());

    Map<String, String> templateIds = (Map<String, String>) portletDataContext
            .getNewPrimaryKeysMap(JournalTemplate.class);

    String parentTemplateId = MapUtil.getString(templateIds, article.getTemplateId(), article.getTemplateId());

    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;
        }
    }

    long structurePrimaryKey = 0;

    if (Validator.isNotNull(article.getStructureId())) {
        String structureUuid = articleElement.attributeValue("structure-uuid");

        JournalStructure existingStructure = JournalStructureUtil.fetchByUUID_G(structureUuid,
                portletDataContext.getScopeGroupId());

        if (existingStructure == null) {
            Group companyGroup = GroupLocalServiceUtil.getCompanyGroup(portletDataContext.getCompanyId());

            long companyGroupId = companyGroup.getGroupId();

            existingStructure = JournalStructureUtil.fetchByUUID_G(structureUuid, companyGroupId);
        }

        if (existingStructure == null) {
            String newStructureId = structureIds.get(article.getStructureId());

            if (Validator.isNotNull(newStructureId)) {
                existingStructure = JournalStructureUtil.fetchByG_S(portletDataContext.getScopeGroupId(),
                        String.valueOf(newStructureId));
            }

            if (existingStructure == null) {
                if (_log.isWarnEnabled()) {
                    StringBundler sb = new StringBundler();

                    sb.append("Structure ");
                    sb.append(article.getStructureId());
                    sb.append(" is missing for article ");
                    sb.append(article.getArticleId());
                    sb.append(", skipping this article.");

                    _log.warn(sb.toString());
                }

                return;
            }
        }

        structurePrimaryKey = existingStructure.getPrimaryKey();

        parentStructureId = existingStructure.getStructureId();
    }

    if (Validator.isNotNull(article.getTemplateId())) {
        String templateUuid = articleElement.attributeValue("template-uuid");

        JournalTemplate existingTemplate = JournalTemplateUtil.fetchByUUID_G(templateUuid,
                portletDataContext.getScopeGroupId());

        if (existingTemplate == null) {
            Group companyGroup = GroupLocalServiceUtil.getCompanyGroup(portletDataContext.getCompanyId());

            long companyGroupId = companyGroup.getGroupId();

            existingTemplate = JournalTemplateUtil.fetchByUUID_G(templateUuid, companyGroupId);
        }

        if (existingTemplate == null) {
            String newTemplateId = templateIds.get(article.getTemplateId());

            if (Validator.isNotNull(newTemplateId)) {
                existingTemplate = JournalTemplateUtil.fetchByG_T(portletDataContext.getScopeGroupId(),
                        newTemplateId);
            }

            if (existingTemplate == null) {
                if (_log.isWarnEnabled()) {
                    StringBundler sb = new StringBundler();

                    sb.append("Template ");
                    sb.append(article.getTemplateId());
                    sb.append(" is missing for article ");
                    sb.append(article.getArticleId());
                    sb.append(", skipping this article.");

                    _log.warn(sb.toString());
                }

                return;
            }
        }

        parentTemplateId = existingTemplate.getTemplateId();
    }

    File smallFile = null;

    String smallImagePath = articleElement.attributeValue("small-image-path");

    if (article.isSmallImage() && Validator.isNotNull(smallImagePath)) {
        byte[] bytes = portletDataContext.getZipEntryAsByteArray(smallImagePath);

        smallFile = FileUtil.createTempFile(article.getSmallImageType());

        FileUtil.write(smallFile, bytes);
    }

    Map<String, byte[]> images = new HashMap<String, byte[]>();

    String imagePath = articleElement.attributeValue("image-path");

    if (portletDataContext.getBooleanParameter(_NAMESPACE, "images") && Validator.isNotNull(imagePath)) {

        List<String> imageFiles = portletDataContext.getZipFolderEntries(imagePath);

        for (String imageFile : imageFiles) {
            String fileName = imageFile;

            if (fileName.contains(StringPool.SLASH)) {
                fileName = fileName.substring(fileName.lastIndexOf(CharPool.SLASH) + 1);
            }

            if (fileName.endsWith(".xml")) {
                continue;
            }

            int pos = fileName.lastIndexOf(CharPool.PERIOD);

            if (pos != -1) {
                fileName = fileName.substring(0, pos);
            }

            images.put(fileName, portletDataContext.getZipEntryAsByteArray(imageFile));
        }
    }

    String articleURL = null;

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

    ServiceContext serviceContext = portletDataContext.createServiceContext(articleElement, article,
            _NAMESPACE);

    serviceContext.setAddGroupPermissions(addGroupPermissions);
    serviceContext.setAddGuestPermissions(addGuestPermissions);
    serviceContext.setAttribute("imported", Boolean.TRUE.toString());

    if (article.getStatus() != WorkflowConstants.STATUS_APPROVED) {
        serviceContext.setWorkflowAction(WorkflowConstants.ACTION_SAVE_DRAFT);
    }

    JournalArticle importedArticle = null;

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

    if (portletDataContext.isDataStrategyMirror()) {
        JournalArticleResource articleResource = JournalArticleResourceUtil.fetchByUUID_G(articleResourceUuid,
                portletDataContext.getScopeGroupId());

        if (articleResource == null) {
            Group companyGroup = GroupLocalServiceUtil.getCompanyGroup(portletDataContext.getCompanyId());

            long companyGroupId = companyGroup.getGroupId();

            articleResource = JournalArticleResourceUtil.fetchByUUID_G(articleResourceUuid, companyGroupId);
        }
        //Modification start
        if (articleResource == null) {
            articleResource = JournalArticleResourceUtil.fetchByG_A(portletDataContext.getScopeGroupId(),
                    articleId);
        }
        //Modification end
        serviceContext.setUuid(articleResourceUuid);

        JournalArticle existingArticle = null;

        if (articleResource != null) {
            try {
                existingArticle = JournalArticleLocalServiceUtil.getLatestArticle(
                        articleResource.getResourcePrimKey(), WorkflowConstants.STATUS_ANY, false);
            } catch (NoSuchArticleException nsae) {
            }
        }

        if (existingArticle == null) {
            existingArticle = JournalArticleUtil.fetchByG_A_V(portletDataContext.getScopeGroupId(),
                    newArticleId, article.getVersion());
        }

        if (existingArticle == null) {
            importedArticle = JournalArticleLocalServiceUtil.addArticle(userId,
                    portletDataContext.getScopeGroupId(), article.getClassNameId(), structurePrimaryKey,
                    articleId, autoArticleId, article.getVersion(), article.getTitleMap(),
                    article.getDescriptionMap(), article.getContent(), article.getType(), parentStructureId,
                    parentTemplateId, 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,
                    images, articleURL, serviceContext);
        } else {
            importedArticle = JournalArticleLocalServiceUtil.updateArticle(userId, existingArticle.getGroupId(),
                    existingArticle.getArticleId(), existingArticle.getVersion(), article.getTitleMap(),
                    article.getDescriptionMap(), article.getContent(), article.getType(), parentStructureId,
                    parentTemplateId, 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,
                    images, articleURL, serviceContext);
        }
    } else {
        importedArticle = JournalArticleLocalServiceUtil.addArticle(userId,
                portletDataContext.getScopeGroupId(), article.getClassNameId(), structurePrimaryKey, articleId,
                autoArticleId, article.getVersion(), article.getTitleMap(), article.getDescriptionMap(),
                article.getContent(), article.getType(), parentStructureId, parentTemplateId,
                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, images, articleURL,
                serviceContext);
    }

    if (smallFile != null) {
        smallFile.delete();
    }

    portletDataContext.importClassedModel(article, importedArticle, _NAMESPACE);

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

    Group companyGroup = GroupLocalServiceUtil.getCompanyGroup(portletDataContext.getCompanyId());

    if (importedArticle.getGroupId() == companyGroup.getGroupId()) {
        portletDataContext.addCompanyReference(JournalArticle.class, articleId);
    }

    if (!articleId.equals(importedArticle.getArticleId())) {
        if (_log.isWarnEnabled()) {
            _log.warn("An article with the ID " + articleId + " already " + "exists. The new generated ID is "
                    + importedArticle.getArticleId());
        }
    }
}