ALF-10318 Update CalendarEntry to hold the created and modified at dates

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@30601 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Nick Burch
2011-09-19 12:56:01 +00:00
parent fb406b769b
commit eced94e231
5 changed files with 88 additions and 7 deletions

View File

@@ -24,6 +24,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.alfresco.model.ContentModel;
import org.alfresco.service.cmr.calendar.CalendarEntry;
import org.alfresco.service.cmr.calendar.CalendarEntryDTO;
import org.alfresco.service.cmr.repository.NodeRef;
@@ -117,6 +118,19 @@ public class CalendarEntryImpl extends CalendarEntryDTO
entry.setOutlookUID((String)properties.get(CalendarModel.PROP_OUTLOOK_UID));
//entry.setColor(properties.get(CalendarModel.PROP_COLOR));
// If the auditable properties are available and the type is correct, record them
if(entry instanceof CalendarEntryDTO)
{
if(properties.containsKey(ContentModel.PROP_CREATED))
{
((CalendarEntryDTO)entry).setCreatedAt((Date)properties.get(ContentModel.PROP_CREATED));
}
if(properties.containsKey(ContentModel.PROP_MODIFIED))
{
((CalendarEntryDTO)entry).setModifiedAt((Date)properties.get(ContentModel.PROP_MODIFIED));
}
}
}
/**

View File

@@ -39,6 +39,7 @@ import org.alfresco.repo.node.getchildren.GetChildrenCannedQuery;
import org.alfresco.repo.node.getchildren.GetChildrenCannedQueryFactory;
import org.alfresco.repo.site.SiteServiceImpl;
import org.alfresco.service.cmr.calendar.CalendarEntry;
import org.alfresco.service.cmr.calendar.CalendarEntryDTO;
import org.alfresco.service.cmr.calendar.CalendarService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
@@ -143,6 +144,10 @@ public class CalendarServiceImpl implements CalendarService
}
NodeRef event = nodeService.getChildByName(container, ContentModel.ASSOC_CONTAINS, entryName);
return getCalendarEntry(event, entryName, container);
}
private CalendarEntry getCalendarEntry(NodeRef event, String entryName, NodeRef container)
{
if (event != null)
{
CalendarEntryImpl entry = new CalendarEntryImpl(event, container, entryName);
@@ -196,6 +201,11 @@ public class CalendarServiceImpl implements CalendarService
entryImpl.setTags(entry.getTags());
}
// Set the auditable properties on it
Date createdAt = (Date)nodeService.getProperty(nodeRef, ContentModel.PROP_CREATED);
entryImpl.setCreatedAt(createdAt);
entryImpl.setModifiedAt(createdAt);
// Tag it
taggingService.setTags(nodeRef, entry.getTags());
@@ -230,9 +240,23 @@ public class CalendarServiceImpl implements CalendarService
// Update the tags
taggingService.setTags(entry.getNodeRef(), entry.getTags());
// Nothing was changed on the entry itself
// Update the auditable properties
if(entry instanceof CalendarEntryDTO)
{
((CalendarEntryDTO)entry).setModifiedAt(
(Date)nodeService.getProperty(entry.getNodeRef(), ContentModel.PROP_MODIFIED)
);
// Return the same object
return entry;
}
else
{
// Need to change the modified date, but we can't
// Re-fetch to pick up the change
return getCalendarEntry(entry.getNodeRef(), entry.getSystemName(), entry.getContainerNodeRef());
}
}
@Override
public void deleteCalendarEntry(CalendarEntry entry)

View File

@@ -185,6 +185,9 @@ public class CalendarServiceImplTest
NodeRef site = NODE_SERVICE.getPrimaryParent(container).getParentRef();
assertEquals(CALENDAR_SITE.getNodeRef(), site);
// Tell the test system about it, for tidying later
testNodesToTidy.add(entry.getNodeRef());
// Check the details on the object
assertEquals("Title", entry.getTitle());
@@ -197,6 +200,10 @@ public class CalendarServiceImplTest
assertEquals(true, entry.isOutlook());
assertEquals("12345LookOut!", entry.getOutlookUID());
// Check that auditable properties turned up
assertNotNull(entry.getCreatedAt());
assertNotNull(entry.getModifiedAt());
// Fetch it, and check the details
entry = CALENDAR_SERVICE.getCalendarEntry(CALENDAR_SITE.getShortName(), entry.getSystemName());
@@ -210,9 +217,9 @@ public class CalendarServiceImplTest
assertEquals(true, entry.isOutlook());
assertEquals("12345LookOut!", entry.getOutlookUID());
// Mark it as done with
testNodesToTidy.add(entry.getNodeRef());
// Check that auditable properties turned up
assertNotNull(entry.getCreatedAt());
assertNotNull(entry.getModifiedAt());
}
@Test public void createUpdateDeleteEntry() throws Exception

View File

@@ -159,4 +159,14 @@ public interface CalendarEntry extends Serializable, PermissionCheckValue
* @return the Tags associated with the event
*/
List<String> getTags();
/**
* @return the creation date and time
*/
Date getCreatedAt();
/**
* @return the modification date and time
*/
Date getModifiedAt();
}

View File

@@ -52,6 +52,8 @@ public class CalendarEntryDTO implements CalendarEntry, Serializable
private String sharePointDocFolder;
private boolean isOutlook = false;
private String outlookUID;
private Date createdAt;
private Date modifiedAt;
private List<String> tags = new ArrayList<String>();
/**
@@ -270,6 +272,30 @@ public class CalendarEntryDTO implements CalendarEntry, Serializable
return tags;
}
/**
* Gets when this entry was created
*/
public Date getCreatedAt()
{
return createdAt;
}
public void setCreatedAt(Date createdAt)
{
this.createdAt = createdAt;
}
/**
* Gets when this entry was modified
*/
public Date getModifiedAt()
{
return modifiedAt;
}
public void setModifiedAt(Date modifiedAt)
{
this.modifiedAt = modifiedAt;
}
/**
* Does the given {@link CalendarEntry} define an all-day
* event?