Support for listing calendar entries by their outlook status (isOutlook / OutlookUID), via a Canned Query

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@38094 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Nick Burch
2012-06-20 21:38:53 +00:00
parent 33db4ac506
commit 74a9e650c2
5 changed files with 96 additions and 0 deletions

View File

@@ -12,6 +12,7 @@
<list>
<value>getCalendarEntry</value>
<value>listCalendarEntries</value>
<value>listOutlookCalendarEntries</value>
</list>
</property>
</bean>

View File

@@ -1007,6 +1007,7 @@
<property name="objectDefinitionSource">
<value>
org.alfresco.service.cmr.calendar.CalendarService.listCalendarEntries=ACL_ALLOW,AFTER_ACL_NODE.sys:base.ReadProperties
org.alfresco.service.cmr.calendar.CalendarService.listOutlookCalendarEntries=ACL_ALLOW,AFTER_ACL_NODE.sys:base.ReadProperties
</value>
</property>
</bean>

View File

@@ -35,6 +35,10 @@ import org.alfresco.query.PagingResults;
import org.alfresco.repo.calendar.cannedqueries.GetCalendarEntriesCannedQuery;
import org.alfresco.repo.calendar.cannedqueries.GetCalendarEntriesCannedQueryFactory;
import org.alfresco.repo.domain.node.NodeDAO;
import org.alfresco.repo.node.getchildren.FilterProp;
import org.alfresco.repo.node.getchildren.FilterPropBoolean;
import org.alfresco.repo.node.getchildren.FilterPropString;
import org.alfresco.repo.node.getchildren.FilterPropString.FilterTypeString;
import org.alfresco.repo.node.getchildren.GetChildrenCannedQuery;
import org.alfresco.repo.node.getchildren.GetChildrenCannedQueryFactory;
import org.alfresco.repo.site.SiteServiceImpl;
@@ -348,6 +352,54 @@ public class CalendarServiceImpl implements CalendarService
return cq.execute();
}
@Override
public PagingResults<CalendarEntry> listOutlookCalendarEntries(String siteShortName, String outlookUID,
PagingRequest paging)
{
NodeRef container = getSiteCalendarContainer(siteShortName, false);
if (container == null)
{
// No events
return new EmptyPagingResults<CalendarEntry>();
}
// Build our sorting, by date
// There is a limit on the number of filter and sorts, so we can't
// do all that much sorting
List<Pair<QName,Boolean>> sort = new ArrayList<Pair<QName, Boolean>>();
sort.add(new Pair<QName, Boolean>(CalendarModel.PROP_FROM_DATE, true));
sort.add(new Pair<QName, Boolean>(CalendarModel.PROP_TO_DATE, true));
// We only want calendar entries
Set<QName> types = new HashSet<QName>();
types.add(CalendarModel.TYPE_EVENT);
// Filtering is OR based, so we can't filder on both IS_OUTLOOK and OUTLOOK_UID
// Luckily, OUTLOOK_UID implies IS_OUTLOOK
List<FilterProp> filters = new ArrayList<FilterProp>();
if (outlookUID != null)
{
// Filter by the UID, will get only outlook ones implicitly
filters.add(new FilterPropString(
CalendarModel.PROP_OUTLOOK_UID, outlookUID, FilterTypeString.EQUALS
));
}
else
{
// Find all Outlook ones
filters.add(new FilterPropBoolean(CalendarModel.PROP_IS_OUTLOOK, Boolean.TRUE));
}
// Run the canned query
GetChildrenCannedQueryFactory getChildrenCannedQueryFactory = (GetChildrenCannedQueryFactory)cannedQueryRegistry.getNamedObject(CANNED_QUERY_GET_CHILDREN);
GetChildrenCannedQuery cq = (GetChildrenCannedQuery)getChildrenCannedQueryFactory.getCannedQuery(
container, null, null, types, filters, sort, paging);
// Execute the canned query
CannedQueryResults<NodeRef> results = cq.execute();
return wrap(results, container);
}
/**
* Our class to wrap up paged results of NodeRefs as
* CalendarEntry instances

View File

@@ -503,6 +503,41 @@ public class CalendarServiceImplTest
results = CALENDAR_SERVICE.listCalendarEntries(CALENDAR_SITE.getShortName(), paging);
assertEquals(1, results.getPage().size());
assertEquals("TitleC", results.getPage().get(0).getTitle());
// Currently, none of the events are Outlook ones, so an outlook list should find none
paging = new PagingRequest(3);
results = CALENDAR_SERVICE.listOutlookCalendarEntries(CALENDAR_SITE.getShortName(), null, paging);
assertEquals(0, results.getPage().size());
// Make two of them be outlook ones, will both be found if no UID restriction is given
String uidB = "THIS_is_A_fake_UID_123";
String uidC = "THIS_is_A_fake_UID_4321";
((CalendarEntryDTO)entryB).setOutlook(true);
((CalendarEntryDTO)entryB).setOutlookUID(uidB);
((CalendarEntryDTO)entryC).setOutlook(true);
((CalendarEntryDTO)entryC).setOutlookUID(uidC);
CALENDAR_SERVICE.updateCalendarEntry(entryB);
CALENDAR_SERVICE.updateCalendarEntry(entryC);
paging = new PagingRequest(3);
results = CALENDAR_SERVICE.listOutlookCalendarEntries(CALENDAR_SITE.getShortName(), null, paging);
assertEquals(2, results.getPage().size());
assertEquals("TitleB", results.getPage().get(0).getTitle());
assertEquals("TitleC", results.getPage().get(1).getTitle());
// Restrict by UID
paging = new PagingRequest(3);
results = CALENDAR_SERVICE.listOutlookCalendarEntries(CALENDAR_SITE.getShortName(), uidB, paging);
assertEquals(1, results.getPage().size());
assertEquals("TitleB", results.getPage().get(0).getTitle());
paging = new PagingRequest(3);
results = CALENDAR_SERVICE.listOutlookCalendarEntries(CALENDAR_SITE.getShortName(), uidC, paging);
assertEquals(1, results.getPage().size());
assertEquals("TitleC", results.getPage().get(0).getTitle());
}
/**

View File

@@ -82,4 +82,11 @@ public interface CalendarService
*/
@NotAuditable
PagingResults<CalendarEntry> listCalendarEntries(String[] siteShortNames, Date from, Date to, PagingRequest paging);
/**
* Retrieves all Outlook based {@link CalendarEntry} instances in the repository
* for the given site, optionally filtered by the Outlook Event UID.
*/
@NotAuditable
PagingResults<CalendarEntry> listOutlookCalendarEntries(String siteShortName, String outlookUID, PagingRequest paging);
}