mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
ALF-9156 Add CalendarService list methods, and add a temp implementation of the basic case using the FileFolderService, plus tests
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@28920 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -42,7 +42,9 @@
|
||||
<bean id="calendarService" class="org.alfresco.repo.calendar.CalendarServiceImpl">
|
||||
<property name="nodeService" ref="NodeService"/>
|
||||
<property name="siteService" ref="SiteService"/>
|
||||
<property name="searchService" ref="SearchService" /> <!-- TODO Temp -->
|
||||
<property name="taggingService" ref="TaggingService"/>
|
||||
<property name="fileFolderService" ref="FileFolderService" /> <!-- TODO Temp -->
|
||||
<property name="permissionService" ref="PermissionService"/>
|
||||
<property name="transactionService" ref="transactionService" />
|
||||
</bean>
|
||||
|
@@ -28,17 +28,23 @@ import java.util.Set;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.query.PagingRequest;
|
||||
import org.alfresco.query.PagingResults;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
|
||||
import org.alfresco.service.cmr.calendar.CalendarEntry;
|
||||
import org.alfresco.service.cmr.calendar.CalendarService;
|
||||
import org.alfresco.service.cmr.model.FileFolderService;
|
||||
import org.alfresco.service.cmr.model.FileInfo;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.search.SearchService;
|
||||
import org.alfresco.service.cmr.security.PermissionService;
|
||||
import org.alfresco.service.cmr.site.SiteService;
|
||||
import org.alfresco.service.cmr.tagging.TaggingService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.service.transaction.TransactionService;
|
||||
import org.alfresco.util.Pair;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
@@ -64,7 +70,9 @@ public class CalendarServiceImpl implements CalendarService
|
||||
|
||||
private NodeService nodeService;
|
||||
private SiteService siteService;
|
||||
private SearchService searchService; // TODO Temp only
|
||||
private TaggingService taggingService;
|
||||
private FileFolderService fileFolderService; // TODO Temp only
|
||||
private PermissionService permissionService;
|
||||
private TransactionService transactionService;
|
||||
|
||||
@@ -78,11 +86,27 @@ public class CalendarServiceImpl implements CalendarService
|
||||
this.siteService = siteService;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Temp only
|
||||
*/
|
||||
public void setSearchService(SearchService searchService)
|
||||
{
|
||||
this.searchService = searchService;
|
||||
}
|
||||
|
||||
public void setTaggingService(TaggingService taggingService)
|
||||
{
|
||||
this.taggingService = taggingService;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Temp only
|
||||
*/
|
||||
public void setFileFolderService(FileFolderService fileFolderService)
|
||||
{
|
||||
this.fileFolderService = fileFolderService;
|
||||
}
|
||||
|
||||
public void setPermissionService(PermissionService permissionService)
|
||||
{
|
||||
this.permissionService = permissionService;
|
||||
@@ -330,4 +354,83 @@ public class CalendarServiceImpl implements CalendarService
|
||||
|
||||
nodeService.deleteNode(entry.getNodeRef());
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Switch to delegating
|
||||
*/
|
||||
@Override
|
||||
public PagingResults<CalendarEntry> listCalendarEntries(
|
||||
String siteShortName, PagingRequest paging)
|
||||
{
|
||||
// TODO Switch to this
|
||||
//return listCalendarEntries(new String[] { siteShortName }, paging);
|
||||
|
||||
NodeRef container = getSiteCalendarContainer(siteShortName, false);
|
||||
if(container == null)
|
||||
{
|
||||
// No events
|
||||
return null;
|
||||
}
|
||||
|
||||
// Ask the file folder service
|
||||
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));
|
||||
PagingResults<FileInfo> results = fileFolderService.list(container, true, false, null, sort, paging);
|
||||
return wrap(results);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PagingResults<CalendarEntry> listCalendarEntries(
|
||||
String[] siteShortNames, PagingRequest paging)
|
||||
{
|
||||
// TODO Use search for now
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PagingResults<CalendarEntry> listCalendarEntries(
|
||||
String[] siteShortNames, Date from, Date to, PagingRequest paging)
|
||||
{
|
||||
// TODO Use search for now
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Temp hack!
|
||||
*/
|
||||
private PagingResults<CalendarEntry> wrap(final PagingResults<FileInfo> results)
|
||||
{
|
||||
return new PagingResults<CalendarEntry>()
|
||||
{
|
||||
@Override
|
||||
public String getQueryExecutionId()
|
||||
{
|
||||
return results.getQueryExecutionId();
|
||||
}
|
||||
@Override
|
||||
public List<CalendarEntry> getPage()
|
||||
{
|
||||
List<CalendarEntry> entries = new ArrayList<CalendarEntry>();
|
||||
for(FileInfo file : results.getPage())
|
||||
{
|
||||
CalendarEntryImpl entry = new CalendarEntryImpl(file.getNodeRef(), file.getName());
|
||||
entry.populate(nodeService.getProperties(file.getNodeRef()));
|
||||
entry.setTags(taggingService.getTags(file.getNodeRef()));
|
||||
entries.add(entry);
|
||||
}
|
||||
return entries;
|
||||
}
|
||||
@Override
|
||||
public boolean hasMoreItems()
|
||||
{
|
||||
return results.hasMoreItems();
|
||||
}
|
||||
@Override
|
||||
public Pair<Integer, Integer> getTotalResultCount()
|
||||
{
|
||||
return results.getTotalResultCount();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@@ -25,7 +25,6 @@ import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
@@ -33,7 +32,6 @@ import java.util.List;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.query.PagingRequest;
|
||||
import org.alfresco.query.PagingResults;
|
||||
import org.alfresco.repo.blog.BlogService.BlogPostInfo;
|
||||
import org.alfresco.repo.policy.BehaviourFilter;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.site.SiteModel;
|
||||
@@ -41,10 +39,7 @@ import org.alfresco.repo.transaction.RetryingTransactionHelper;
|
||||
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.dictionary.DataTypeDefinition;
|
||||
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.security.MutableAuthenticationService;
|
||||
@@ -53,10 +48,7 @@ import org.alfresco.service.cmr.site.SiteInfo;
|
||||
import org.alfresco.service.cmr.site.SiteService;
|
||||
import org.alfresco.service.cmr.site.SiteVisibility;
|
||||
import org.alfresco.service.cmr.tagging.TaggingService;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.ApplicationContextHelper;
|
||||
import org.alfresco.util.Pair;
|
||||
import org.alfresco.util.PropertyMap;
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
@@ -430,7 +422,55 @@ public class CalendarServiceImplTest
|
||||
CALENDAR_SERVICE.deleteCalendarEntry(entry);
|
||||
}
|
||||
|
||||
@Test public void calendarListing() throws Exception
|
||||
/**
|
||||
* Simplest tests for listing on just one site, with no filtering
|
||||
*/
|
||||
@Test public void calendarSingleSiteListing() throws Exception
|
||||
{
|
||||
PagingRequest paging = new PagingRequest(10);
|
||||
|
||||
// Nothing to start
|
||||
PagingResults<CalendarEntry> results =
|
||||
CALENDAR_SERVICE.listCalendarEntries(CALENDAR_SITE.getShortName(), paging);
|
||||
assertEquals(0, results.getPage().size());
|
||||
|
||||
// Add a few
|
||||
CALENDAR_SERVICE.createCalendarEntry(CALENDAR_SITE.getShortName(), new CalendarEntryDTO(
|
||||
"TitleA", "Description", "Location", new Date(1302431400), new Date(1302435000)
|
||||
));
|
||||
CALENDAR_SERVICE.createCalendarEntry(CALENDAR_SITE.getShortName(), new CalendarEntryDTO(
|
||||
"TitleB", "Description", "Location", new Date(1302431400), new Date(1302442200)
|
||||
));
|
||||
CALENDAR_SERVICE.createCalendarEntry(CALENDAR_SITE.getShortName(), new CalendarEntryDTO(
|
||||
"TitleC", "Description", "Location", new Date(1302435000), new Date(1302442200)
|
||||
));
|
||||
|
||||
// Check now
|
||||
results = CALENDAR_SERVICE.listCalendarEntries(CALENDAR_SITE.getShortName(), paging);
|
||||
assertEquals(3, results.getPage().size());
|
||||
assertEquals("TitleA", results.getPage().get(0).getTitle());
|
||||
assertEquals("TitleB", results.getPage().get(1).getTitle());
|
||||
assertEquals("TitleC", results.getPage().get(2).getTitle());
|
||||
|
||||
// Add one more, before those, and drop the page size
|
||||
CALENDAR_SERVICE.createCalendarEntry(CALENDAR_SITE.getShortName(), new CalendarEntryDTO(
|
||||
"TitleD", "Description", "Location", new Date(1302417000), new Date(1302420600)
|
||||
));
|
||||
|
||||
paging = new PagingRequest(3);
|
||||
results = CALENDAR_SERVICE.listCalendarEntries(CALENDAR_SITE.getShortName(), paging);
|
||||
assertEquals(3, results.getPage().size());
|
||||
assertEquals("TitleD", results.getPage().get(0).getTitle());
|
||||
assertEquals("TitleA", results.getPage().get(1).getTitle());
|
||||
assertEquals("TitleB", results.getPage().get(2).getTitle());
|
||||
|
||||
paging = new PagingRequest(3, 3);
|
||||
results = CALENDAR_SERVICE.listCalendarEntries(CALENDAR_SITE.getShortName(), paging);
|
||||
assertEquals(1, results.getPage().size());
|
||||
assertEquals("TitleC", results.getPage().get(0).getTitle());
|
||||
}
|
||||
|
||||
@Test public void calendarMultiSiteListing() throws Exception
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
|
@@ -20,8 +20,9 @@ package org.alfresco.service.cmr.calendar;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.alfresco.query.PagingRequest;
|
||||
import org.alfresco.query.PagingResults;
|
||||
import org.alfresco.service.NotAuditable;
|
||||
import org.alfresco.service.cmr.site.SiteInfo;
|
||||
|
||||
/**
|
||||
* The Calendar service.
|
||||
@@ -61,4 +62,25 @@ public interface CalendarService {
|
||||
*/
|
||||
@NotAuditable
|
||||
CalendarEntry getCalendarEntry(String siteShortName, String entryName);
|
||||
|
||||
/**
|
||||
* Retrieves all {@link CalendarEntry} instances in the repository
|
||||
* for the given site.
|
||||
*/
|
||||
@NotAuditable
|
||||
PagingResults<CalendarEntry> listCalendarEntries(String siteShortName, PagingRequest paging);
|
||||
|
||||
/**
|
||||
* Retrieves all {@link CalendarEntry} instances in the repository
|
||||
* for the given sites.
|
||||
*/
|
||||
@NotAuditable
|
||||
PagingResults<CalendarEntry> listCalendarEntries(String[] siteShortNames, PagingRequest paging);
|
||||
|
||||
/**
|
||||
* Retrieves all {@link CalendarEntry} instances in the repository
|
||||
* for the given sites, between the specified date range
|
||||
*/
|
||||
@NotAuditable
|
||||
PagingResults<CalendarEntry> listCalendarEntries(String[] siteShortNames, Date from, Date to, PagingRequest paging);
|
||||
}
|
||||
|
Reference in New Issue
Block a user