Return-Path: Delivered-To: apmail-incubator-chemistry-commits-archive@minotaur.apache.org Received: (qmail 21850 invoked from network); 29 Jan 2011 16:41:51 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 29 Jan 2011 16:41:51 -0000 Received: (qmail 1489 invoked by uid 500); 29 Jan 2011 16:41:51 -0000 Delivered-To: apmail-incubator-chemistry-commits-archive@incubator.apache.org Received: (qmail 1442 invoked by uid 500); 29 Jan 2011 16:41:50 -0000 Mailing-List: contact chemistry-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: chemistry-dev@incubator.apache.org Delivered-To: mailing list chemistry-commits@incubator.apache.org Received: (qmail 1433 invoked by uid 99); 29 Jan 2011 16:41:50 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 29 Jan 2011 16:41:50 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 29 Jan 2011 16:41:43 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 8C4042388903; Sat, 29 Jan 2011 16:41:20 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: svn commit: r1065064 - in /incubator/chemistry/dotcmis/trunk: ./ DotCMIS/ DotCMIS/binding/ DotCMIS/binding/atompub/ DotCMIS/client/ DotCMISUnitTest/ Date: Sat, 29 Jan 2011 16:41:20 -0000 To: chemistry-commits@incubator.apache.org From: fmui@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110129164120.8C4042388903@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: fmui Date: Sat Jan 29 16:41:19 2011 New Revision: 1065064 URL: http://svn.apache.org/viewvc?rev=1065064&view=rev Log: implemented enumerators Added: incubator/chemistry/dotcmis/trunk/DotCMIS/client/client-utils.cs incubator/chemistry/dotcmis/trunk/DotCMISUnitTest/EnumeratorTest.cs incubator/chemistry/dotcmis/trunk/DotCMISUnitTest/SmokeTest.cs Modified: incubator/chemistry/dotcmis/trunk/DotCMIS.suo incubator/chemistry/dotcmis/trunk/DotCMIS/DotCMIS.csproj incubator/chemistry/dotcmis/trunk/DotCMIS/binding/atompub/atompub-linkcache.cs incubator/chemistry/dotcmis/trunk/DotCMIS/binding/binding-caches.cs incubator/chemistry/dotcmis/trunk/DotCMIS/client/client-impl.cs incubator/chemistry/dotcmis/trunk/DotCMIS/client/client-intf.cs incubator/chemistry/dotcmis/trunk/DotCMIS/client/client-types.cs incubator/chemistry/dotcmis/trunk/DotCMISUnitTest/DotCMISUnitTest.csproj incubator/chemistry/dotcmis/trunk/DotCMISUnitTest/DotCMISUnitTest.csproj.user incubator/chemistry/dotcmis/trunk/DotCMISUnitTest/TestFramework.cs Modified: incubator/chemistry/dotcmis/trunk/DotCMIS.suo URL: http://svn.apache.org/viewvc/incubator/chemistry/dotcmis/trunk/DotCMIS.suo?rev=1065064&r1=1065063&r2=1065064&view=diff ============================================================================== Binary files - no diff available. Modified: incubator/chemistry/dotcmis/trunk/DotCMIS/DotCMIS.csproj URL: http://svn.apache.org/viewvc/incubator/chemistry/dotcmis/trunk/DotCMIS/DotCMIS.csproj?rev=1065064&r1=1065063&r2=1065064&view=diff ============================================================================== --- incubator/chemistry/dotcmis/trunk/DotCMIS/DotCMIS.csproj (original) +++ incubator/chemistry/dotcmis/trunk/DotCMIS/DotCMIS.csproj Sat Jan 29 16:41:19 2011 @@ -59,6 +59,7 @@ + Modified: incubator/chemistry/dotcmis/trunk/DotCMIS/binding/atompub/atompub-linkcache.cs URL: http://svn.apache.org/viewvc/incubator/chemistry/dotcmis/trunk/DotCMIS/binding/atompub/atompub-linkcache.cs?rev=1065064&r1=1065063&r2=1065064&view=diff ============================================================================== --- incubator/chemistry/dotcmis/trunk/DotCMIS/binding/atompub/atompub-linkcache.cs (original) +++ incubator/chemistry/dotcmis/trunk/DotCMIS/binding/atompub/atompub-linkcache.cs Sat Jan 29 16:41:19 2011 @@ -256,7 +256,7 @@ namespace DotCMIS.Binding.AtomPub { public ContentTypeCacheLevel() { - EnableKeyFallback(null); + EnableKeyFallback(NullKey); } public override object this[string key] Modified: incubator/chemistry/dotcmis/trunk/DotCMIS/binding/binding-caches.cs URL: http://svn.apache.org/viewvc/incubator/chemistry/dotcmis/trunk/DotCMIS/binding/binding-caches.cs?rev=1065064&r1=1065063&r2=1065064&view=diff ============================================================================== --- incubator/chemistry/dotcmis/trunk/DotCMIS/binding/binding-caches.cs (original) +++ incubator/chemistry/dotcmis/trunk/DotCMIS/binding/binding-caches.cs Sat Jan 29 16:41:19 2011 @@ -352,7 +352,7 @@ namespace DotCMIS.Binding internal abstract class AbstractDictionaryCacheLevel : ICacheLevel { - private static string NullKey = ""; + protected static string NullKey = ""; private IDictionary dict; private bool fallbackEnabled = false; Modified: incubator/chemistry/dotcmis/trunk/DotCMIS/client/client-impl.cs URL: http://svn.apache.org/viewvc/incubator/chemistry/dotcmis/trunk/DotCMIS/client/client-impl.cs?rev=1065064&r1=1065063&r2=1065064&view=diff ============================================================================== --- incubator/chemistry/dotcmis/trunk/DotCMIS/client/client-impl.cs (original) +++ incubator/chemistry/dotcmis/trunk/DotCMIS/client/client-impl.cs Sat Jan 29 16:41:19 2011 @@ -26,6 +26,7 @@ using DotCMIS.Exceptions; using System.Threading; using DotCMIS.Enums; using DotCMIS.Data.Extensions; +using DotCMIS.Binding.Services; namespace DotCMIS.Client { @@ -332,11 +333,51 @@ namespace DotCMIS.Client return ObjectFactory.ConvertTypeDefinition(typeDefinition); } - public IItemIterable GetTypeChildren(string typeId, bool includePropertyDefinitions) - { throw new CmisNotSupportedException("Client not implemented!"); } + public IItemEnumerable GetTypeChildren(string typeId, bool includePropertyDefinitions) + { + IRepositoryService repositoryService = Binding.GetRepositoryService(); + + PageFetcher.FetchPage fetchPageDelegate = delegate(long maxNumItems, long skipCount) + { + // fetch the data + ITypeDefinitionList tdl = repositoryService.GetTypeChildren(RepositoryId, typeId, includePropertyDefinitions, maxNumItems, skipCount, null); + + // convert type definitions + IList page = new List(tdl.List.Count); + foreach (ITypeDefinition typeDefinition in tdl.List) + { + page.Add(ObjectFactory.ConvertTypeDefinition(typeDefinition)); + } + + return new PageFetcher.Page(page, tdl.NumItems, tdl.HasMoreItems); + }; + + return new CollectionEnumerable(new PageFetcher(DefaultContext.MaxItemsPerPage, fetchPageDelegate)); + } public IList> GetTypeDescendants(string typeId, int depth, bool includePropertyDefinitions) - { throw new CmisNotSupportedException("Client not implemented!"); } + { + IList descendants = Binding.GetRepositoryService().GetTypeDescendants( + RepositoryId, typeId, depth, includePropertyDefinitions, null); + + return ConvertTypeDescendants(descendants); + } + + private IList> ConvertTypeDescendants(IList descendantsList) + { + IList> result = new List>(); + + foreach (ITypeDefinitionContainer container in descendantsList) + { + Tree tree = new Tree(); + tree.Item = ObjectFactory.ConvertTypeDefinition(container.TypeDefinition); + tree.Children = ConvertTypeDescendants(container.Children); + + result.Add(tree); + } + + return result; + } // navigation @@ -347,9 +388,7 @@ namespace DotCMIS.Client public IFolder GetRootFolder(IOperationContext context) { - string rootFolderId = RepositoryInfo.RootFolderId; - - ICmisObject rootFolder = GetObject(CreateObjectId(rootFolderId), context); + ICmisObject rootFolder = GetObject(CreateObjectId(RepositoryInfo.RootFolderId), context); if (!(rootFolder is IFolder)) { throw new CmisRuntimeException("Root folder object is not a folder!"); @@ -358,10 +397,10 @@ namespace DotCMIS.Client return (IFolder)rootFolder; } - public IItemIterable GetCheckedOutDocs() + public IItemEnumerable GetCheckedOutDocs() { throw new CmisNotSupportedException("Client not implemented!"); } - public IItemIterable GetCheckedOutDocs(IOperationContext context) + public IItemEnumerable GetCheckedOutDocs(IOperationContext context) { throw new CmisNotSupportedException("Client not implemented!"); } public ICmisObject GetObject(IObjectId objectId) @@ -382,59 +421,59 @@ namespace DotCMIS.Client // discovery - public IItemIterable Query(string statement, bool searchAllVersions) + public IItemEnumerable Query(string statement, bool searchAllVersions) { throw new CmisNotSupportedException("Client not implemented!"); } - public IItemIterable query(string statement, bool searchAllVersions, IOperationContext context) + public IItemEnumerable Query(string statement, bool searchAllVersions, IOperationContext context) { throw new CmisNotSupportedException("Client not implemented!"); } - public IChangeEvents getContentChanges(string changeLogToken, bool includeProperties, long maxNumItems) + public IChangeEvents GetContentChanges(string changeLogToken, bool includeProperties, long maxNumItems) { throw new CmisNotSupportedException("Client not implemented!"); } - public IChangeEvents getContentChanges(string changeLogToken, bool includeProperties, long maxNumItems, + public IChangeEvents GetContentChanges(string changeLogToken, bool includeProperties, long maxNumItems, IOperationContext context) { throw new CmisNotSupportedException("Client not implemented!"); } // create - public IObjectId CreateDocument(IDictionary properties, IObjectId folderId, IContentStream contentStream, + public IObjectId CreateDocument(IDictionary properties, IObjectId folderId, IContentStream contentStream, VersioningState? versioningState, IList policies, IList addAces, IList removeAces) { throw new CmisNotSupportedException("Client not implemented!"); } - public IObjectId CreateDocument(IDictionary properties, IObjectId folderId, IContentStream contentStream, + public IObjectId CreateDocument(IDictionary properties, IObjectId folderId, IContentStream contentStream, VersioningState? versioningState) { throw new CmisNotSupportedException("Client not implemented!"); } - public IObjectId CreateDocumentFromSource(IObjectId source, IDictionary properties, IObjectId folderId, + public IObjectId CreateDocumentFromSource(IObjectId source, IDictionary properties, IObjectId folderId, VersioningState? versioningState, IList policies, IList addAces, IList removeAces) { throw new CmisNotSupportedException("Client not implemented!"); } - public IObjectId CreateDocumentFromSource(IObjectId source, IDictionary properties, IObjectId folderId, + public IObjectId CreateDocumentFromSource(IObjectId source, IDictionary properties, IObjectId folderId, VersioningState? versioningState) { throw new CmisNotSupportedException("Client not implemented!"); } - public IObjectId CreateFolder(IDictionary properties, IObjectId folderId, IList policies, IList addAces, + public IObjectId CreateFolder(IDictionary properties, IObjectId folderId, IList policies, IList addAces, IList removeAces) { throw new CmisNotSupportedException("Client not implemented!"); } - public IObjectId CreateFolder(IDictionary properties, IObjectId folderId) + public IObjectId CreateFolder(IDictionary properties, IObjectId folderId) { throw new CmisNotSupportedException("Client not implemented!"); } - public IObjectId CreatePolicy(IDictionary properties, IObjectId folderId, IList policies, IList addAces, + public IObjectId CreatePolicy(IDictionary properties, IObjectId folderId, IList policies, IList addAces, IList removeAces) { throw new CmisNotSupportedException("Client not implemented!"); } - public IObjectId CreatePolicy(IDictionary properties, IObjectId folderId) + public IObjectId CreatePolicy(IDictionary properties, IObjectId folderId) { throw new CmisNotSupportedException("Client not implemented!"); } - public IObjectId CreateRelationship(IDictionary properties, IList policies, IList addAces, + public IObjectId CreateRelationship(IDictionary properties, IList policies, IList addAces, IList removeAces) { throw new CmisNotSupportedException("Client not implemented!"); } - public IObjectId CreateRelationship(IDictionary properties) + public IObjectId CreateRelationship(IDictionary properties) { throw new CmisNotSupportedException("Client not implemented!"); } - public IItemIterable GetRelationships(IObjectId objectId, bool includeSubRelationshipTypes, + public IItemEnumerable GetRelationships(IObjectId objectId, bool includeSubRelationshipTypes, RelationshipDirection? relationshipDirection, IObjectType type, IOperationContext context) { throw new CmisNotSupportedException("Client not implemented!"); } @@ -462,335 +501,4 @@ namespace DotCMIS.Client Monitor.Exit(sessionLock); } } - - /// - /// Operation context implementation. - /// - public class OperationContext : IOperationContext - { - public const string PropertiesStar = "*"; - public const string RenditionNone = "cmis:none"; - - private HashSet filter; - private bool includeAllowableActions; - private bool includeAcls; - private IncludeRelationshipsFlag? includeRelationships; - private bool includePolicies; - private HashSet renditionFilter; - private bool includePathSegments; - private string orderBy; - private bool cacheEnabled; - private string cacheKey; - private int maxItemsPerPage; - - public OperationContext() - { - filter = null; - includeAcls = false; - includeAllowableActions = true; - includePolicies = false; - includeRelationships = IncludeRelationshipsFlag.None; - renditionFilter = null; - includePathSegments = true; - orderBy = null; - cacheEnabled = false; - maxItemsPerPage = 100; - - GenerateCacheKey(); - } - - public OperationContext(IOperationContext source) - { - filter = new HashSet(source.Filter); - includeAcls = source.IncludeAcls; - includeAllowableActions = source.IncludeAllowableActions; - includePolicies = source.IncludePolicies; - includeRelationships = source.IncludeRelationships; - renditionFilter = new HashSet(source.RenditionFilter); - includePathSegments = source.IncludePathSegments; - orderBy = source.OrderBy; - cacheEnabled = source.CacheEnabled; - maxItemsPerPage = source.MaxItemsPerPage; - - GenerateCacheKey(); - } - - public OperationContext(HashSet filter, bool includeAcls, bool includeAllowableActions, - bool includePolicies, IncludeRelationshipsFlag includeRelationships, HashSet renditionFilter, - bool includePathSegments, String orderBy, bool cacheEnabled, int maxItemsPerPage) - { - this.filter = filter; - this.includeAcls = includeAcls; - this.includeAllowableActions = includeAllowableActions; - this.includePolicies = includePolicies; - this.includeRelationships = includeRelationships; - this.renditionFilter = renditionFilter; - this.includePathSegments = includePathSegments; - this.orderBy = orderBy; - this.cacheEnabled = cacheEnabled; - this.maxItemsPerPage = maxItemsPerPage; - - GenerateCacheKey(); - } - - public HashSet Filter - { - get { return new HashSet(filter); } - set - { - if (value != null) - { - HashSet tempSet = new HashSet(); - foreach (string oid in value) - { - if (oid == null) { continue; } - - string toid = oid.Trim(); - if (toid.Length == 0) { continue; } - if (toid == PropertiesStar) - { - tempSet = new HashSet(); - tempSet.Add(PropertiesStar); - break; - } - if (toid.IndexOf(',') > -1) - { - throw new ArgumentException("Query id must not contain a comma!"); - } - - tempSet.Add(toid); - } - - if (tempSet.Count == 0) { filter = null; } - else { filter = tempSet; } - } - else - { - filter = null; - } - - GenerateCacheKey(); - } - } - - public string FilterString - { - get - { - if (filter == null) { return null; } - - if (filter.Contains(PropertiesStar)) - { - return PropertiesStar; - } - - this.filter.Add(PropertyIds.ObjectId); - this.filter.Add(PropertyIds.BaseTypeId); - this.filter.Add(PropertyIds.ObjectTypeId); - - StringBuilder sb = new StringBuilder(); - - foreach (String oid in filter) - { - if (sb.Length > 0) { sb.Append(','); } - sb.Append(oid); - } - - return sb.ToString(); - } - - set - { - if (value == null || value.Trim().Length == 0) - { - Filter = null; - return; - } - - string[] ids = value.Split(','); - HashSet tempSet = new HashSet(); - foreach (string qid in ids) - { - tempSet.Add(qid); - } - - Filter = tempSet; - } - } - - public bool IncludeAllowableActions - { - get { return includeAllowableActions; } - set { includeAllowableActions = value; GenerateCacheKey(); } - } - - public bool IncludeAcls - { - get { return includeAcls; } - set { includeAcls = value; GenerateCacheKey(); } - } - - public IncludeRelationshipsFlag? IncludeRelationships - { - get { return includeRelationships; } - set { includeRelationships = value; GenerateCacheKey(); } - } - - public bool IncludePolicies - { - get { return includePolicies; } - set { includePolicies = value; GenerateCacheKey(); } - } - - public HashSet RenditionFilter - { - get { return new HashSet(renditionFilter); } - set - { - HashSet tempSet = new HashSet(); - if (value != null) - { - foreach (String rf in value) - { - if (rf == null) { continue; } - - String trf = rf.Trim(); - if (trf.Length == 0) { continue; } - if (trf.IndexOf(',') > -1) - { - throw new ArgumentException("Rendition must not contain a comma!"); - } - - tempSet.Add(trf); - } - - if (tempSet.Count == 0) - { - tempSet.Add(RenditionNone); - } - } - else - { - tempSet.Add(RenditionNone); - } - - renditionFilter = tempSet; - - GenerateCacheKey(); - } - } - - public string RenditionFilterString - { - get - { - if (renditionFilter == null) { return null; } - - StringBuilder sb = new StringBuilder(); - foreach (string rf in renditionFilter) - { - if (sb.Length > 0) { sb.Append(','); } - sb.Append(rf); - } - - return sb.ToString(); - } - - set - { - if (value == null || value.Trim().Length == 0) - { - RenditionFilter = null; - return; - } - - string[] renditions = value.Split(','); - HashSet tempSet = new HashSet(); - foreach (string rend in renditions) - { - tempSet.Add(rend); - } - - RenditionFilter = tempSet; - } - } - - public bool IncludePathSegments - { - get { return includePathSegments; } - set { includePathSegments = value; GenerateCacheKey(); } - } - - public string OrderBy - { - get { return orderBy; } - set { orderBy = value; GenerateCacheKey(); } - } - - public bool CacheEnabled - { - get { return cacheEnabled; } - set { cacheEnabled = value; GenerateCacheKey(); } - } - - public string CacheKey - { - get { return cacheKey; } - } - - public int MaxItemsPerPage - { - get { return maxItemsPerPage; } - set { maxItemsPerPage = value; } - } - - protected void GenerateCacheKey() - { - if (!cacheEnabled) - { - cacheKey = null; - } - - StringBuilder sb = new StringBuilder(); - - sb.Append(includeAcls ? "1" : "0"); - sb.Append(includeAllowableActions ? "1" : "0"); - sb.Append(includePolicies ? "1" : "0"); - sb.Append("|"); - sb.Append(filter == null ? "" : FilterString); - sb.Append("|"); - sb.Append(includeRelationships == null ? "" : includeRelationships.GetCmisValue()); - - sb.Append("|"); - sb.Append(renditionFilter == null ? "" : RenditionFilterString); - - cacheKey = sb.ToString(); - } - } - - /// - /// Object id implementation. - /// - public class ObjectId : IObjectId - { - private string id; - public string Id - { - get { return id; } - set - { - if (value == null || value.Length == 0) - { - throw new ArgumentException("Id must be set!"); - } - - id = value; - } - } - - public ObjectId(string id) - { - Id = id; - } - } } Modified: incubator/chemistry/dotcmis/trunk/DotCMIS/client/client-intf.cs URL: http://svn.apache.org/viewvc/incubator/chemistry/dotcmis/trunk/DotCMIS/client/client-intf.cs?rev=1065064&r1=1065063&r2=1065064&view=diff ============================================================================== --- incubator/chemistry/dotcmis/trunk/DotCMIS/client/client-intf.cs (original) +++ incubator/chemistry/dotcmis/trunk/DotCMIS/client/client-intf.cs Sat Jan 29 16:41:19 2011 @@ -60,15 +60,15 @@ namespace DotCMIS.Client // types IObjectType GetTypeDefinition(string typeId); - IItemIterable GetTypeChildren(string typeId, bool includePropertyDefinitions); + IItemEnumerable GetTypeChildren(string typeId, bool includePropertyDefinitions); IList> GetTypeDescendants(string typeId, int depth, bool includePropertyDefinitions); // navigation IFolder GetRootFolder(); IFolder GetRootFolder(IOperationContext context); - IItemIterable GetCheckedOutDocs(); - IItemIterable GetCheckedOutDocs(IOperationContext context); + IItemEnumerable GetCheckedOutDocs(); + IItemEnumerable GetCheckedOutDocs(IOperationContext context); ICmisObject GetObject(IObjectId objectId); ICmisObject GetObject(IObjectId objectId, IOperationContext context); ICmisObject GetObjectByPath(string path); @@ -76,33 +76,33 @@ namespace DotCMIS.Client // discovery - IItemIterable Query(string statement, bool searchAllVersions); - IItemIterable query(string statement, bool searchAllVersions, IOperationContext context); - IChangeEvents getContentChanges(string changeLogToken, bool includeProperties, long maxNumItems); - IChangeEvents getContentChanges(string changeLogToken, bool includeProperties, long maxNumItems, + IItemEnumerable Query(string statement, bool searchAllVersions); + IItemEnumerable Query(string statement, bool searchAllVersions, IOperationContext context); + IChangeEvents GetContentChanges(string changeLogToken, bool includeProperties, long maxNumItems); + IChangeEvents GetContentChanges(string changeLogToken, bool includeProperties, long maxNumItems, IOperationContext context); // create - IObjectId CreateDocument(IDictionary properties, IObjectId folderId, IContentStream contentStream, + IObjectId CreateDocument(IDictionary properties, IObjectId folderId, IContentStream contentStream, VersioningState? versioningState, IList policies, IList addAces, IList removeAces); - IObjectId CreateDocument(IDictionary properties, IObjectId folderId, IContentStream contentStream, + IObjectId CreateDocument(IDictionary properties, IObjectId folderId, IContentStream contentStream, VersioningState? versioningState); - IObjectId CreateDocumentFromSource(IObjectId source, IDictionary properties, IObjectId folderId, + IObjectId CreateDocumentFromSource(IObjectId source, IDictionary properties, IObjectId folderId, VersioningState? versioningState, IList policies, IList addAces, IList removeAces); - IObjectId CreateDocumentFromSource(IObjectId source, IDictionary properties, IObjectId folderId, + IObjectId CreateDocumentFromSource(IObjectId source, IDictionary properties, IObjectId folderId, VersioningState? versioningState); - IObjectId CreateFolder(IDictionary properties, IObjectId folderId, IList policies, IList addAces, + IObjectId CreateFolder(IDictionary properties, IObjectId folderId, IList policies, IList addAces, IList removeAces); - IObjectId CreateFolder(IDictionary properties, IObjectId folderId); - IObjectId CreatePolicy(IDictionary properties, IObjectId folderId, IList policies, IList addAces, + IObjectId CreateFolder(IDictionary properties, IObjectId folderId); + IObjectId CreatePolicy(IDictionary properties, IObjectId folderId, IList policies, IList addAces, IList removeAces); - IObjectId CreatePolicy(IDictionary properties, IObjectId folderId); - IObjectId CreateRelationship(IDictionary properties, IList policies, IList addAces, + IObjectId CreatePolicy(IDictionary properties, IObjectId folderId); + IObjectId CreateRelationship(IDictionary properties, IList policies, IList addAces, IList removeAces); - IObjectId CreateRelationship(IDictionary properties); + IObjectId CreateRelationship(IDictionary properties); - IItemIterable GetRelationships(IObjectId objectId, bool includeSubRelationshipTypes, + IItemEnumerable GetRelationships(IObjectId objectId, bool includeSubRelationshipTypes, RelationshipDirection? relationshipDirection, IObjectType type, IOperationContext context); // permissions @@ -169,7 +169,7 @@ namespace DotCMIS.Client public interface ITree { T Item { get; } - IList> GetChildren(); + IList> Children { get; } } public interface IObjectType : ITypeDefinition @@ -177,7 +177,7 @@ namespace DotCMIS.Client bool IsBaseType { get; } IObjectType GetBaseType(); IObjectType GetParentType(); - IItemIterable GetChildren(); + IItemEnumerable GetChildren(); IList> GetDescendants(int depth); } @@ -201,11 +201,11 @@ namespace DotCMIS.Client { } - public interface IItemIterable + public interface IItemEnumerable : IEnumerable { - IItemIterable SkipTo(long position); - IItemIterable GetPage(); - IItemIterable GetPage(int maxNumItems); + IItemEnumerable SkipTo(long position); + IItemEnumerable GetPage(); + IItemEnumerable GetPage(int maxNumItems); long PageNumItems { get; } bool HasMoreItems { get; } long TotalNumItems { get; } @@ -369,13 +369,13 @@ namespace DotCMIS.Client IList> GetFolderTree(int depth, IOperationContext context); IList> GetDescendants(int depth); IList> GetDescendants(int depth, IOperationContext context); - IItemIterable GetChildren(); - IItemIterable GetChildren(IOperationContext context); + IItemEnumerable GetChildren(); + IItemEnumerable GetChildren(IOperationContext context); bool IsRootFolder { get; } IFolder FolderParent { get; } string Path { get; } - IItemIterable GetCheckedOutDocs(); - IItemIterable GetCheckedOutDocs(IOperationContext context); + IItemEnumerable GetCheckedOutDocs(); + IItemEnumerable GetCheckedOutDocs(IOperationContext context); } public interface IPolicyProperties Modified: incubator/chemistry/dotcmis/trunk/DotCMIS/client/client-types.cs URL: http://svn.apache.org/viewvc/incubator/chemistry/dotcmis/trunk/DotCMIS/client/client-types.cs?rev=1065064&r1=1065063&r2=1065064&view=diff ============================================================================== --- incubator/chemistry/dotcmis/trunk/DotCMIS/client/client-types.cs (original) +++ incubator/chemistry/dotcmis/trunk/DotCMIS/client/client-types.cs Sat Jan 29 16:41:19 2011 @@ -25,6 +25,9 @@ using DotCMIS.Data; namespace DotCMIS.Client { + /// + /// Helper for all type implementations. + /// internal class ObjectTypeHelper { private ISession session; @@ -62,7 +65,7 @@ namespace DotCMIS.Client return parentType; } - public IItemIterable GetChildren() + public IItemEnumerable GetChildren() { return session.GetTypeChildren(objectType.Id, true); } @@ -73,6 +76,9 @@ namespace DotCMIS.Client } } + /// + /// Document type implementation. + /// public class DocumentType : DocumentTypeDefinition, IDocumentType { private ObjectTypeHelper helper; @@ -87,7 +93,7 @@ namespace DotCMIS.Client public IObjectType GetBaseType() { return helper.GetBaseType(); } - public IItemIterable GetChildren() { return helper.GetChildren(); } + public IItemEnumerable GetChildren() { return helper.GetChildren(); } public IList> GetDescendants(int depth) { return helper.GetDescendants(depth); } @@ -96,6 +102,9 @@ namespace DotCMIS.Client public bool IsBaseType { get { return helper.IsBaseType; } } } + /// + /// Folder type implementation. + /// public class FolderType : FolderTypeDefinition, IFolderType { private ObjectTypeHelper helper; @@ -108,7 +117,7 @@ namespace DotCMIS.Client public IObjectType GetBaseType() { return helper.GetBaseType(); } - public IItemIterable GetChildren() { return helper.GetChildren(); } + public IItemEnumerable GetChildren() { return helper.GetChildren(); } public IList> GetDescendants(int depth) { return helper.GetDescendants(depth); } @@ -117,6 +126,9 @@ namespace DotCMIS.Client public bool IsBaseType { get { return helper.IsBaseType; } } } + /// + /// Relationship type implementation. + /// public class RelationshipType : RelationshipTypeDefinition, IRelationshipType { private ObjectTypeHelper helper; @@ -131,7 +143,7 @@ namespace DotCMIS.Client public IObjectType GetBaseType() { return helper.GetBaseType(); } - public IItemIterable GetChildren() { return helper.GetChildren(); } + public IItemEnumerable GetChildren() { return helper.GetChildren(); } public IList> GetDescendants(int depth) { return helper.GetDescendants(depth); } @@ -182,6 +194,9 @@ namespace DotCMIS.Client } } + /// + /// Policy type implementation. + /// public class PolicyType : PolicyTypeDefinition, IPolicyType { private ObjectTypeHelper helper; @@ -194,7 +209,7 @@ namespace DotCMIS.Client public IObjectType GetBaseType() { return helper.GetBaseType(); } - public IItemIterable GetChildren() { return helper.GetChildren(); } + public IItemEnumerable GetChildren() { return helper.GetChildren(); } public IList> GetDescendants(int depth) { return helper.GetDescendants(depth); } Added: incubator/chemistry/dotcmis/trunk/DotCMIS/client/client-utils.cs URL: http://svn.apache.org/viewvc/incubator/chemistry/dotcmis/trunk/DotCMIS/client/client-utils.cs?rev=1065064&view=auto ============================================================================== --- incubator/chemistry/dotcmis/trunk/DotCMIS/client/client-utils.cs (added) +++ incubator/chemistry/dotcmis/trunk/DotCMIS/client/client-utils.cs Sat Jan 29 16:41:19 2011 @@ -0,0 +1,682 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using DotCMIS.Enums; +using System.Collections; + +namespace DotCMIS.Client +{ + /// + /// Operation context implementation. + /// + public class OperationContext : IOperationContext + { + public const string PropertiesStar = "*"; + public const string RenditionNone = "cmis:none"; + + private HashSet filter; + private bool includeAllowableActions; + private bool includeAcls; + private IncludeRelationshipsFlag? includeRelationships; + private bool includePolicies; + private HashSet renditionFilter; + private bool includePathSegments; + private string orderBy; + private bool cacheEnabled; + private string cacheKey; + private int maxItemsPerPage; + + public OperationContext() + { + filter = null; + includeAcls = false; + includeAllowableActions = true; + includePolicies = false; + includeRelationships = IncludeRelationshipsFlag.None; + renditionFilter = null; + includePathSegments = true; + orderBy = null; + cacheEnabled = false; + maxItemsPerPage = 100; + + GenerateCacheKey(); + } + + public OperationContext(IOperationContext source) + { + filter = new HashSet(source.Filter); + includeAcls = source.IncludeAcls; + includeAllowableActions = source.IncludeAllowableActions; + includePolicies = source.IncludePolicies; + includeRelationships = source.IncludeRelationships; + renditionFilter = new HashSet(source.RenditionFilter); + includePathSegments = source.IncludePathSegments; + orderBy = source.OrderBy; + cacheEnabled = source.CacheEnabled; + maxItemsPerPage = source.MaxItemsPerPage; + + GenerateCacheKey(); + } + + public OperationContext(HashSet filter, bool includeAcls, bool includeAllowableActions, + bool includePolicies, IncludeRelationshipsFlag includeRelationships, HashSet renditionFilter, + bool includePathSegments, String orderBy, bool cacheEnabled, int maxItemsPerPage) + { + this.filter = filter; + this.includeAcls = includeAcls; + this.includeAllowableActions = includeAllowableActions; + this.includePolicies = includePolicies; + this.includeRelationships = includeRelationships; + this.renditionFilter = renditionFilter; + this.includePathSegments = includePathSegments; + this.orderBy = orderBy; + this.cacheEnabled = cacheEnabled; + this.maxItemsPerPage = maxItemsPerPage; + + GenerateCacheKey(); + } + + public HashSet Filter + { + get { return new HashSet(filter); } + set + { + if (value != null) + { + HashSet tempSet = new HashSet(); + foreach (string oid in value) + { + if (oid == null) { continue; } + + string toid = oid.Trim(); + if (toid.Length == 0) { continue; } + if (toid == PropertiesStar) + { + tempSet = new HashSet(); + tempSet.Add(PropertiesStar); + break; + } + if (toid.IndexOf(',') > -1) + { + throw new ArgumentException("Query id must not contain a comma!"); + } + + tempSet.Add(toid); + } + + if (tempSet.Count == 0) { filter = null; } + else { filter = tempSet; } + } + else + { + filter = null; + } + + GenerateCacheKey(); + } + } + + public string FilterString + { + get + { + if (filter == null) { return null; } + + if (filter.Contains(PropertiesStar)) + { + return PropertiesStar; + } + + this.filter.Add(PropertyIds.ObjectId); + this.filter.Add(PropertyIds.BaseTypeId); + this.filter.Add(PropertyIds.ObjectTypeId); + + StringBuilder sb = new StringBuilder(); + + foreach (String oid in filter) + { + if (sb.Length > 0) { sb.Append(','); } + sb.Append(oid); + } + + return sb.ToString(); + } + + set + { + if (value == null || value.Trim().Length == 0) + { + Filter = null; + return; + } + + string[] ids = value.Split(','); + HashSet tempSet = new HashSet(); + foreach (string qid in ids) + { + tempSet.Add(qid); + } + + Filter = tempSet; + } + } + + public bool IncludeAllowableActions + { + get { return includeAllowableActions; } + set { includeAllowableActions = value; GenerateCacheKey(); } + } + + public bool IncludeAcls + { + get { return includeAcls; } + set { includeAcls = value; GenerateCacheKey(); } + } + + public IncludeRelationshipsFlag? IncludeRelationships + { + get { return includeRelationships; } + set { includeRelationships = value; GenerateCacheKey(); } + } + + public bool IncludePolicies + { + get { return includePolicies; } + set { includePolicies = value; GenerateCacheKey(); } + } + + public HashSet RenditionFilter + { + get { return new HashSet(renditionFilter); } + set + { + HashSet tempSet = new HashSet(); + if (value != null) + { + foreach (String rf in value) + { + if (rf == null) { continue; } + + String trf = rf.Trim(); + if (trf.Length == 0) { continue; } + if (trf.IndexOf(',') > -1) + { + throw new ArgumentException("Rendition must not contain a comma!"); + } + + tempSet.Add(trf); + } + + if (tempSet.Count == 0) + { + tempSet.Add(RenditionNone); + } + } + else + { + tempSet.Add(RenditionNone); + } + + renditionFilter = tempSet; + + GenerateCacheKey(); + } + } + + public string RenditionFilterString + { + get + { + if (renditionFilter == null) { return null; } + + StringBuilder sb = new StringBuilder(); + foreach (string rf in renditionFilter) + { + if (sb.Length > 0) { sb.Append(','); } + sb.Append(rf); + } + + return sb.ToString(); + } + + set + { + if (value == null || value.Trim().Length == 0) + { + RenditionFilter = null; + return; + } + + string[] renditions = value.Split(','); + HashSet tempSet = new HashSet(); + foreach (string rend in renditions) + { + tempSet.Add(rend); + } + + RenditionFilter = tempSet; + } + } + + public bool IncludePathSegments + { + get { return includePathSegments; } + set { includePathSegments = value; GenerateCacheKey(); } + } + + public string OrderBy + { + get { return orderBy; } + set { orderBy = value; GenerateCacheKey(); } + } + + public bool CacheEnabled + { + get { return cacheEnabled; } + set { cacheEnabled = value; GenerateCacheKey(); } + } + + public string CacheKey + { + get { return cacheKey; } + } + + public int MaxItemsPerPage + { + get { return maxItemsPerPage; } + set { maxItemsPerPage = value; } + } + + protected void GenerateCacheKey() + { + if (!cacheEnabled) + { + cacheKey = null; + } + + StringBuilder sb = new StringBuilder(); + + sb.Append(includeAcls ? "1" : "0"); + sb.Append(includeAllowableActions ? "1" : "0"); + sb.Append(includePolicies ? "1" : "0"); + sb.Append("|"); + sb.Append(filter == null ? "" : FilterString); + sb.Append("|"); + sb.Append(includeRelationships == null ? "" : includeRelationships.GetCmisValue()); + + sb.Append("|"); + sb.Append(renditionFilter == null ? "" : RenditionFilterString); + + cacheKey = sb.ToString(); + } + } + + /// + /// Object id implementation. + /// + public class ObjectId : IObjectId + { + private string id; + public string Id + { + get { return id; } + set + { + if (value == null || value.Length == 0) + { + throw new ArgumentException("Id must be set!"); + } + + id = value; + } + } + + public ObjectId(string id) + { + Id = id; + } + } + + /// + /// Tree implementation. + /// + public class Tree : ITree + { + public T Item { get; set; } + public IList> Children { get; set; } + } + + /// + /// Base class for IItemEnumerable's. + /// + public abstract class AbstractEnumerable : IItemEnumerable + { + private AbstractEnumerator enumerator; + protected AbstractEnumerator Enumerator + { + get + { + if (enumerator == null) { enumerator = CreateEnumerator(); } + return enumerator; + } + } + + protected PageFetcher PageFetcher { get; set; } + protected long SkipCount { get; private set; } + + public AbstractEnumerable(PageFetcher pageFetcher) : + this(0, pageFetcher) { } + + protected AbstractEnumerable(long position, PageFetcher pageFetcher) + { + this.PageFetcher = pageFetcher; + this.SkipCount = position; + } + + protected abstract AbstractEnumerator CreateEnumerator(); + + IEnumerator IEnumerable.GetEnumerator() + { + return Enumerator; + } + + IEnumerator IEnumerable.GetEnumerator() + { + return Enumerator; + } + + public IItemEnumerable SkipTo(long position) + { + return new CollectionEnumerable(position, PageFetcher); + } + + public IItemEnumerable GetPage() + { + return new CollectionPageEnumerable(SkipCount, PageFetcher); + } + + public IItemEnumerable GetPage(int maxNumItems) + { + PageFetcher.MaxNumItems = maxNumItems; + return new CollectionPageEnumerable(SkipCount, PageFetcher); + } + + public long PageNumItems { get { return Enumerator.PageNumItems; } } + + public bool HasMoreItems { get { return Enumerator.HasMoreItems; } } + + public long TotalNumItems { get { return Enumerator.TotalNumItems; } } + } + + /// + /// Abstract Enumerator implementation. + /// + public abstract class AbstractEnumerator : IEnumerator + { + private PageFetcher pageFetcher; + private PageFetcher.Page page = null; + private long? totalNumItems = null; + private bool? hasMoreItems = null; + + protected T current; + + public AbstractEnumerator(long skipCount, PageFetcher pageFetcher) + { + this.SkipCount = skipCount; + this.pageFetcher = pageFetcher; + } + + T IEnumerator.Current { get { return current; } } + object IEnumerator.Current { get { return current; } } + + public void Reset() + { + throw new NotSupportedException(); + } + + public abstract bool MoveNext(); + + public void Dispose() { } + + public long SkipCount { get; protected set; } + + public int SkipOffset { get; protected set; } + + public long Position { get { return SkipCount + SkipOffset; } } + + public long PageNumItems + { + get + { + PageFetcher.Page page = GetCurrentPage(); + if (page != null) + { + IList items = page.Items; + if (items != null) + { + return items.Count; + } + } + return 0; + } + } + + public long TotalNumItems + { + get + { + if (totalNumItems == null) + { + totalNumItems = -1; + PageFetcher.Page page = GetCurrentPage(); + if (page != null) + { + totalNumItems = page.TotalNumItems; + } + } + return (long)totalNumItems; + } + } + + public bool HasMoreItems + { + get + { + if (hasMoreItems == null) + { + hasMoreItems = false; + PageFetcher.Page page = GetCurrentPage(); + if (page != null) + { + if (page.HasMoreItems.HasValue) + { + hasMoreItems = page.HasMoreItems; + } + } + } + return (bool)hasMoreItems; + } + } + + protected int IncrementSkipOffset() + { + return SkipOffset++; + } + + protected PageFetcher.Page GetCurrentPage() + { + if (page == null) + { + page = pageFetcher.FetchNextPage(SkipCount); + } + return page; + } + + protected PageFetcher.Page IncrementPage() + { + SkipCount += SkipOffset; + SkipOffset = 0; + totalNumItems = null; + hasMoreItems = null; + page = pageFetcher.FetchNextPage(SkipCount); + return page; + } + } + + /// + /// Page fetcher. + /// + public class PageFetcher + { + public delegate Page FetchPage(long maxNumItems, long skipCount); + + private FetchPage fetchPageDelegate; + + public PageFetcher(long maxNumItems, FetchPage fetchPageDelegate) + { + MaxNumItems = maxNumItems; + this.fetchPageDelegate = fetchPageDelegate; + } + + public long MaxNumItems { get; set; } + + public Page FetchNextPage(long skipCount) + { + return fetchPageDelegate(MaxNumItems, skipCount); + } + + public class Page

+ { + public Page(IList

items, long? totalNumItems, bool? hasMoreItems) + { + Items = items; + TotalNumItems = totalNumItems; + HasMoreItems = hasMoreItems; + } + + public IList

Items { get; private set; } + public long? TotalNumItems { get; private set; } + public bool? HasMoreItems { get; private set; } + } + } + + ///

+ /// CMIS Collection Enumerable. + /// + public class CollectionEnumerable : AbstractEnumerable + { + public CollectionEnumerable(PageFetcher pageFetcher) : + this(0, pageFetcher) { } + + public CollectionEnumerable(long position, PageFetcher pageFetcher) : + base(position, pageFetcher) { } + + protected override AbstractEnumerator CreateEnumerator() + { + return new CollectionEnumerator(SkipCount, PageFetcher); + } + } + + /// + /// Enumerator for iterating over all items in a CMIS Collection. + /// + public class CollectionEnumerator : AbstractEnumerator + { + public CollectionEnumerator(long skipCount, PageFetcher pageFetcher) : + base(skipCount, pageFetcher) { } + + public override bool MoveNext() + { + PageFetcher.Page page = GetCurrentPage(); + if (page == null) + { + return false; + } + + IList items = page.Items; + if (items == null || items.Count == 0) + { + return false; + } + + if (SkipOffset == items.Count) + { + page = IncrementPage(); + items = page == null ? null : page.Items; + } + + if (items == null || items.Count == 0 || SkipOffset == items.Count) + { + return false; + } + + current = items[IncrementSkipOffset()]; + + return true; + } + } + + /// + /// Enumerable for a CMIS Collection Page. + /// + public class CollectionPageEnumerable : AbstractEnumerable + { + public CollectionPageEnumerable(PageFetcher pageFetcher) : + this(0, pageFetcher) { } + + public CollectionPageEnumerable(long position, PageFetcher pageFetcher) : + base(position, pageFetcher) { } + + protected override AbstractEnumerator CreateEnumerator() + { + return new CollectionPageEnumerator(SkipCount, PageFetcher); + } + } + + /// + /// Enumerator for iterating over a page of items in a CMIS Collection. + /// + public class CollectionPageEnumerator : AbstractEnumerator + { + public CollectionPageEnumerator(long skipCount, PageFetcher pageFetcher) : + base(skipCount, pageFetcher) { } + + public override bool MoveNext() + { + PageFetcher.Page page = GetCurrentPage(); + if (page == null) + { + return false; + } + + IList items = page.Items; + if (items == null || items.Count == 0 || SkipOffset == items.Count) + { + return false; + } + + current = items[IncrementSkipOffset()]; + + return true; + } + } +} Modified: incubator/chemistry/dotcmis/trunk/DotCMISUnitTest/DotCMISUnitTest.csproj URL: http://svn.apache.org/viewvc/incubator/chemistry/dotcmis/trunk/DotCMISUnitTest/DotCMISUnitTest.csproj?rev=1065064&r1=1065063&r2=1065064&view=diff ============================================================================== --- incubator/chemistry/dotcmis/trunk/DotCMISUnitTest/DotCMISUnitTest.csproj (original) +++ incubator/chemistry/dotcmis/trunk/DotCMISUnitTest/DotCMISUnitTest.csproj Sat Jan 29 16:41:19 2011 @@ -44,7 +44,9 @@ + + Modified: incubator/chemistry/dotcmis/trunk/DotCMISUnitTest/DotCMISUnitTest.csproj.user URL: http://svn.apache.org/viewvc/incubator/chemistry/dotcmis/trunk/DotCMISUnitTest/DotCMISUnitTest.csproj.user?rev=1065064&r1=1065063&r2=1065064&view=diff ============================================================================== --- incubator/chemistry/dotcmis/trunk/DotCMISUnitTest/DotCMISUnitTest.csproj.user (original) +++ incubator/chemistry/dotcmis/trunk/DotCMISUnitTest/DotCMISUnitTest.csproj.user Sat Jan 29 16:41:19 2011 @@ -3,7 +3,7 @@ Program C:\Program Files (x86)\NUnit 2.5.9\bin\net-2.0\nunit-console.exe - C:\projects\opencmis\DotCMIS\DotCMISUnitTest\bin\Debug\DotCMISUnitTest.dll - C:\projects\opencmis\DotCMIS\DotCMISUnitTest\bin\Debug + C:\projects\chemistry\dotcmis\trunk\DotCMISUnitTest\bin\Debug\DotCMISUnitTest.dll + C:\projects\chemistry\dotcmis\trunk\DotCMISUnitTest\bin\Debug\ \ No newline at end of file Added: incubator/chemistry/dotcmis/trunk/DotCMISUnitTest/EnumeratorTest.cs URL: http://svn.apache.org/viewvc/incubator/chemistry/dotcmis/trunk/DotCMISUnitTest/EnumeratorTest.cs?rev=1065064&view=auto ============================================================================== --- incubator/chemistry/dotcmis/trunk/DotCMISUnitTest/EnumeratorTest.cs (added) +++ incubator/chemistry/dotcmis/trunk/DotCMISUnitTest/EnumeratorTest.cs Sat Jan 29 16:41:19 2011 @@ -0,0 +1,133 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +using System.Collections.Generic; +using DotCMIS.Client; +using NUnit.Framework; + +namespace DotCMISUnitTest +{ + [TestFixture] + class EnumeratorTest + { + private const int PageSize = 12; + + private IList source; + private IItemEnumerable testEnumerable; + + [SetUp] + public void Init() + { + source = new List(); + for (int i = 0; i < 100; i++) + { + source.Add(i); + } + + PageFetcher.FetchPage fetchPageDelegate = delegate(long maxNumItems, long skipCount) + { + IList page = new List(); + + for (int i = (int)skipCount; i < skipCount + maxNumItems; i++) + { + if (source.Count <= i) { break; } + page.Add(source[i]); + } + + return new PageFetcher.Page(page, source.Count, skipCount + maxNumItems < source.Count); + }; + + testEnumerable = new CollectionEnumerable(new PageFetcher(PageSize, fetchPageDelegate)); + } + + [Test] + public void TestIteration() + { + Assert.AreEqual(source.Count, testEnumerable.TotalNumItems); + Assert.AreEqual(PageSize, testEnumerable.PageNumItems); + + int i = 0; + foreach (int x in testEnumerable) + { + Assert.AreEqual(i, x); + i++; + } + } + + [Test] + public void TestSkip() + { + int i = 42; + foreach (int x in testEnumerable.SkipTo(42)) + { + Assert.AreEqual(i, x); + i++; + } + + Assert.AreEqual(source.Count, i); + } + + [Test] + public void TestOverSkip() + { + foreach (int x in testEnumerable.SkipTo(source.Count + 1)) + { + Assert.Fail(); + } + } + + [Test] + public void TestPage() + { + int i = 0; + foreach (int x in testEnumerable.GetPage(8)) + { + Assert.AreEqual(i, x); + i++; + } + + Assert.AreEqual(8, i); + } + + [Test] + public void TestBigPage() + { + int i = 0; + foreach (int x in testEnumerable.GetPage(source.Count * 2)) + { + Assert.AreEqual(i, x); + i++; + } + + Assert.AreEqual(source.Count, i); + } + + [Test] + public void TestSkipAndPage() + { + int i = 42; + foreach (int x in testEnumerable.SkipTo(42).GetPage(20)) + { + Assert.AreEqual(i, x); + i++; + } + + Assert.AreEqual(62, i); + } + } +} Added: incubator/chemistry/dotcmis/trunk/DotCMISUnitTest/SmokeTest.cs URL: http://svn.apache.org/viewvc/incubator/chemistry/dotcmis/trunk/DotCMISUnitTest/SmokeTest.cs?rev=1065064&view=auto ============================================================================== --- incubator/chemistry/dotcmis/trunk/DotCMISUnitTest/SmokeTest.cs (added) +++ incubator/chemistry/dotcmis/trunk/DotCMISUnitTest/SmokeTest.cs Sat Jan 29 16:41:19 2011 @@ -0,0 +1,129 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using NUnit.Framework; +using DotCMIS.Client; +using DotCMIS.Enums; + +namespace DotCMISUnitTest +{ + [TestFixture] + class SmokeTest : TestFramework + { + [Test] + public void TestSession() + { + Assert.NotNull(Session); + Assert.NotNull(Session.Binding); + Assert.NotNull(Session.RepositoryInfo); + Assert.NotNull(Session.RepositoryInfo.Id); + Assert.NotNull(Session.RepositoryInfo.RootFolderId); + Assert.NotNull(Session.DefaultContext); + Assert.NotNull(Session.ObjectFactory); + + Assert.AreEqual("test", Session.CreateObjectId("test").Id); + } + + [Test] + public void SmokeTestTypes() + { + // getTypeDefinition + IObjectType documentType = Session.GetTypeDefinition("cmis:document"); + Assert.NotNull(documentType); + Assert.True(documentType is DocumentType); + Assert.AreEqual("cmis:document", documentType.Id); + Assert.AreEqual(BaseTypeId.CmisDocument, documentType.BaseTypeId); + Assert.True(documentType.IsBaseType); + Assert.Null(documentType.ParentTypeId); + Assert.NotNull(documentType.PropertyDefintions); + Assert.True(documentType.PropertyDefintions.Count >= 9); + + IObjectType folderType = Session.GetTypeDefinition("cmis:folder"); + Assert.NotNull(folderType); + Assert.True(folderType is FolderType); + Assert.AreEqual("cmis:folder", folderType.Id); + Assert.AreEqual(BaseTypeId.CmisFolder, folderType.BaseTypeId); + Assert.True(folderType.IsBaseType); + Assert.Null(folderType.ParentTypeId); + Assert.NotNull(folderType.PropertyDefintions); + Assert.True(folderType.PropertyDefintions.Count >= 9); + + // getTypeChildren + Session.Clear(); + + IItemEnumerable children = Session.GetTypeChildren(null, true); + Assert.NotNull(children); + + int count; + count = 0; + foreach (IObjectType type in children) + { + Assert.NotNull(type); + Assert.NotNull(type.Id); + Assert.True(type.IsBaseType); + Assert.Null(type.ParentTypeId); + Assert.NotNull(type.PropertyDefintions); + + Session.Clear(); + IObjectType type2 = Session.GetTypeDefinition(type.Id); + AssertAreEqual(type, type2); + + Session.GetTypeChildren(type.Id, true); + + count++; + } + + Assert.True(count >= 2); + Assert.True(count <= 4); + + // getTypeDescendants + Session.Clear(); + + IList> descendants = Session.GetTypeDescendants(null, -1, true); + + count = 0; + foreach (ITree tree in descendants) + { + Assert.NotNull(tree); + Assert.NotNull(tree.Item); + + IObjectType type = tree.Item; + Assert.NotNull(type); + Assert.NotNull(type.Id); + Assert.True(type.IsBaseType); + Assert.Null(type.ParentTypeId); + Assert.NotNull(type.PropertyDefintions); + + Session.Clear(); + IObjectType type2 = Session.GetTypeDefinition(type.Id); + AssertAreEqual(type, type2); + + Session.GetTypeDescendants(type.Id, 2, true); + + count++; + } + + Assert.True(count >= 2); + Assert.True(count <= 4); + } + } +} Modified: incubator/chemistry/dotcmis/trunk/DotCMISUnitTest/TestFramework.cs URL: http://svn.apache.org/viewvc/incubator/chemistry/dotcmis/trunk/DotCMISUnitTest/TestFramework.cs?rev=1065064&r1=1065063&r2=1065064&view=diff ============================================================================== --- incubator/chemistry/dotcmis/trunk/DotCMISUnitTest/TestFramework.cs (original) +++ incubator/chemistry/dotcmis/trunk/DotCMISUnitTest/TestFramework.cs Sat Jan 29 16:41:19 2011 @@ -26,6 +26,7 @@ using DotCMIS.Data; using DotCMIS.Enums; using DotCMIS.Exceptions; using NUnit.Framework; +using DotCMIS.Client; namespace DotCMISUnitTest { @@ -33,7 +34,8 @@ namespace DotCMISUnitTest { private IRepositoryInfo repositoryInfo; - public ICmisBinding Binding { get; set; } + public ISession Session { get; set; } + public ICmisBinding Binding { get { return Session.Binding; } } public IRepositoryInfo RepositoryInfo { get @@ -59,51 +61,59 @@ namespace DotCMISUnitTest DefaultDocumentType = "cmis:document"; DefaultFolderType = "cmis:folder"; - Binding = ConnectAtomPub(); + Session = ConnectAtomPub(); } - public ICmisBinding ConnectAtomPub() + public ISession ConnectAtomPub() { - Dictionary parametersAtom = new Dictionary(); + Dictionary parameters = new Dictionary(); - string baseUrlAtom = "http://localhost:8080/alfresco/opencmis-atom"; + string baseUrlAtom = "http://localhost:8080/alfresco/service/cmis"; - parametersAtom[SessionParameter.AtomPubUrl] = baseUrlAtom; - parametersAtom[SessionParameter.User] = "admin"; - parametersAtom[SessionParameter.Password] = "admin"; + parameters[SessionParameter.BindingType] = BindingType.AtomPub; + parameters[SessionParameter.AtomPubUrl] = baseUrlAtom; + parameters[SessionParameter.User] = "admin"; + parameters[SessionParameter.Password] = "admin"; - CmisBindingFactory factory = CmisBindingFactory.NewInstance(); - ICmisBinding binding = factory.CreateCmisAtomPubBinding(parametersAtom); + SessionFactory factory = SessionFactory.NewInstance(); + ISession session = factory.GetRepositories(parameters)[0].CreateSession(); - Assert.NotNull(binding); + Assert.NotNull(session); + Assert.NotNull(session.Binding); + Assert.NotNull(session.RepositoryInfo); + Assert.NotNull(session.RepositoryInfo.Id); - return binding; + return session; } - public ICmisBinding ConnectWebServices() + public ISession ConnectWebServices() { - Dictionary parametersWS = new Dictionary(); + Dictionary parameters = new Dictionary(); - string baseUrlWS = "https://localhost:8443/alfresco/opencmis-ws"; + string baseUrlWS = "http://localhost:8080/alfresco/cmis"; - parametersWS[SessionParameter.WebServicesRepositoryService] = baseUrlWS + "/RepositoryService?wsdl"; - parametersWS[SessionParameter.WebServicesAclService] = baseUrlWS + "/AclService?wsdl"; - parametersWS[SessionParameter.WebServicesDiscoveryService] = baseUrlWS + "/DiscoveryService?wsdl"; - parametersWS[SessionParameter.WebServicesMultifilingService] = baseUrlWS + "/MultifilingService?wsdl"; - parametersWS[SessionParameter.WebServicesNavigationService] = baseUrlWS + "/NavigationService?wsdl"; - parametersWS[SessionParameter.WebServicesObjectService] = baseUrlWS + "/ObjectService?wsdl"; - parametersWS[SessionParameter.WebServicesPolicyService] = baseUrlWS + "/PolicyService?wsdl"; - parametersWS[SessionParameter.WebServicesRelationshipService] = baseUrlWS + "/RelationshipService?wsdl"; - parametersWS[SessionParameter.WebServicesVersioningService] = baseUrlWS + "/VersioningService?wsdl"; - parametersWS[SessionParameter.User] = "admin"; - parametersWS[SessionParameter.Password] = "admin"; + parameters[SessionParameter.BindingType] = BindingType.WebServices; + parameters[SessionParameter.WebServicesRepositoryService] = baseUrlWS + "/RepositoryService?wsdl"; + parameters[SessionParameter.WebServicesAclService] = baseUrlWS + "/AclService?wsdl"; + parameters[SessionParameter.WebServicesDiscoveryService] = baseUrlWS + "/DiscoveryService?wsdl"; + parameters[SessionParameter.WebServicesMultifilingService] = baseUrlWS + "/MultifilingService?wsdl"; + parameters[SessionParameter.WebServicesNavigationService] = baseUrlWS + "/NavigationService?wsdl"; + parameters[SessionParameter.WebServicesObjectService] = baseUrlWS + "/ObjectService?wsdl"; + parameters[SessionParameter.WebServicesPolicyService] = baseUrlWS + "/PolicyService?wsdl"; + parameters[SessionParameter.WebServicesRelationshipService] = baseUrlWS + "/RelationshipService?wsdl"; + parameters[SessionParameter.WebServicesVersioningService] = baseUrlWS + "/VersioningService?wsdl"; + parameters[SessionParameter.User] = "admin"; + parameters[SessionParameter.Password] = "admin"; + + SessionFactory factory = SessionFactory.NewInstance(); + ISession session = factory.GetRepositories(parameters)[0].CreateSession(); + + Assert.NotNull(session); + Assert.NotNull(session.Binding); + Assert.NotNull(session.RepositoryInfo); + Assert.NotNull(session.RepositoryInfo.Id); - CmisBindingFactory factory = CmisBindingFactory.NewInstance(); - ICmisBinding binding = factory.CreateCmisWebServicesBinding(parametersWS); - - Assert.NotNull(binding); - - return binding; + return session; } public IObjectData GetFullObject(string objectId) @@ -311,5 +321,28 @@ namespace DotCMISUnitTest return result; } + + // ---- asserts ---- + + public void AssertAreEqual(IObjectType expected, IObjectType actual) + { + if (expected == null && actual == null) + { + return; + } + + Assert.NotNull(expected); + Assert.NotNull(actual); + + Assert.AreEqual(expected.Id, actual.Id); + Assert.AreEqual(expected.IsBaseType, actual.IsBaseType); + Assert.AreEqual(expected.BaseTypeId, actual.BaseTypeId); + Assert.AreEqual(expected.DisplayName, actual.DisplayName); + Assert.AreEqual(expected.Description, actual.Description); + Assert.AreEqual(expected.LocalName, actual.LocalName); + Assert.AreEqual(expected.LocalNamespace, actual.LocalNamespace); + Assert.AreEqual(expected.QueryName, actual.QueryName); + Assert.AreEqual(expected.PropertyDefintions.Count, actual.PropertyDefintions.Count); + } } }