Example usage for com.liferay.portal.kernel.util DateRange DateRange

List of usage examples for com.liferay.portal.kernel.util DateRange DateRange

Introduction

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

Prototype

public DateRange(Date startDate, Date endDate) 

Source Link

Usage

From source file:com.liferay.exportimport.controller.PortletExportController.java

License:Open Source License

public void exportPortletData(PortletDataContext portletDataContext, Portlet portlet, Layout layout,
        javax.portlet.PortletPreferences jxPortletPreferences, Element parentElement) throws Exception {

    if (portlet == null) {
        return;/*from w w w  .j av  a 2s  . c  o m*/
    }

    PortletDataHandler portletDataHandler = portlet.getPortletDataHandlerInstance();

    if ((portletDataHandler == null) || portletDataHandler.isDataPortletInstanceLevel()) {

        return;
    }

    Group group = _groupLocalService.getGroup(portletDataContext.getGroupId());

    long plid = LayoutConstants.DEFAULT_PLID;

    if (layout != null) {
        group = layout.getGroup();
        plid = layout.getPlid();
    }

    if (group.isStagingGroup()) {
        group = group.getLiveGroup();
    }

    String portletId = portlet.getPortletId();

    if (ExportImportThreadLocal.isStagingInProcess() && !group.isStagedPortlet(portletId)) {

        if (_log.isDebugEnabled()) {
            _log.debug("Not exporting data for " + portletId + " because it is configured not to be staged");
        }

        return;
    }

    if (_log.isDebugEnabled()) {
        _log.debug("Exporting data for " + portletId);
    }

    String path = ExportImportPathUtil.getPortletDataPath(portletDataContext);

    if (portletDataContext.hasPrimaryKey(String.class, path)) {
        return;
    }

    Date originalStartDate = portletDataContext.getStartDate();

    Date portletLastPublishDate = ExportImportDateUtil.getLastPublishDate(portletDataContext,
            jxPortletPreferences);

    portletDataContext.setStartDate(portletLastPublishDate);

    long groupId = portletDataContext.getGroupId();

    portletDataContext.setGroupId(portletDataContext.getScopeGroupId());

    portletDataContext.clearScopedPrimaryKeys();

    String data = null;

    try {
        data = portletDataHandler.exportData(portletDataContext, portletId, jxPortletPreferences);
    } finally {
        portletDataContext.setGroupId(groupId);
        portletDataContext.setStartDate(originalStartDate);
    }

    if (Validator.isNull(data)) {
        if (_log.isDebugEnabled()) {
            _log.debug("Not exporting data for " + portletId + " because null data was returned");
        }

        return;
    }

    Element portletDataElement = parentElement.addElement("portlet-data");

    portletDataElement.addAttribute("path", path);

    portletDataContext.addZipEntry(path, data);

    boolean updateLastPublishDate = MapUtil.getBoolean(portletDataContext.getParameterMap(),
            PortletDataHandlerKeys.UPDATE_LAST_PUBLISH_DATE);

    if (ExportImportThreadLocal.isStagingInProcess() && updateLastPublishDate) {

        DateRange adjustedDateRange = new DateRange(portletLastPublishDate, portletDataContext.getEndDate());

        _exportImportProcessCallbackRegistry.registerCallback(portletDataContext.getExportImportProcessId(),
                new UpdatePortletLastPublishDateCallable(adjustedDateRange, portletDataContext.getEndDate(),
                        portletDataContext.getGroupId(), plid, portletId));
    }
}

From source file:com.liferay.exportimport.lar.PortletDataContextImpl.java

License:Open Source License

@Override
public DateRange getDateRange() {
    DateRange dateRange = null;/*  ww  w . j a  v a2 s .com*/

    if (hasDateRange()) {
        dateRange = new DateRange(_startDate, _endDate);
    }

    return dateRange;
}

From source file:com.liferay.exportimport.test.ExportImportDateUtilTest.java

License:Open Source License

@Test
public void testUpdateLastPublishDateFirstPublishLayoutSet() throws Exception {

    Date now = new Date();

    Date startDate = new Date(now.getTime() + Time.DAY);
    Date endDate = new Date(now.getTime() + Time.WEEK);

    DateRange dateRange = new DateRange(startDate, endDate);

    ExportImportDateUtil.updateLastPublishDate(_layoutSet.getGroupId(), _layoutSet.isPrivateLayout(), dateRange,
            endDate);//from   w  w w.java 2 s.  c  o m

    _layoutSet = LayoutSetLocalServiceUtil.getLayoutSet(_layoutSet.getLayoutSetId());

    Date lastPublishDate = ExportImportDateUtil.getLastPublishDate(_layoutSet);

    // It should be null, since no update should have happened, because it
    // would result in a gap for contents

    Assert.assertNull(lastPublishDate);
}

From source file:com.liferay.exportimport.test.ExportImportDateUtilTest.java

License:Open Source License

@Test
public void testUpdateLastPublishDateFirstPublishPortlet() throws Exception {

    Date now = new Date();

    Date startDate = new Date(now.getTime() + Time.DAY);
    Date endDate = new Date(now.getTime() + Time.WEEK);

    DateRange dateRange = new DateRange(startDate, endDate);

    ExportImportDateUtil.updateLastPublishDate(PortletKeys.EXPORT_IMPORT, _portletPreferences, dateRange,
            endDate);//from  ww  w.j a  v a 2 s.c o m

    Date lastPublishDate = ExportImportDateUtil.getLastPublishDate(_portletPreferences);

    // It should be null, since no update should have happened, because it
    // would result in a gap for contents

    Assert.assertNull(lastPublishDate);
}

From source file:com.liferay.exportimport.test.ExportImportDateUtilTest.java

License:Open Source License

@Test
public void testUpdateLastPublishDateOverlappingRangeLayoutSet() throws Exception {

    Date now = new Date();

    updateLastPublishDate(_layoutSet, now);

    Date startDate = new Date(now.getTime() - Time.DAY);
    Date endDate = new Date(now.getTime() + Time.WEEK);

    DateRange dateRange = new DateRange(startDate, endDate);

    ExportImportDateUtil.updateLastPublishDate(_layoutSet.getGroupId(), _layoutSet.isPrivateLayout(), dateRange,
            endDate);/*from  ww w.  ja va  2s  . c om*/

    _layoutSet = LayoutSetLocalServiceUtil.getLayoutSet(_layoutSet.getLayoutSetId());

    Date lastPublishDate = ExportImportDateUtil.getLastPublishDate(_layoutSet);

    Assert.assertEquals(endDate.getTime(), lastPublishDate.getTime());
}

From source file:com.liferay.exportimport.test.ExportImportDateUtilTest.java

License:Open Source License

@Test
public void testUpdateLastPublishDateOverlappingRangePortlet() throws Exception {

    Date now = new Date();

    updateLastPublishDate(_portletPreferences, now);

    Date startDate = new Date(now.getTime() - Time.DAY);
    Date endDate = new Date(now.getTime() + Time.WEEK);

    DateRange dateRange = new DateRange(startDate, endDate);

    ExportImportDateUtil.updateLastPublishDate(PortletKeys.EXPORT_IMPORT, _portletPreferences, dateRange,
            endDate);/*from w ww.ja  va 2 s  .co  m*/

    Date lastPublishDate = ExportImportDateUtil.getLastPublishDate(_portletPreferences);

    Assert.assertEquals(endDate.getTime(), lastPublishDate.getTime());
}

From source file:com.liferay.exportimport.test.ExportImportDateUtilTest.java

License:Open Source License

@Test
public void testUpdateLastPublishDateRangeBeforeLastPublishDateLayoutSet() throws Exception {

    Date now = new Date();

    updateLastPublishDate(_layoutSet, now);

    Date startDate = new Date(now.getTime() - Time.WEEK);
    Date endDate = new Date(now.getTime() - Time.DAY);

    DateRange dateRange = new DateRange(startDate, endDate);

    ExportImportDateUtil.updateLastPublishDate(_layoutSet.getGroupId(), _layoutSet.isPrivateLayout(), dateRange,
            endDate);//from w ww  .j  a  va 2s  .c o  m

    _layoutSet = LayoutSetLocalServiceUtil.getLayoutSet(_layoutSet.getLayoutSetId());

    Date lastPublishDate = ExportImportDateUtil.getLastPublishDate(_layoutSet);

    Assert.assertEquals(now.getTime(), lastPublishDate.getTime());
}

From source file:com.liferay.exportimport.test.ExportImportDateUtilTest.java

License:Open Source License

@Test
public void testUpdateLastPublishDateRangeBeforeLastPublishDatePortlet() throws Exception {

    Date now = new Date();

    updateLastPublishDate(_portletPreferences, now);

    Date startDate = new Date(now.getTime() - Time.WEEK);
    Date endDate = new Date(now.getTime() - Time.DAY);

    DateRange dateRange = new DateRange(startDate, endDate);

    ExportImportDateUtil.updateLastPublishDate(PortletKeys.EXPORT_IMPORT, _portletPreferences, dateRange,
            endDate);//from  w ww.j  a  va  2  s  . c  om

    Date lastPublishDate = ExportImportDateUtil.getLastPublishDate(_portletPreferences);

    Assert.assertEquals(now.getTime(), lastPublishDate.getTime());
}

From source file:com.liferay.exportimport.test.ExportImportDateUtilTest.java

License:Open Source License

@Test
public void testUpdateLastPublishDateWithGapLayoutSet() throws Exception {
    Date now = new Date();

    updateLastPublishDate(_layoutSet, now);

    Date startDate = new Date(now.getTime() + Time.DAY);
    Date endDate = new Date(now.getTime() + Time.WEEK);

    DateRange dateRange = new DateRange(startDate, endDate);

    ExportImportDateUtil.updateLastPublishDate(_layoutSet.getGroupId(), _layoutSet.isPrivateLayout(), dateRange,
            endDate);/*ww  w .  j  a va2s. c  o  m*/

    _layoutSet = LayoutSetLocalServiceUtil.getLayoutSet(_layoutSet.getLayoutSetId());

    Date lastPublishDate = ExportImportDateUtil.getLastPublishDate(_layoutSet);

    Assert.assertEquals(now.getTime(), lastPublishDate.getTime());
}

From source file:com.liferay.exportimport.test.ExportImportDateUtilTest.java

License:Open Source License

@Test
public void testUpdateLastPublishDateWithGapPortlet() throws Exception {
    Date now = new Date();

    updateLastPublishDate(_portletPreferences, now);

    Date startDate = new Date(now.getTime() + Time.DAY);
    Date endDate = new Date(now.getTime() + Time.WEEK);

    DateRange dateRange = new DateRange(startDate, endDate);

    ExportImportDateUtil.updateLastPublishDate(PortletKeys.EXPORT_IMPORT, _portletPreferences, dateRange,
            endDate);/*from   w w  w  .ja v  a2  s.  c om*/

    Date lastPublishDate = ExportImportDateUtil.getLastPublishDate(_portletPreferences);

    Assert.assertEquals(now.getTime(), lastPublishDate.getTime());
}