mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-08 14:51:49 +00:00
A couple of minor fixes.
Fix method signature to refer to the precise exception thrown. Use Instant from Java 8 rather than DateUtils.truncate.
This commit is contained in:
@@ -37,6 +37,7 @@ import java.io.IOException;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.Serializable;
|
||||
import java.io.Writer;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collections;
|
||||
@@ -46,6 +47,7 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import javax.transaction.SystemException;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.model.ContentModel;
|
||||
@@ -54,7 +56,6 @@ import org.alfresco.module.org_alfresco_module_rm.action.RecordsManagementAction
|
||||
import org.alfresco.module.org_alfresco_module_rm.audit.event.AuditEvent;
|
||||
import org.alfresco.module.org_alfresco_module_rm.capability.CapabilityService;
|
||||
import org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanService;
|
||||
import org.alfresco.module.org_alfresco_module_rm.model.rma.type.RmSiteType;
|
||||
import org.alfresco.repo.audit.AuditComponent;
|
||||
import org.alfresco.repo.audit.model.AuditApplication;
|
||||
import org.alfresco.repo.content.MimetypeMap;
|
||||
@@ -727,7 +728,7 @@ public class RecordsManagementAuditServiceImpl extends AbstractLifecycleBean
|
||||
*
|
||||
* @param auditedNodes details of the nodes that were modified
|
||||
*/
|
||||
private void auditInTxn(Set<RMAuditNode> auditedNodes) throws Throwable
|
||||
private void auditInTxn(Set<RMAuditNode> auditedNodes) throws SystemException
|
||||
{
|
||||
// Go through all the audit information and audit it
|
||||
boolean auditedSomething = false;
|
||||
@@ -1137,9 +1138,10 @@ public class RecordsManagementAuditServiceImpl extends AbstractLifecycleBean
|
||||
* @param date The date for which the start should be calculated.
|
||||
* @return Returns the start of the given date.
|
||||
*/
|
||||
private Date getStartOfDay(Date date)
|
||||
protected Date getStartOfDay(Date date)
|
||||
{
|
||||
return DateUtils.truncate(date == null ? new Date() : date, Calendar.DATE);
|
||||
date = (date == null ? new Date() : date);
|
||||
return Date.from(date.toInstant().truncatedTo(ChronoUnit.DAYS));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -37,6 +37,7 @@ import static org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanServic
|
||||
import static org.alfresco.module.org_alfresco_module_rm.model.RecordsManagementModel.TYPE_RM_SITE;
|
||||
import static org.alfresco.module.org_alfresco_module_rm.model.rma.type.RmSiteType.DEFAULT_SITE_NAME;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.times;
|
||||
@@ -46,7 +47,9 @@ import static org.mockito.MockitoAnnotations.initMocks;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -173,4 +176,25 @@ public class RecordsManagementAuditServiceImplUnitTest
|
||||
// Check that the event of viewing the audit log was itself audited.
|
||||
verify(mockAuditComponent).recordAuditValues(eq(RM_AUDIT_PATH_ROOT), any(Map.class));
|
||||
}
|
||||
|
||||
/** Check that passing null to getStartOfDay doesn't result in null being returned. */
|
||||
@Test
|
||||
public void testGetStartOfDay_null()
|
||||
{
|
||||
Date startOfDay = recordsManagementAuditServiceImpl.getStartOfDay(null);
|
||||
assertNotNull("Expected date to be created by method.", startOfDay);
|
||||
}
|
||||
|
||||
/** Check that any time component passed to getStartOfDay is not included in the response. */
|
||||
@Test
|
||||
public void testGetStartOfDay_timeDiscarded() throws Exception
|
||||
{
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss.SSS");
|
||||
Date date = format.parse("2001-02-03 04:05:06.789");
|
||||
|
||||
// Call the method under test.
|
||||
Date startOfDay = recordsManagementAuditServiceImpl.getStartOfDay(date);
|
||||
|
||||
assertEquals("Unexpected date truncation.", format.parse("2001-02-03 00:00:00.000"), startOfDay);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user