Merged 5.2.N (5.2.1) to HEAD (5.2)

126098 amukha: Merged 5.1.N (5.1.2) to 5.2.N (5.2.1)
      126058 jkaabimofrad: ACE-5001: Added a utility class to calculate the number of days between the start and end dates, so we could have a single source when dealing with such functionality. Also, changed the RepoUsageComponentImpl class to use this util class.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@127841 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Alan Davis
2016-06-06 08:35:08 +00:00
parent 412d05e36a
commit 4f30a54465
2 changed files with 82 additions and 8 deletions

View File

@@ -52,7 +52,8 @@ import org.alfresco.service.cmr.attributes.AttributeService;
import org.alfresco.service.cmr.dictionary.DictionaryService; import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.security.AuthorityService; import org.alfresco.service.cmr.security.AuthorityService;
import org.alfresco.service.namespace.QName; import org.alfresco.service.namespace.QName;
import org.alfresco.service.transaction.TransactionService; import org.alfresco.service.transaction.TransactionService;
import org.alfresco.util.DateUtil;
import org.alfresco.util.PropertyCheck; import org.alfresco.util.PropertyCheck;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
@@ -512,24 +513,23 @@ public class RepoUsageComponentImpl implements RepoUsageComponent
Long licenseExpiryDate = restrictions.getLicenseExpiryDate(); Long licenseExpiryDate = restrictions.getLicenseExpiryDate();
if (licenseExpiryDate != null) if (licenseExpiryDate != null)
{ {
long remainingMs = licenseExpiryDate - System.currentTimeMillis(); int remainingDays = DateUtil.calculateDays(System.currentTimeMillis(), licenseExpiryDate);
double remainingDays = (double) remainingMs / (double)(24*3600000); if (remainingDays <= 0)
if (remainingDays <= 0.0)
{ {
errors.add(I18NUtil.getMessage("system.usage.err.limit_license_expired")); errors.add(I18NUtil.getMessage("system.usage.err.limit_license_expired"));
level = RepoUsageLevel.LOCKED_DOWN; level = RepoUsageLevel.LOCKED_DOWN;
} }
else if (remainingDays <= 7.0) else if (remainingDays <= 7)
{ {
warnings.add(I18NUtil.getMessage("system.usage.err.limit_license_expiring", (int)remainingDays)); warnings.add(I18NUtil.getMessage("system.usage.err.limit_license_expiring", remainingDays));
if (level.ordinal() < RepoUsageLevel.WARN_ADMIN.ordinal()) if (level.ordinal() < RepoUsageLevel.WARN_ADMIN.ordinal())
{ {
level = RepoUsageLevel.WARN_ALL; level = RepoUsageLevel.WARN_ALL;
} }
} }
else if (remainingDays <= 21.0) else if (remainingDays <= 21)
{ {
warnings.add(I18NUtil.getMessage("system.usage.err.limit_license_expiring", (int)remainingDays)); warnings.add(I18NUtil.getMessage("system.usage.err.limit_license_expiring", remainingDays));
if (level.ordinal() < RepoUsageLevel.WARN_ALL.ordinal()) if (level.ordinal() < RepoUsageLevel.WARN_ALL.ordinal())
{ {
level = RepoUsageLevel.WARN_ADMIN; level = RepoUsageLevel.WARN_ADMIN;

View File

@@ -0,0 +1,74 @@
/*
* #%L
* Alfresco Repository
* %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
package org.alfresco.util;
import org.joda.time.DateTime;
import org.joda.time.Interval;
import org.joda.time.Period;
import org.joda.time.PeriodType;
/**
* A utility class for working with dates.
*
* @author Jamal Kaabi-Mofrad
*/
public class DateUtil
{
private DateUtil()
{
//Private constructor to suppress default constructor for non-instantiability
}
/**
* Calculate the number of days between start and end dates based on the <b>default</b> timezone.
* If the end date is before the start date, the returned value is negative.
*
* @param startMs start date in milliseconds
* @param endMs end date in milliseconds
* @return number days between
*/
public static int calculateDays(long startMs, long endMs)
{
DateTime startDateTime = new DateTime(startMs).withTimeAtStartOfDay();
DateTime endDateTime = new DateTime(endMs).withTimeAtStartOfDay();
int days;
if (endDateTime.isBefore(startDateTime))
{
Interval interval = new Interval(endDateTime, startDateTime);
Period period = interval.toPeriod(PeriodType.days());
days = 0 - period.getDays();
}
else
{
Interval interval = new Interval(startDateTime, endDateTime);
Period period = interval.toPeriod(PeriodType.days());
days = period.getDays();
}
return days;
}
}