RM-812 (Unable to audit for events that happened on a single day only, that is, date from and to being the same)

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@53938 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Tuna Aksoy
2013-08-12 11:28:15 +00:00
parent 026cc3035c
commit 9714ce7727

View File

@@ -26,6 +26,7 @@ import java.io.OutputStreamWriter;
import java.io.Serializable;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
@@ -71,6 +72,7 @@ import org.alfresco.util.PropertyCheck;
import org.alfresco.util.PropertyMap;
import org.alfresco.util.TempFileProvider;
import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.lang.time.DateUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.json.JSONArray;
@@ -498,7 +500,7 @@ public class RecordsManagementAuditServiceImpl
// TODO use file plan to scope audit log
// TODO: return proper date, for now it's today's date
return new Date();
return getStartOfDay(new Date());
}
/**
@@ -519,7 +521,7 @@ public class RecordsManagementAuditServiceImpl
// TODO use file plan to scope audit log
// TODO: return proper date, for now it's today's date
return new Date();
return getEndOfDay(new Date());
}
/**
@@ -1081,8 +1083,8 @@ public class RecordsManagementAuditServiceImpl
};
String user = params.getUser();
Long fromTime = (params.getDateFrom() == null ? null : new Long(params.getDateFrom().getTime()));
Long toTime = (params.getDateTo() == null ? null : new Long(params.getDateTo().getTime()));
Long fromTime = getFromDateTime(params.getDateFrom());
Long toTime = getToDateTime(params.getDateTo());
NodeRef nodeRef = params.getNodeRef();
int maxEntries = params.getMaxEntries();
boolean forward = maxEntries > 0 ? false : true; // Reverse order if the results are limited
@@ -1113,6 +1115,90 @@ public class RecordsManagementAuditServiceImpl
writeAuditTrailFooter(writer, reportFormat);
}
/**
* Calculates the start of the given date.
* For example, if you had the date time of 12 Aug 2013 12:10:15.158
* the result would be 12 Aug 2013 00:00:00.000.
*
* @param date The date for which the start should be calculated.
* @return Returns the start of the given date.
*/
private Date getStartOfDay(Date date)
{
return DateUtils.truncate(date == null ? new Date() : date, Calendar.DATE);
}
/**
* Gets the start of the from date
* @see org.alfresco.module.org_alfresco_module_rm.audit.RecordsManagementAuditServiceImpl.getStartOfDay()
*
* @param date The date for which the start should be retrieved.
* @return Returns null if the given date is null, otherwise the start of the given day.
*/
private Date getFromDate(Date date)
{
return date == null ? null : getStartOfDay(date);
}
/**
* Returns the number of milliseconds for the "from date".
*
* @param date The date for which the number of milliseconds should retrieved.
* @return Returns null if the given date is null, otherwise the number of milliseconds for the given date.
*/
private Long getFromDateTime(Date date)
{
Long fromDateTime = null;
Date fromDate = getFromDate(date);
if (fromDate != null)
{
fromDateTime = new Long(fromDate.getTime());
}
return fromDateTime;
}
/**
* Calculates the end of the given date.
* For example, if you had the date time of 12 Aug 2013 12:10:15.158
* the result would be 12 Aug 2013 23:59:59.999.
*
* @param date The date for which the end should be calculated.
* @return Returns the end of the given date.
*/
private Date getEndOfDay(Date date)
{
return DateUtils.addMilliseconds(DateUtils.ceiling(date == null ? new Date() : date, Calendar.DATE), -1);
}
/**
* Gets the end of the from date
* @see org.alfresco.module.org_alfresco_module_rm.audit.RecordsManagementAuditServiceImpl.getEndOfDay()
*
* @param date The date for which the end should be retrieved.
* @return Returns null if the given date is null, otherwise the end of the given day.
*/
private Date getToDate(Date date)
{
return date == null ? null : getEndOfDay(date);
}
/**
* Returns the number of milliseconds for the "to date".
*
* @param date The date for which the number of milliseconds should retrieved.
* @return Returns null if the given date is null, otherwise the number of milliseconds for the given date.
*/
private Long getToDateTime(Date date)
{
Long toDateTime = null;
Date toDate = getToDate(date);
if (toDate != null)
{
toDateTime = new Long(toDate.getTime());
}
return toDateTime;
}
/**
* {@inheritDoc}
*/
@@ -1255,9 +1341,9 @@ public class RecordsManagementAuditServiceImpl
// write header as JSON
writer.write("{\n\t\"data\":\n\t{");
writer.write("\n\t\t\"started\": \"");
writer.write(ISO8601DateFormat.format(getDateLastStarted()));
writer.write(ISO8601DateFormat.format(getStartOfDay(params.getDateFrom())));
writer.write("\",\n\t\t\"stopped\": \"");
writer.write(ISO8601DateFormat.format(getDateLastStopped()));
writer.write(ISO8601DateFormat.format(getEndOfDay(params.getDateTo())));
writer.write("\",\n\t\t\"enabled\": ");
writer.write(Boolean.toString(isEnabled()));
writer.write(",\n\t\t\"entries\":[");