Return-Path: Delivered-To: apmail-incubator-chemistry-commits-archive@minotaur.apache.org Received: (qmail 58147 invoked from network); 5 Feb 2011 16:28:06 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 5 Feb 2011 16:28:06 -0000 Received: (qmail 75268 invoked by uid 500); 5 Feb 2011 16:28:06 -0000 Delivered-To: apmail-incubator-chemistry-commits-archive@incubator.apache.org Received: (qmail 75222 invoked by uid 500); 5 Feb 2011 16:28:04 -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 75214 invoked by uid 99); 5 Feb 2011 16:28:02 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 05 Feb 2011 16:28:02 +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, 05 Feb 2011 16:27:55 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 68936238890A; Sat, 5 Feb 2011 16:27:32 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1067465 [1/2] - in /incubator/chemistry/dotcmis/trunk: DotCMIS/ DotCMIS/binding/ DotCMIS/binding/atompub/ DotCMIS/binding/webservices/ DotCMIS/client/ DotCMIS/data/ DotCMISUnitTest/ Date: Sat, 05 Feb 2011 16:27:32 -0000 To: chemistry-commits@incubator.apache.org From: fmui@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110205162732.68936238890A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: fmui Date: Sat Feb 5 16:27:31 2011 New Revision: 1067465 URL: http://svn.apache.org/viewvc?rev=1067465&view=rev Log: added CmisObject implementations Modified: incubator/chemistry/dotcmis/trunk/DotCMIS/binding/atompub/atompub.cs incubator/chemistry/dotcmis/trunk/DotCMIS/binding/binding-impl.cs incubator/chemistry/dotcmis/trunk/DotCMIS/binding/binding-intf.cs incubator/chemistry/dotcmis/trunk/DotCMIS/binding/converter.cs incubator/chemistry/dotcmis/trunk/DotCMIS/binding/services.cs incubator/chemistry/dotcmis/trunk/DotCMIS/binding/webservices/webservices.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-objectfactory.cs incubator/chemistry/dotcmis/trunk/DotCMIS/client/client-objects.cs incubator/chemistry/dotcmis/trunk/DotCMIS/client/client-types.cs incubator/chemistry/dotcmis/trunk/DotCMIS/const.cs incubator/chemistry/dotcmis/trunk/DotCMIS/data/data-impl.cs incubator/chemistry/dotcmis/trunk/DotCMIS/data/data-intf.cs incubator/chemistry/dotcmis/trunk/DotCMISUnitTest/TestFramework.cs Modified: incubator/chemistry/dotcmis/trunk/DotCMIS/binding/atompub/atompub.cs URL: http://svn.apache.org/viewvc/incubator/chemistry/dotcmis/trunk/DotCMIS/binding/atompub/atompub.cs?rev=1067465&r1=1067464&r2=1067465&view=diff ============================================================================== --- incubator/chemistry/dotcmis/trunk/DotCMIS/binding/atompub/atompub.cs (original) +++ incubator/chemistry/dotcmis/trunk/DotCMIS/binding/atompub/atompub.cs Sat Feb 5 16:27:31 2011 @@ -113,7 +113,7 @@ namespace DotCMIS.Binding.AtomPub // nothing to do } - public void Close() + public void Dispose() { // nothing to do } @@ -2118,7 +2118,7 @@ namespace DotCMIS.Binding.AtomPub } public void CheckIn(string repositoryId, ref string objectId, bool? major, IProperties properties, - IContentStream contentStream, string checkinComment, List policies, IAcl addAces, IAcl removeAces, + IContentStream contentStream, string checkinComment, IList policies, IAcl addAces, IAcl removeAces, IExtensionsData extension) { // we need an object id Modified: incubator/chemistry/dotcmis/trunk/DotCMIS/binding/binding-impl.cs URL: http://svn.apache.org/viewvc/incubator/chemistry/dotcmis/trunk/DotCMIS/binding/binding-impl.cs?rev=1067465&r1=1067464&r2=1067465&view=diff ============================================================================== --- incubator/chemistry/dotcmis/trunk/DotCMIS/binding/binding-impl.cs (original) +++ incubator/chemistry/dotcmis/trunk/DotCMIS/binding/binding-impl.cs Sat Feb 5 16:27:31 2011 @@ -35,7 +35,6 @@ namespace DotCMIS.Binding.Impl internal class CmisBinding : ICmisBinding { private BindingSession session; - private BindingsObjectFactory objectFactory; private BindingRepositoryService repositoryServiceWrapper; public CmisBinding(IDictionary sessionParameters) @@ -57,9 +56,6 @@ namespace DotCMIS.Binding.Impl session.PutValue(key, sessionParameters[key]); } - // set up object factory - objectFactory = new BindingsObjectFactory(); - // set up authentication provider string authenticationProviderClass; if (sessionParameters.TryGetValue(SessionParameter.AuthenticationProviderClass, out authenticationProviderClass)) @@ -149,11 +145,6 @@ namespace DotCMIS.Binding.Impl return spi.GetPolicyService(); } - public IBindingsObjectFactory GetObjectFactory() - { - return objectFactory; - } - public void ClearAllCaches() { CheckSession(); @@ -200,14 +191,14 @@ namespace DotCMIS.Binding.Impl } } - public void Close() + public void Dispose() { CheckSession(); session.Lock(); try { - GetSpi().Close(); + GetSpi().Dispose(); } finally { @@ -564,41 +555,21 @@ namespace DotCMIS.Binding.Impl } /// - /// Object factory implementation. - /// - internal class BindingsObjectFactory : IBindingsObjectFactory - { - } - - /// /// SPI interface. /// - internal interface ICmisSpi + internal interface ICmisSpi : IDisposable { void initialize(BindingSession session); - IRepositoryService GetRepositoryService(); - INavigationService GetNavigationService(); - IObjectService GetObjectService(); - IVersioningService GetVersioningService(); - IRelationshipService GetRelationshipService(); - IDiscoveryService GetDiscoveryService(); - IMultiFilingService GetMultiFilingService(); - IAclService GetAclService(); - IPolicyService GetPolicyService(); - void ClearAllCaches(); - void ClearRepositoryCache(string repositoryId); - - void Close(); } } Modified: incubator/chemistry/dotcmis/trunk/DotCMIS/binding/binding-intf.cs URL: http://svn.apache.org/viewvc/incubator/chemistry/dotcmis/trunk/DotCMIS/binding/binding-intf.cs?rev=1067465&r1=1067464&r2=1067465&view=diff ============================================================================== --- incubator/chemistry/dotcmis/trunk/DotCMIS/binding/binding-intf.cs (original) +++ incubator/chemistry/dotcmis/trunk/DotCMIS/binding/binding-intf.cs Sat Feb 5 16:27:31 2011 @@ -18,16 +18,14 @@ */ using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using DotCMIS.Binding.Services; +using System.Net; using DotCMIS.Binding.Impl; +using DotCMIS.Binding.Services; using DotCMIS.CMISWebServicesReference; -using System.Net; namespace DotCMIS.Binding { - public interface ICmisBinding + public interface ICmisBinding : IDisposable { IRepositoryService GetRepositoryService(); INavigationService GetNavigationService(); @@ -38,10 +36,8 @@ namespace DotCMIS.Binding IMultiFilingService GetMultiFilingService(); IAclService GetAclService(); IPolicyService GetPolicyService(); - IBindingsObjectFactory GetObjectFactory(); void ClearAllCaches(); void ClearRepositoryCache(string repositoryId); - void Close(); } public interface IBindingSession @@ -131,11 +127,6 @@ namespace DotCMIS.Binding } } - - public interface IBindingsObjectFactory - { - } - public class CmisBindingFactory { // Default CMIS AtomPub binding SPI implementation Modified: incubator/chemistry/dotcmis/trunk/DotCMIS/binding/converter.cs URL: http://svn.apache.org/viewvc/incubator/chemistry/dotcmis/trunk/DotCMIS/binding/converter.cs?rev=1067465&r1=1067464&r2=1067465&view=diff ============================================================================== --- incubator/chemistry/dotcmis/trunk/DotCMIS/binding/converter.cs (original) +++ incubator/chemistry/dotcmis/trunk/DotCMIS/binding/converter.cs Sat Feb 5 16:27:31 2011 @@ -424,9 +424,9 @@ namespace DotCMIS.Binding result.DisplayName = propDef.displayName; result.QueryName = propDef.queryName; result.Description = propDef.description; - result.PropertyType = (PropertyType?)CmisValue.SerializerToCmisEnum(propDef.propertyType); - result.Cardinality = (Cardinality?)CmisValue.SerializerToCmisEnum(propDef.cardinality); - result.Updatability = (Updatability?)CmisValue.SerializerToCmisEnum(propDef.updatability); + result.PropertyType = (PropertyType)CmisValue.SerializerToCmisEnum(propDef.propertyType); + result.Cardinality = (Cardinality)CmisValue.SerializerToCmisEnum(propDef.cardinality); + result.Updatability = (Updatability)CmisValue.SerializerToCmisEnum(propDef.updatability); result.IsInherited = (propDef.inheritedSpecified ? (bool?)propDef.inherited : null); result.IsRequired = propDef.required; result.IsQueryable = propDef.queryable; @@ -702,7 +702,7 @@ namespace DotCMIS.Binding { if (property == null) { return null; } - PropertyData result = null; + AbstractPropertyData result = null; if (property is cmisPropertyString) { result = new PropertyString(); Modified: incubator/chemistry/dotcmis/trunk/DotCMIS/binding/services.cs URL: http://svn.apache.org/viewvc/incubator/chemistry/dotcmis/trunk/DotCMIS/binding/services.cs?rev=1067465&r1=1067464&r2=1067465&view=diff ============================================================================== --- incubator/chemistry/dotcmis/trunk/DotCMIS/binding/services.cs (original) +++ incubator/chemistry/dotcmis/trunk/DotCMIS/binding/services.cs Sat Feb 5 16:27:31 2011 @@ -123,7 +123,7 @@ namespace DotCMIS.Binding.Services void CancelCheckOut(string repositoryId, string objectId, IExtensionsData extension); void CheckIn(string repositoryId, ref string objectId, bool? major, IProperties properties, - IContentStream contentStream, string checkinComment, List policies, IAcl addAces, IAcl removeAces, + IContentStream contentStream, string checkinComment, IList policies, IAcl addAces, IAcl removeAces, IExtensionsData extension); IObjectData GetObjectOfLatestVersion(string repositoryId, string objectId, string versionSeriesId, bool major, Modified: incubator/chemistry/dotcmis/trunk/DotCMIS/binding/webservices/webservices.cs URL: http://svn.apache.org/viewvc/incubator/chemistry/dotcmis/trunk/DotCMIS/binding/webservices/webservices.cs?rev=1067465&r1=1067464&r2=1067465&view=diff ============================================================================== --- incubator/chemistry/dotcmis/trunk/DotCMIS/binding/webservices/webservices.cs (original) +++ incubator/chemistry/dotcmis/trunk/DotCMIS/binding/webservices/webservices.cs Sat Feb 5 16:27:31 2011 @@ -114,7 +114,7 @@ namespace DotCMIS.Binding.WebServices // nothing to do } - public void Close() + public void Dispose() { // nothing to do } @@ -1110,7 +1110,7 @@ namespace DotCMIS.Binding.WebServices } public void CheckIn(string repositoryId, ref string objectId, bool? major, IProperties properties, - IContentStream contentStream, string checkinComment, List policies, IAcl addAces, IAcl removeAces, + IContentStream contentStream, string checkinComment, IList policies, IAcl addAces, IAcl removeAces, IExtensionsData extension) { VersioningServicePortClient port = Provider.GetVersioningService(); 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=1067465&r1=1067464&r2=1067465&view=diff ============================================================================== --- incubator/chemistry/dotcmis/trunk/DotCMIS/client/client-impl.cs (original) +++ incubator/chemistry/dotcmis/trunk/DotCMIS/client/client-impl.cs Sat Feb 5 16:27:31 2011 @@ -243,15 +243,15 @@ namespace DotCMIS.Client cacheType = typeof(NoCache); } - object cacheObject = Activator.CreateInstance(cacheType); - if (!(cacheObject is ICache)) + ICache cacheObject = Activator.CreateInstance(cacheType) as ICache; + if (cacheObject == null) { throw new Exception("Class does not implement ICache!"); } - ((ICache)cacheObject).Initialize(this, parameters); + cacheObject.Initialize(this, parameters); - return (ICache)cacheObject; + return cacheObject; } catch (Exception e) { @@ -275,15 +275,15 @@ namespace DotCMIS.Client ofType = typeof(ObjectFactory); } - object ofObject = Activator.CreateInstance(ofType); - if (!(ofObject is IObjectFactory)) + IObjectFactory ofObject = Activator.CreateInstance(ofType) as IObjectFactory; + if (ofObject == null) { throw new Exception("Class does not implement IObjectFactory!"); } - ((IObjectFactory)ofObject).Initialize(this, parameters); + ofObject.Initialize(this, parameters); - return (IObjectFactory)ofObject; + return ofObject; } catch (Exception e) { @@ -335,12 +335,12 @@ namespace DotCMIS.Client public IItemEnumerable GetTypeChildren(string typeId, bool includePropertyDefinitions) { - IRepositoryService repositoryService = Binding.GetRepositoryService(); + IRepositoryService service = Binding.GetRepositoryService(); PageFetcher.FetchPage fetchPageDelegate = delegate(long maxNumItems, long skipCount) { // fetch the data - ITypeDefinitionList tdl = repositoryService.GetTypeChildren(RepositoryId, typeId, includePropertyDefinitions, maxNumItems, skipCount, null); + ITypeDefinitionList tdl = service.GetTypeChildren(RepositoryId, typeId, includePropertyDefinitions, maxNumItems, skipCount, null); // convert type definitions IList page = new List(tdl.List.Count); @@ -388,13 +388,13 @@ namespace DotCMIS.Client public IFolder GetRootFolder(IOperationContext context) { - ICmisObject rootFolder = GetObject(CreateObjectId(RepositoryInfo.RootFolderId), context); - if (!(rootFolder is IFolder)) + IFolder rootFolder = GetObject(CreateObjectId(RepositoryInfo.RootFolderId), context) as IFolder; + if (rootFolder == null) { throw new CmisRuntimeException("Root folder object is not a folder!"); } - return (IFolder)rootFolder; + return rootFolder; } public IItemEnumerable GetCheckedOutDocs() 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=1067465&r1=1067464&r2=1067465&view=diff ============================================================================== --- incubator/chemistry/dotcmis/trunk/DotCMIS/client/client-intf.cs (original) +++ incubator/chemistry/dotcmis/trunk/DotCMIS/client/client-intf.cs Sat Feb 5 16:27:31 2011 @@ -120,7 +120,7 @@ namespace DotCMIS.Client // ACL and ACE IAcl ConvertAces(IList aces); IAcl CreateAcl(IList aces); - IAce CreateAce(string principal, List permissions); + IAce CreateAce(string principal, IList permissions); // policies IList ConvertPolicies(IList policies); @@ -130,14 +130,13 @@ namespace DotCMIS.Client // content stream IContentStream CreateContentStream(string filename, long length, string mimetype, Stream stream); - IContentStream ConvertContentStream(IContentStream contentStream); // types IObjectType ConvertTypeDefinition(ITypeDefinition typeDefinition); IObjectType GetTypeFromObjectData(IObjectData objectData); // properties - IProperty CreateProperty(IPropertyDefinition type, IList values); + IProperty CreateProperty(IPropertyDefinition type, IList values); IDictionary ConvertProperties(IObjectType objectType, IProperties properties); IProperties ConvertProperties(IDictionary properties, IObjectType type, HashSet updatabilityFilter); IList ConvertQueryProperties(IProperties properties); @@ -223,12 +222,18 @@ namespace DotCMIS.Client IContentStream GetContentStream(); } - public interface IProperty : IPropertyData + public interface IProperty { + string Id { get; } + string LocalName { get; } + string DisplayName { get; } + string QueryName { get; } bool IsMultiValued { get; } - PropertyType PropertyType { get; } - PropertyDefinition PropertyDefinition { get; } + PropertyType? PropertyType { get; } + IPropertyDefinition PropertyDefinition { get; } object Value { get; } + IList Values { get; } + object FirstValue { get; } string ValueAsString { get; } string ValuesAsString { get; } } @@ -296,8 +301,8 @@ namespace DotCMIS.Client IFileableCmisObject Move(IObjectId sourceFolderId, IObjectId targetFolderId); // navigation service - IList GetParents(); - IList GetPaths(); + IList Parents { get; } + IList Paths { get; } // multifiling service void AddToFolder(IObjectId folderId, bool allVersions); @@ -312,11 +317,11 @@ namespace DotCMIS.Client bool? IsLatestMajorVersion { get; } string VersionLabel { get; } string VersionSeriesId { get; } - bool? VersionSeriesCheckedOut { get; } + bool? IsVersionSeriesCheckedOut { get; } string VersionSeriesCheckedOutBy { get; } string VersionSeriesCheckedOutId { get; } string CheckinComment { get; } - long ContentStreamLength { get; } + long? ContentStreamLength { get; } string ContentStreamMimeType { get; } string ContentStreamFileName { get; } string ContentStreamId { get; } @@ -335,7 +340,7 @@ namespace DotCMIS.Client void CancelCheckOut(); IObjectId CheckIn(bool major, IDictionary properties, IContentStream contentStream, string checkinComment, IList policies, IList addAces, IList removeAces); - IObjectId checkIn(bool major, IDictionary properties, IContentStream contentStream, string checkinComment); + IObjectId CheckIn(bool major, IDictionary properties, IContentStream contentStream, string checkinComment); IDocument GetObjectOfLatestVersion(bool major); IDocument GetObjectOfLatestVersion(bool major, IOperationContext context); IList GetAllVersions(); @@ -361,7 +366,7 @@ namespace DotCMIS.Client IFolder CreateFolder(IDictionary properties, IList policies, IList addAces, IList removeAces, IOperationContext context); IFolder CreateFolder(IDictionary properties); - IPolicy CreatePolicy(IDictionary properties, List policies, IList addAces, IList removeAces, + IPolicy CreatePolicy(IDictionary properties, IList policies, IList addAces, IList removeAces, IOperationContext context); IPolicy CreatePolicy(IDictionary properties); IList DeleteTree(bool allversions, UnfileObject? unfile, bool continueOnFailure); Modified: incubator/chemistry/dotcmis/trunk/DotCMIS/client/client-objectfactory.cs URL: http://svn.apache.org/viewvc/incubator/chemistry/dotcmis/trunk/DotCMIS/client/client-objectfactory.cs?rev=1067465&r1=1067464&r2=1067465&view=diff ============================================================================== --- incubator/chemistry/dotcmis/trunk/DotCMIS/client/client-objectfactory.cs (original) +++ incubator/chemistry/dotcmis/trunk/DotCMIS/client/client-objectfactory.cs Sat Feb 5 16:27:31 2011 @@ -24,6 +24,7 @@ using DotCMIS.Data; using System.IO; using DotCMIS.Enums; using DotCMIS.Exceptions; +using System.Collections; namespace DotCMIS.Client { @@ -37,55 +38,469 @@ namespace DotCMIS.Client } // ACL and ACE - public IAcl ConvertAces(IList aces) { return null; } - public IAcl CreateAcl(IList aces) { return null; } - public IAce CreateAce(string principal, List permissions) { return null; } + public IAcl ConvertAces(IList aces) + { + if (aces == null) { return null; } + + Acl result = new Acl(); + result.Aces = new List(); + + foreach (IAce ace in aces) + { + result.Aces.Add(ace); + } + + return result; + } + + public IAcl CreateAcl(IList aces) + { + Acl acl = new Acl(); + acl.Aces = aces; + + return acl; + } + + public IAce CreateAce(string principal, IList permissions) + { + Ace ace = new Ace(); + Principal acePrincipal = new Principal(); + acePrincipal.Id = principal; + ace.Principal = acePrincipal; + ace.Permissions = permissions; + + return ace; + } // policies - public IList ConvertPolicies(IList policies) { return null; } + public IList ConvertPolicies(IList policies) + { + if (policies == null) { return null; } + + IList result = new List(); + foreach (IPolicy policy in policies) + { + if (policy != null && policy.Id != null) + { + result.Add(policy.Id); + } + } + + return result; + } // renditions - public IRendition ConvertRendition(string objectId, IRenditionData rendition) { return null; } + public IRendition ConvertRendition(string objectId, IRenditionData rendition) + { + if (rendition == null) + { + throw new ArgumentException("rendition"); + } + + return new Rendition(this.session, objectId, rendition.StreamId, rendition.MimeType, rendition.Length, rendition.Kind, + rendition.Title, rendition.Height, rendition.Height, rendition.RenditionDocumentId); + } // content stream - public IContentStream CreateContentStream(string filename, long length, string mimetype, Stream stream) { return null; } - public IContentStream ConvertContentStream(IContentStream contentStream) { return null; } + public IContentStream CreateContentStream(string filename, long length, string mimetype, Stream stream) + { + ContentStream result = new ContentStream(); + result.FileName = filename; + result.Length = length; + result.MimeType = mimetype; + result.Stream = stream; + + return result; + } // types public IObjectType ConvertTypeDefinition(ITypeDefinition typeDefinition) { - if (typeDefinition is IDocumentTypeDefinition) + switch (typeDefinition.BaseTypeId) { - return new DocumentType(session, (IDocumentTypeDefinition)typeDefinition); + case BaseTypeId.CmisDocument: + return new DocumentType(session, (IDocumentTypeDefinition)typeDefinition); + case BaseTypeId.CmisFolder: + return new FolderType(session, (IFolderTypeDefinition)typeDefinition); + case BaseTypeId.CmisRelationship: + return new RelationshipType(session, (IRelationshipTypeDefinition)typeDefinition); + case BaseTypeId.CmisPolicy: + return new PolicyType(session, (IPolicyTypeDefinition)typeDefinition); + default: + throw new CmisRuntimeException("Unknown base type!"); } - else if (typeDefinition is IFolderTypeDefinition) + } + + public IObjectType GetTypeFromObjectData(IObjectData objectData) + { + if (objectData == null || objectData.Properties == null) { - return new FolderType(session, (IFolderTypeDefinition)typeDefinition); + return null; } - else if (typeDefinition is IRelationshipTypeDefinition) + + IPropertyId typeProperty = objectData.Properties[PropertyIds.ObjectTypeId] as IPropertyId; + if (typeProperty == null) { - return new RelationshipType(session, (IRelationshipTypeDefinition)typeDefinition); + return null; } - else if (typeDefinition is IPolicyTypeDefinition) + + return session.GetTypeDefinition(typeProperty.FirstValue); + } + + // properties + public IProperty CreateProperty(IPropertyDefinition type, IList values) + { + return new Property(type, (IList)values); + } + + protected IProperty ConvertProperty(IObjectType objectType, IPropertyData pd) + { + IPropertyDefinition definition = objectType[pd.Id]; + if (definition == null) { - return new PolicyType(session, (IPolicyTypeDefinition)typeDefinition); + // property without definition + throw new CmisRuntimeException("Property '" + pd.Id + "' doesn't exist!"); } - else + + switch (definition.PropertyType) { - throw new CmisRuntimeException("Unknown base type!"); + case PropertyType.String: + return CreateProperty(definition, ((IPropertyString)pd).Values); + case PropertyType.Id: + return CreateProperty(definition, ((IPropertyId)pd).Values); + case PropertyType.Integer: + return CreateProperty(definition, ((IPropertyInteger)pd).Values); + case PropertyType.Boolean: + return CreateProperty(definition, ((IPropertyBoolean)pd).Values); + case PropertyType.Decimal: + return CreateProperty(definition, ((IPropertyDecimal)pd).Values); + case PropertyType.Uri: + return CreateProperty(definition, ((IPropertyUri)pd).Values); + case PropertyType.Html: + return CreateProperty(definition, ((IPropertyHtml)pd).Values); + default: + return null; } } - public IObjectType GetTypeFromObjectData(IObjectData objectData) { return null; } + public IDictionary ConvertProperties(IObjectType objectType, IProperties properties) + { + if (objectType == null) + { + throw new ArgumentNullException("objectType"); + } + + if (objectType.PropertyDefintions == null) + { + throw new ArgumentException("Object type has no property defintions!"); + } - // properties - public IProperty CreateProperty(IPropertyDefinition type, IList values) { return null; } - public IDictionary ConvertProperties(IObjectType objectType, IProperties properties) { return null; } - public IProperties ConvertProperties(IDictionary properties, IObjectType type, HashSet updatabilityFilter) { return null; } - public IList ConvertQueryProperties(IProperties properties) { return null; } + if (properties == null || properties.PropertyList == null) + { + throw new ArgumentException("Properties must be set!"); + } + + // iterate through properties and convert them + IDictionary result = new Dictionary(); + foreach (IPropertyData property in properties.PropertyList) + { + // find property definition + IProperty apiProperty = ConvertProperty(objectType, property); + result[property.Id] = apiProperty; + } + + return result; + } + + public IProperties ConvertProperties(IDictionary properties, IObjectType type, HashSet updatabilityFilter) + { + // check input + if (properties == null) + { + return null; + } + + // get the type + if (type == null) + { + string typeId = properties[PropertyIds.ObjectTypeId] as string; + if (typeId == null) + { + throw new ArgumentException("Type or type property must be set!"); + } + + type = session.GetTypeDefinition(typeId); + } + + Properties result = new Properties(); + + // the big loop + foreach (KeyValuePair property in properties) + { + string id = property.Key; + object value = property.Value; + + if (value is IProperty) + { + IProperty p = (IProperty)value; + if (id != p.Id) + { + throw new ArgumentException("Property id mismatch: '" + id + "' != '" + p.Id + "'!"); + } + value = (p.PropertyDefinition.Cardinality == Cardinality.Single ? p.FirstValue : p.Values); + } + + // get the property definition + IPropertyDefinition definition = type[id]; + if (definition == null) + { + throw new ArgumentException("Property +'" + id + "' is not valid for this type!"); + } + + // check updatability + if (updatabilityFilter != null) + { + if (!updatabilityFilter.Contains(definition.Updatability)) + { + continue; + } + } + + // single and multi value check + IList values; + if (value == null) + { + values = null; + } + else if (value is IList) + { + if (definition.Cardinality != Cardinality.Multi) + { + throw new ArgumentException("Property '" + id + "' is not a multi value property!"); + } + values = (IList)value; + + // check if the list is homogeneous and does not contain null values + Type valueType = null; + foreach (object o in values) + { + if (o == null) + { + throw new ArgumentException("Property '" + id + "' contains null values!"); + } + if (valueType == null) + { + valueType = o.GetType(); + } + else + { + if (!valueType.IsInstanceOfType(o)) + { + throw new ArgumentException("Property '" + id + "' is inhomogeneous!"); + } + } + } + } + else + { + if (definition.Cardinality != Cardinality.Single) + { + throw new ArgumentException("Property '" + id + "' is not a single value property!"); + } + values = new List(); + values.Add(value); + } + + // assemble property + object firstValue = (values == null || values.Count == 0 ? null : values[0]); + + switch (definition.PropertyType) + { + case PropertyType.String: + PropertyString stringProperty = new PropertyString(); + stringProperty.Id = id; + stringProperty.Values = new List(values.Count); + if (values != null) + { + if (firstValue != null && !(firstValue is string)) + { + throw new ArgumentException("Property '" + id + "' is a String property!"); + } + + foreach (object o in values) + { + stringProperty.Values.Add((string)o); + } + } + result.AddProperty(stringProperty); + break; + case PropertyType.Id: + PropertyId idProperty = new PropertyId(); + idProperty.Id = id; + idProperty.Values = new List(values.Count); + if (values != null) + { + if (firstValue != null && !(firstValue is string)) + { + throw new ArgumentException("Property '" + id + "' is a Id property!"); + } + + foreach (object o in values) + { + idProperty.Values.Add((string)o); + } + } + result.AddProperty(idProperty); + break; + case PropertyType.Integer: + PropertyInteger intProperty = new PropertyInteger(); + intProperty.Id = id; + intProperty.Values = new List(values.Count); + if (values != null) + { + if (firstValue != null && !(firstValue is sbyte || firstValue is byte || firstValue is short || firstValue is ushort || firstValue is int || firstValue is uint || firstValue is long)) + { + throw new ArgumentException("Property '" + id + "' is an Integer property!"); + } + + foreach (object o in values) + { + intProperty.Values.Add((long)o); + } + } + result.AddProperty(intProperty); + break; + case PropertyType.Boolean: + PropertyBoolean booleanProperty = new PropertyBoolean(); + booleanProperty.Id = id; + booleanProperty.Values = new List(values.Count); + if (values != null) + { + if (firstValue != null && !(firstValue is bool)) + { + throw new ArgumentException("Property '" + id + "' is a boolean property!"); + } + + foreach (object o in values) + { + booleanProperty.Values.Add((bool)o); + } + } + result.AddProperty(booleanProperty); + break; + case PropertyType.DateTime: + PropertyDateTime dateTimeProperty = new PropertyDateTime(); + dateTimeProperty.Id = id; + dateTimeProperty.Values = new List(values.Count); + if (values != null) + { + if (firstValue != null && !(firstValue is DateTime)) + { + throw new ArgumentException("Property '" + id + "' is a Boolean property!"); + } + + foreach (object o in values) + { + dateTimeProperty.Values.Add((DateTime)o); + } + } + result.AddProperty(dateTimeProperty); + break; + case PropertyType.Decimal: + PropertyDecimal decimalProperty = new PropertyDecimal(); + decimalProperty.Id = id; + decimalProperty.Values = new List(values.Count); + if (values != null) + { + if (firstValue != null && !(firstValue is DateTime)) + { + throw new ArgumentException("Property '" + id + "' is a Decimal property!"); + } + + foreach (object o in values) + { + decimalProperty.Values.Add((decimal)o); + } + } + result.AddProperty(decimalProperty); + break; + case PropertyType.Uri: + PropertyUri uriProperty = new PropertyUri(); + uriProperty.Id = id; + uriProperty.Values = new List(values.Count); + if (values != null) + { + if (firstValue != null && !(firstValue is string)) + { + throw new ArgumentException("Property '" + id + "' is a URI property!"); + } + + foreach (object o in values) + { + uriProperty.Values.Add((string)o); + } + } + result.AddProperty(uriProperty); + break; + case PropertyType.Html: + PropertyHtml htmlProperty = new PropertyHtml(); + htmlProperty.Id = id; + htmlProperty.Values = new List(values.Count); + if (values != null) + { + if (firstValue != null && !(firstValue is string)) + { + throw new ArgumentException("Property '" + id + "' is a HTML property!"); + } + + foreach (object o in values) + { + htmlProperty.Values.Add((string)o); + } + } + result.AddProperty(htmlProperty); + break; + } + } + + return result; + } + + public IList ConvertQueryProperties(IProperties properties) + { + if ((properties == null) || (properties.PropertyList == null)) + { + throw new ArgumentException("Properties must be set!"); + } + + return new List(properties.PropertyList); + } // objects - public ICmisObject ConvertObject(IObjectData objectData, IOperationContext context) { return null; } + public ICmisObject ConvertObject(IObjectData objectData, IOperationContext context) + { + if (objectData == null) + { + throw new ArgumentNullException("objectData"); + } + + IObjectType type = GetTypeFromObjectData(objectData); + + switch (objectData.BaseTypeId) + { + case BaseTypeId.CmisDocument: + return new Document(session, type, objectData, context); + case BaseTypeId.CmisFolder: + return new Folder(session, type, objectData, context); + case BaseTypeId.CmisPolicy: + return new Policy(session, type, objectData, context); + case BaseTypeId.CmisRelationship: + return new Relationship(session, type, objectData, context); + default: + throw new CmisRuntimeException("Unsupported type: " + objectData.BaseTypeId); + } + } + public IQueryResult ConvertQueryResult(IObjectData objectData) { return null; } public IChangeEvent ConvertChangeEvent(IObjectData objectData) { return null; } public IChangeEvents ConvertChangeEvents(String changeLogToken, IObjectList objectList) { return null; } Modified: incubator/chemistry/dotcmis/trunk/DotCMIS/client/client-objects.cs URL: http://svn.apache.org/viewvc/incubator/chemistry/dotcmis/trunk/DotCMIS/client/client-objects.cs?rev=1067465&r1=1067464&r2=1067465&view=diff ============================================================================== --- incubator/chemistry/dotcmis/trunk/DotCMIS/client/client-objects.cs (original) +++ incubator/chemistry/dotcmis/trunk/DotCMIS/client/client-objects.cs Sat Feb 5 16:27:31 2011 @@ -27,10 +27,14 @@ using DotCMIS.Data; using DotCMIS.Data.Extensions; using DotCMIS.Enums; using DotCMIS.Exceptions; +using DotCMIS.Binding.Services; namespace DotCMIS.Client { - internal abstract class AbstractCmisObject : ICmisObject + /// + /// CMIS object base class. + /// + public abstract class AbstractCmisObject : ICmisObject { protected ISession Session { get; private set; } protected string RepositoryId { get { return Session.RepositoryInfo.Id; } } @@ -80,7 +84,7 @@ namespace DotCMIS.Client private object objectLock = new object(); - protected void initialize(ISession session, IObjectType objectType, IObjectData objectData, IOperationContext context) + protected void Initialize(ISession session, IObjectType objectType, IObjectData objectData, IOperationContext context) { if (session == null) { @@ -104,7 +108,6 @@ namespace DotCMIS.Client this.CreationContext = new OperationContext(context); this.RefreshTimestamp = DateTime.UtcNow; - IObjectFactory of = Session.ObjectFactory; if (objectData != null) @@ -146,10 +149,10 @@ namespace DotCMIS.Client policies = new List(); foreach (string pid in objectData.PolicyIds.PolicyIds) { - ICmisObject policy = Session.GetObject(Session.CreateObjectId(pid)); - if (policy is IPolicy) + IPolicy policy = Session.GetObject(Session.CreateObjectId(pid)) as IPolicy; + if (policy != null) { - policies.Add((IPolicy)policy); + policies.Add(policy); } } extensions[ExtensionLevel.Policies] = objectData.PolicyIds.Extensions; @@ -161,10 +164,10 @@ namespace DotCMIS.Client relationships = new List(); foreach (IObjectData rod in objectData.Relationships) { - ICmisObject relationship = of.ConvertObject(rod, CreationContext); - if (relationship is IRelationship) + IRelationship relationship = of.ConvertObject(rod, CreationContext) as IRelationship; + if (relationship != null) { - relationships.Add((IRelationship)relationship); + relationships.Add(relationship); } } } @@ -274,7 +277,7 @@ namespace DotCMIS.Client // --- properties --- - public IObjectType BaseType { get { return Session.GetTypeDefinition(BaseTypeId.GetCmisValue()); } } + public IObjectType BaseType { get { return Session.GetTypeDefinition(GetPropertyValue(PropertyIds.BaseTypeId) as string); } } public BaseTypeId BaseTypeId { @@ -521,7 +524,7 @@ namespace DotCMIS.Client oc.IncludeRelationships, oc.RenditionFilterString, oc.IncludePolicies, oc.IncludeAcls, null); // reset this object - initialize(Session, ObjectType, objectData, CreationContext); + Initialize(Session, ObjectType, objectData, CreationContext); } finally { @@ -555,4 +558,1106 @@ namespace DotCMIS.Client Monitor.Exit(objectLock); } } -} + + /// + /// Fileable object base class. + /// + public abstract class AbstractFileableCmisObject : AbstractCmisObject, IFileableCmisObject + { + public IFileableCmisObject Move(IObjectId sourceFolderId, IObjectId targetFolderId) + { + string objectId = ObjectId; + + if (sourceFolderId == null || sourceFolderId.Id == null) + { + throw new ArgumentException("Source folder id must be set!"); + } + + if (targetFolderId == null || targetFolderId.Id == null) + { + throw new ArgumentException("Target folder id must be set!"); + } + + Binding.GetObjectService().MoveObject(RepositoryId, ref objectId, targetFolderId.Id, sourceFolderId.Id, null); + + if (objectId == null) + { + return null; + } + + IFileableCmisObject movedObject = Session.GetObject(Session.CreateObjectId(objectId)) as IFileableCmisObject; + if (movedObject == null) + { + throw new CmisRuntimeException("Moved object is invalid!"); + } + + return movedObject; + } + + public virtual IList Parents + { + get + { + // get object ids of the parent folders + IList providerParents = Binding.GetNavigationService().GetObjectParents( + RepositoryId, ObjectId, GetPropertyQueryName(PropertyIds.ObjectId), false, + IncludeRelationshipsFlag.None, null, false, null); + + IList parents = new List(); + + foreach (IObjectParentData p in providerParents) + { + if (p == null || p.Object == null || p.Object.Properties == null) + { + // should not happen... + throw new CmisRuntimeException("Repository sent invalid data!"); + } + + // get id property + IPropertyId idProperty = p.Object.Properties[PropertyIds.ObjectId] as IPropertyId; + if (idProperty == null) + { + // the repository sent an object without a valid object id... + throw new CmisRuntimeException("Repository sent invalid data! No object id!"); + } + + // fetch the object and make sure it is a folder + IObjectId parentId = Session.CreateObjectId(idProperty.FirstValue); + IFolder parentFolder = Session.GetObject(parentId) as IFolder; + if (parentFolder == null) + { + // the repository sent an object that is not a folder... + throw new CmisRuntimeException("Repository sent invalid data! Object is not a folder!"); + } + + parents.Add(parentFolder); + } + + return parents; + } + } + + public virtual IList Paths + { + get + { + // get object paths of the parent folders + IList parents = Binding.GetNavigationService().GetObjectParents( + RepositoryId, ObjectId, GetPropertyQueryName(PropertyIds.Path), false, IncludeRelationshipsFlag.None, + null, true, null); + + IList paths = new List(); + + foreach (IObjectParentData p in parents) + { + if (p == null || p.Object == null || p.Object.Properties == null) + { + // should not happen... + throw new CmisRuntimeException("Repository sent invalid data!"); + } + + // get path property + IPropertyString pathProperty = p.Object.Properties[PropertyIds.Path] as IPropertyString; + if (pathProperty == null) + { + // the repository sent a folder without a valid path... + throw new CmisRuntimeException("Repository sent invalid data! No path property!"); + } + + if (p.RelativePathSegment == null) + { + // the repository didn't send a relative path segment + throw new CmisRuntimeException("Repository sent invalid data! No relative path segement!"); + } + + string folderPath = pathProperty.FirstValue; + paths.Add(folderPath + (folderPath.EndsWith("/") ? "" : "/") + p.RelativePathSegment); + } + + return paths; + } + } + + public void AddToFolder(IObjectId folderId, bool allVersions) + { + if (folderId == null || folderId.Id == null) + { + throw new ArgumentException("Folder Id must be set!"); + } + + Binding.GetMultiFilingService().AddObjectToFolder(RepositoryId, ObjectId, folderId.Id, allVersions, null); + } + + public void RemoveFromFolder(IObjectId folderId) + { + if (folderId == null || folderId.Id == null) + { + throw new ArgumentException("Folder Id must be set!"); + } + + Binding.GetMultiFilingService().RemoveObjectFromFolder(RepositoryId, ObjectId, folderId.Id, null); + } + } + + /// + /// Document implemetation. + /// + public class Document : AbstractFileableCmisObject, IDocument + { + public Document(ISession session, IObjectType objectType, IObjectData objectData, IOperationContext context) + { + Initialize(session, objectType, objectData, context); + } + + // properties + + public bool? IsImmutable { get { return GetPropertyValue(PropertyIds.IsImmutable) as bool?; } } + + public bool? IsLatestVersion { get { return GetPropertyValue(PropertyIds.IsLatestVersion) as bool?; } } + + public bool? IsMajorVersion { get { return GetPropertyValue(PropertyIds.IsMajorVersion) as bool?; } } + + public bool? IsLatestMajorVersion { get { return GetPropertyValue(PropertyIds.IsLatestMajorVersion) as bool?; } } + + public string VersionLabel { get { return GetPropertyValue(PropertyIds.VersionLabel) as string; } } + + public string VersionSeriesId { get { return GetPropertyValue(PropertyIds.VersionSeriesId) as string; } } + + public bool? IsVersionSeriesCheckedOut { get { return GetPropertyValue(PropertyIds.IsVersionSeriesCheckedOut) as bool?; } } + + public string VersionSeriesCheckedOutBy { get { return GetPropertyValue(PropertyIds.VersionSeriesCheckedOutBy) as string; } } + + public string VersionSeriesCheckedOutId { get { return GetPropertyValue(PropertyIds.VersionSeriesCheckedOutId) as string; } } + + public string CheckinComment { get { return GetPropertyValue(PropertyIds.CheckinComment) as string; } } + + public long? ContentStreamLength { get { return GetPropertyValue(PropertyIds.ContentStreamLength) as long?; } } + + public string ContentStreamMimeType { get { return GetPropertyValue(PropertyIds.ContentStreamMimeType) as string; } } + + public string ContentStreamFileName { get { return GetPropertyValue(PropertyIds.ContentStreamFileName) as string; } } + + public string ContentStreamId { get { return GetPropertyValue(PropertyIds.ContentStreamId) as string; } } + + // operations + + public IDocument Copy(IObjectId targetFolderId, IDictionary properties, VersioningState? versioningState, + IList policies, IList addAces, IList removeAces, IOperationContext context) + { + + IObjectId newId = Session.CreateDocumentFromSource(this, properties, targetFolderId, versioningState, policies, addAces, removeAces); + + // if no context is provided the object will not be fetched + if (context == null || newId == null) + { + return null; + } + // get the new object + IDocument newDoc = Session.GetObject(newId, context) as IDocument; + if (newDoc == null) + { + throw new CmisRuntimeException("Newly created object is not a document! New id: " + newId); + } + + return newDoc; + } + + public IDocument Copy(IObjectId targetFolderId) + { + return Copy(targetFolderId, null, null, null, null, null, Session.DefaultContext); + } + + public void DeleteAllVersions() + { + Delete(true); + } + + // versioning + + public IObjectId CheckOut() + { + string newObjectId = null; + + Lock(); + try + { + string objectId = ObjectId; + bool? contentCopied; + + Binding.GetVersioningService().CheckOut(RepositoryId, ref objectId, null, out contentCopied); + newObjectId = objectId; + } + finally + { + Unlock(); + } + + if (newObjectId == null) + { + return null; + } + + return Session.CreateObjectId(newObjectId); + } + + public void CancelCheckOut() + { + Binding.GetVersioningService().CancelCheckOut(RepositoryId, ObjectId, null); + } + + public IObjectId CheckIn(bool major, IDictionary properties, IContentStream contentStream, + string checkinComment, IList policies, IList addAces, IList removeAces) + { + String newObjectId = null; + + Lock(); + try + { + string objectId = ObjectId; + + IObjectFactory of = Session.ObjectFactory; + + HashSet updatebility = new HashSet(); + updatebility.Add(Updatability.ReadWrite); + updatebility.Add(Updatability.WhenCheckedOut); + + Binding.GetVersioningService().CheckIn(RepositoryId, ref objectId, major, of.ConvertProperties(properties, ObjectType, updatebility), + contentStream, checkinComment, of.ConvertPolicies(policies), of.ConvertAces(addAces), of.ConvertAces(removeAces), null); + + newObjectId = objectId; + } + finally + { + Unlock(); + } + + if (newObjectId == null) + { + return null; + } + + return Session.CreateObjectId(newObjectId); + + } + + public IList GetAllVersions() + { + return GetAllVersions(Session.DefaultContext); + } + + public IList GetAllVersions(IOperationContext context) + { + string objectId; + string versionSeriesId; + + Lock(); + try + { + objectId = ObjectId; + versionSeriesId = VersionSeriesId; + } + finally + { + Unlock(); + } + + IList versions = Binding.GetVersioningService().GetAllVersions(RepositoryId, objectId, versionSeriesId, + context.FilterString, context.IncludeAllowableActions, null); + + IObjectFactory of = Session.ObjectFactory; + + IList result = new List(); + if (versions != null) + { + foreach (IObjectData objectData in versions) + { + IDocument doc = of.ConvertObject(objectData, context) as IDocument; + if (doc == null) + { + // should not happen... + continue; + } + + result.Add(doc); + } + } + + return result; + } + + public IDocument GetObjectOfLatestVersion(bool major) + { + return GetObjectOfLatestVersion(major, Session.DefaultContext); + } + + public IDocument GetObjectOfLatestVersion(bool major, IOperationContext context) + { + string objectId; + string versionSeriesId; + + Lock(); + try + { + objectId = ObjectId; + versionSeriesId = VersionSeriesId; + } + finally + { + Unlock(); + } + + if (versionSeriesId == null) + { + throw new CmisRuntimeException("Version series id is unknown!"); + } + + IObjectData objectData = Binding.GetVersioningService().GetObjectOfLatestVersion(RepositoryId, objectId, versionSeriesId, major, + context.FilterString, context.IncludeAllowableActions, context.IncludeRelationships, context.RenditionFilterString, + context.IncludePolicies, context.IncludeAcls, null); + + IDocument result = Session.ObjectFactory.ConvertObject(objectData, context) as IDocument; + if (result == null) + { + throw new CmisRuntimeException("Latest version is not a document!"); + } + + return result; + } + + // content operations + + public IContentStream GetContentStream() + { + return GetContentStream(null); + } + + public IContentStream GetContentStream(String streamId) + { + IContentStream contentStream; + try + { + contentStream = Binding.GetObjectService().GetContentStream(RepositoryId, ObjectId, streamId, null, null, null); + } + catch (CmisConstraintException) + { + // no content stream + return null; + } + + // the AtomPub binding doesn't return a file name + // -> get the file name from properties, if present + if (contentStream.FileName == null && ContentStreamFileName != null) + { + ContentStream newContentStream = new ContentStream(); + newContentStream.FileName = ContentStreamFileName; + newContentStream.Length = contentStream.Length; + newContentStream.MimeType = contentStream.MimeType; + newContentStream.Stream = contentStream.Stream; + newContentStream.Extensions = contentStream.Extensions; + + contentStream = newContentStream; + } + + return contentStream; + } + + public IDocument SetContentStream(IContentStream contentStream, bool overwrite) + { + IObjectId objectId = SetContentStream(contentStream, overwrite, true); + if (objectId == null) + { + return null; + } + + if (ObjectId != objectId.Id) + { + return (IDocument)Session.GetObject(objectId, CreationContext); + } + + return this; + } + + public IObjectId SetContentStream(IContentStream contentStream, bool overwrite, bool refresh) + { + string newObjectId = null; + + Lock(); + try + { + string objectId = ObjectId; + string changeToken = ChangeToken; + + Binding.GetObjectService().SetContentStream(RepositoryId, ref objectId, overwrite, ref changeToken, contentStream, null); + + newObjectId = objectId; + } + finally + { + Unlock(); + } + + if (refresh) + { + Refresh(); + } + + if (newObjectId == null) + { + return null; + } + + return Session.CreateObjectId(newObjectId); + } + + public IDocument DeleteContentStream() + { + IObjectId objectId = DeleteContentStream(true); + if (objectId == null) + { + return null; + } + + if (ObjectId != objectId.Id) + { + return (IDocument)Session.GetObject(objectId, CreationContext); + } + + return this; + } + + public IObjectId DeleteContentStream(bool refresh) + { + string newObjectId = null; + + Lock(); + try + { + string objectId = ObjectId; + string changeToken = ChangeToken; + + Binding.GetObjectService().DeleteContentStream(RepositoryId, ref objectId, ref changeToken, null); + + newObjectId = objectId; + } + finally + { + Unlock(); + } + + if (refresh) + { + Refresh(); + } + + if (newObjectId == null) + { + return null; + } + + return Session.CreateObjectId(newObjectId); + } + + public IObjectId CheckIn(bool major, IDictionary properties, IContentStream contentStream, string checkinComment) + { + return this.CheckIn(major, properties, contentStream, checkinComment, null, null, null); + } + } + + /// + /// Folder implemetation. + /// + public class Folder : AbstractFileableCmisObject, IFolder + { + private static HashSet CreateUpdatability = new HashSet(); + static Folder() + { + CreateUpdatability.Add(Updatability.OnCreate); + CreateUpdatability.Add(Updatability.ReadWrite); + } + + public Folder(ISession session, IObjectType objectType, IObjectData objectData, IOperationContext context) + { + Initialize(session, objectType, objectData, context); + } + + public IDocument CreateDocument(IDictionary properties, IContentStream contentStream, VersioningState? versioningState, + IList policies, IList addAces, IList removeAces, IOperationContext context) + { + IObjectId newId = Session.CreateDocument(properties, this, contentStream, versioningState, policies, addAces, removeAces); + + // if no context is provided the object will not be fetched + if (context == null || newId == null) + { + return null; + } + + // get the new object + IDocument newDoc = Session.GetObject(newId, context) as IDocument; + if (newDoc == null) + { + throw new CmisRuntimeException("Newly created object is not a document! New id: " + newId); + } + + return newDoc; + } + + public IDocument CreateDocumentFromSource(IObjectId source, IDictionary properties, VersioningState? versioningState, + IList policies, IList addAces, IList removeAces, IOperationContext context) + { + IObjectId newId = Session.CreateDocumentFromSource(source, properties, this, versioningState, policies, addAces, removeAces); + + // if no context is provided the object will not be fetched + if (context == null || newId == null) + { + return null; + } + + // get the new object + IDocument newDoc = Session.GetObject(newId, context) as IDocument; + if (newDoc == null) + { + throw new CmisRuntimeException("Newly created object is not a document! New id: " + newId); + } + + return newDoc; + } + + public IFolder CreateFolder(IDictionary properties, IList policies, IList addAces, IList removeAces, IOperationContext context) + { + IObjectId newId = Session.CreateFolder(properties, this, policies, addAces, removeAces); + + // if no context is provided the object will not be fetched + if (context == null || newId == null) + { + return null; + } + + // get the new object + IFolder newFolder = Session.GetObject(newId, context) as IFolder; + if (newFolder == null) + { + throw new CmisRuntimeException("Newly created object is not a folder! New id: " + newId); + } + + return newFolder; + } + + public IPolicy CreatePolicy(IDictionary properties, IList policies, IList addAces, IList removeAces, IOperationContext context) + { + IObjectId newId = Session.CreatePolicy(properties, this, policies, addAces, removeAces); + + // if no context is provided the object will not be fetched + if (context == null || newId == null) + { + return null; + } + + // get the new object + IPolicy newPolicy = Session.GetObject(newId, context) as IPolicy; + if (newPolicy == null) + { + throw new CmisRuntimeException("Newly created object is not a policy! New id: " + newId); + } + + return newPolicy; + } + + public IList DeleteTree(bool allVersions, UnfileObject? unfile, bool continueOnFailure) + { + IFailedToDeleteData failed = Binding.GetObjectService().DeleteTree(RepositoryId, ObjectId, allVersions, unfile, continueOnFailure, null); + return failed.Ids; + } + + public IList AllowedChildObjectTypes + { + get + { + IList result = new List(); + + Lock(); + try + { + IList otids = GetPropertyValue(PropertyIds.AllowedChildObjectTypeIds) as IList; + if (otids == null) + { + return result; + } + + foreach (string otid in otids) + { + result.Add(Session.GetTypeDefinition(otid)); + } + } + finally + { + Unlock(); + } + + return result; + } + } + + public IItemEnumerable GetCheckedOutDocs() + { + return GetCheckedOutDocs(Session.DefaultContext); + } + + public IItemEnumerable GetCheckedOutDocs(IOperationContext context) + { + string objectId = ObjectId; + INavigationService service = Binding.GetNavigationService(); + IObjectFactory of = Session.ObjectFactory; + IOperationContext ctxt = new OperationContext(context); + + PageFetcher.FetchPage fetchPageDelegate = delegate(long maxNumItems, long skipCount) + { + // get checked out documents for this folder + IObjectList checkedOutDocs = service.GetCheckedOutDocs(RepositoryId, objectId, ctxt.FilterString, ctxt.OrderBy, ctxt.IncludeAllowableActions, + ctxt.IncludeRelationships, ctxt.RenditionFilterString, maxNumItems, skipCount, null); + + IList page = new List(); + if (checkedOutDocs.Objects != null) + { + foreach (IObjectData objectData in checkedOutDocs.Objects) + { + IDocument doc = of.ConvertObject(objectData, ctxt) as IDocument; + if (doc == null) + { + // should not happen... + continue; + } + + page.Add(doc); + } + } + + + return new PageFetcher.Page(page, checkedOutDocs.NumItems, checkedOutDocs.HasMoreItems); + }; + + return new CollectionEnumerable(new PageFetcher(ctxt.MaxItemsPerPage, fetchPageDelegate)); + } + + public IItemEnumerable GetChildren() + { + return GetChildren(Session.DefaultContext); + } + + public IItemEnumerable GetChildren(IOperationContext context) + { + string objectId = ObjectId; + INavigationService service = Binding.GetNavigationService(); + IObjectFactory of = Session.ObjectFactory; + IOperationContext ctxt = new OperationContext(context); + + PageFetcher.FetchPage fetchPageDelegate = delegate(long maxNumItems, long skipCount) + { + // get the children + IObjectInFolderList children = service.GetChildren(RepositoryId, objectId, ctxt.FilterString, ctxt.OrderBy, ctxt.IncludeAllowableActions, + ctxt.IncludeRelationships, ctxt.RenditionFilterString, ctxt.IncludePathSegments, maxNumItems, skipCount, null); + + // convert objects + IList page = new List(); + if (children.Objects != null) + { + foreach (IObjectInFolderData objectData in children.Objects) + { + if (objectData.Object != null) + { + page.Add(of.ConvertObject(objectData.Object, ctxt)); + } + } + } + + return new PageFetcher.Page(page, children.NumItems, children.HasMoreItems); + }; + + return new CollectionEnumerable(new PageFetcher(ctxt.MaxItemsPerPage, fetchPageDelegate)); + } + + public IList> GetDescendants(int depth) + { + return GetDescendants(depth, Session.DefaultContext); + } + + public IList> GetDescendants(int depth, IOperationContext context) + { + IList bindingContainerList = Binding.GetNavigationService().GetDescendants(RepositoryId, ObjectId, depth, + context.FilterString, context.IncludeAllowableActions, context.IncludeRelationships, context.RenditionFilterString, + context.IncludePathSegments, null); + + return ConvertProviderContainer(bindingContainerList, context); + } + + public IList> GetFolderTree(int depth) + { + return GetFolderTree(depth, Session.DefaultContext); + } + + public IList> GetFolderTree(int depth, IOperationContext context) + { + IList bindingContainerList = Binding.GetNavigationService().GetFolderTree(RepositoryId, ObjectId, depth, + context.FilterString, context.IncludeAllowableActions, context.IncludeRelationships, context.RenditionFilterString, + context.IncludePathSegments, null); + + return ConvertProviderContainer(bindingContainerList, context); + } + + private IList> ConvertProviderContainer(IList bindingContainerList, IOperationContext context) + { + if (bindingContainerList == null) + { + return null; + } + + IList> result = new List>(); + foreach (IObjectInFolderContainer oifc in bindingContainerList) + { + if (oifc.Object == null || oifc.Object.Object == null) + { + // shouldn't happen ... + continue; + } + + // convert the object + IFileableCmisObject cmisObject = Session.ObjectFactory.ConvertObject(oifc.Object.Object, context) as IFileableCmisObject; + if (cmisObject == null) + { + // the repository must not return objects that are not fileable, but you never know... + continue; + } + + // convert the children + IList> children = ConvertProviderContainer(oifc.Children, context); + + // add both to current container + Tree tree = new Tree(); + tree.Item = cmisObject; + tree.Children = children; + + result.Add(tree); + } + + return result; + } + + public bool IsRootFolder { get { return ObjectId == Session.RepositoryInfo.RootFolderId; } } + + public IFolder FolderParent + { + get + { + if (IsRootFolder) + { + return null; + } + + IList parents = Parents; + if (parents == null || parents.Count == 0) + { + return null; + } + + return parents[0]; + } + } + + public string Path + { + get + { + string path; + + Lock(); + try + { + // get the path property + path = GetPropertyValue(PropertyIds.Path) as string; + + // if the path property isn't set, get it + if (path == null) + { + IObjectData objectData = Binding.GetObjectService().GetObject(RepositoryId, ObjectId, + GetPropertyQueryName(PropertyIds.Path), false, IncludeRelationshipsFlag.None, "cmis:none", false, + false, null); + + if (objectData.Properties != null) + { + PropertyString pathProperty = objectData.Properties[PropertyIds.Path] as PropertyString; + if (pathProperty != null) + { + path = pathProperty.FirstValue; + } + } + } + } + finally + { + Unlock(); + } + + // we still don't know the path ... it's not a CMIS compliant repository + if (path == null) + { + throw new CmisRuntimeException("Repository didn't return " + PropertyIds.Path + "!"); + } + + return path; + } + } + + public override IList Paths + { + get + { + IList result = new List(); + result.Add(Path); + + return result; + } + } + + public IDocument CreateDocument(IDictionary properties, IContentStream contentStream, VersioningState? versioningState) + { + return CreateDocument(properties, contentStream, versioningState, null, null, null, Session.DefaultContext); + } + + public IDocument CreateDocumentFromSource(IObjectId source, IDictionary properties, VersioningState? versioningState) + { + return CreateDocumentFromSource(source, properties, versioningState, null, null, null, Session.DefaultContext); + } + + public IFolder CreateFolder(IDictionary properties) + { + return CreateFolder(properties, null, null, null, Session.DefaultContext); + } + + public IPolicy CreatePolicy(IDictionary properties) + { + return CreatePolicy(properties, null, null, null, Session.DefaultContext); + } + } + + /// + /// Policy implemetation. + /// + public class Policy : AbstractFileableCmisObject, IPolicy + { + public Policy(ISession session, IObjectType objectType, IObjectData objectData, IOperationContext context) + { + Initialize(session, objectType, objectData, context); + } + + public string PolicyText { get { return GetPropertyValue(PropertyIds.PolicyText) as string; } } + } + + /// + /// Relationship implemetation. + /// + public class Relationship : AbstractCmisObject, IRelationship + { + + public Relationship(ISession session, IObjectType objectType, IObjectData objectData, IOperationContext context) + { + Initialize(session, objectType, objectData, context); + } + + public ICmisObject GetSource() + { + return GetSource(Session.DefaultContext); + } + + public ICmisObject GetSource(IOperationContext context) + { + Lock(); + try + { + IObjectId sourceId = SourceId; + if (sourceId == null) + { + return null; + } + + return Session.GetObject(sourceId, context); + } + finally + { + Unlock(); + } + } + + public IObjectId SourceId + { + get + { + string sourceId = GetPropertyValue(PropertyIds.SourceId) as string; + if (sourceId == null || sourceId.Length == 0) + { + return null; + } + + return Session.CreateObjectId(sourceId); + } + } + + public ICmisObject GetTarget() + { + return GetTarget(Session.DefaultContext); + } + + public ICmisObject GetTarget(IOperationContext context) + { + Lock(); + try + { + IObjectId targetId = TargetId; + if (targetId == null) + { + return null; + } + + return Session.GetObject(targetId, context); + } + finally + { + Unlock(); + } + } + + public IObjectId TargetId + { + get + { + string targetId = GetPropertyValue(PropertyIds.TargetId) as string; + if (targetId == null || targetId.Length == 0) + { + return null; + } + + return Session.CreateObjectId(targetId); + } + } + } + + public class Property : IProperty + { + public Property(IPropertyDefinition propertyDefinition, IList values) + { + PropertyDefinition = propertyDefinition; + Values = values; + } + + public string Id { get { return PropertyDefinition.Id; } } + + public string LocalName { get { return PropertyDefinition.LocalName; } } + + public string DisplayName { get { return PropertyDefinition.DisplayName; } } + + public string QueryName { get { return PropertyDefinition.QueryName; } } + + public bool IsMultiValued { get { return PropertyDefinition.Cardinality == Cardinality.Multi; } } + + public PropertyType? PropertyType { get { return PropertyDefinition.PropertyType; } } + + public IPropertyDefinition PropertyDefinition { get; protected set; } + + public object Value + { + get + { + if (PropertyDefinition.Cardinality == Cardinality.Single) + { + return Values.Count == 0 ? null : Values[0]; + } + else + { + return Values; + } + } + } + + public IList Values { get; protected set; } + + public object FirstValue { get { return Values.Count == 0 ? null : Values[0]; } } + + public string ValueAsString { get { return FormatValue(FirstValue); } } + + public string ValuesAsString + { + get + { + StringBuilder result = new StringBuilder(); + foreach (object value in Values) + { + if (result.Length > 0) + { + result.Append(", "); + } + + result.Append(FormatValue(value)); + } + + return "[" + result.ToString() + "]"; + } + } + + private string FormatValue(object value) + { + if (value == null) + { + return null; + } + + // for future formating + + return value.ToString(); + } + } + + public class Rendition : RenditionData, IRendition + { + private ISession session; + private string objectId; + + public Rendition(ISession session, string objectId, string streamId, string mimeType, long? length, string kind, + string title, long? height, long? width, string renditionDocumentId) + { + this.session = session; + this.objectId = objectId; + + StreamId = streamId; + MimeType = mimeType; + Length = length; + Kind = kind; + Title = title; + Height = height; + Width = width; + RenditionDocumentId = renditionDocumentId; + } + + public IDocument GetRenditionDocument() + { + return GetRenditionDocument(session.DefaultContext); + } + + public IDocument GetRenditionDocument(IOperationContext context) + { + if (RenditionDocumentId == null) + { + return null; + } + + return session.GetObject(session.CreateObjectId(RenditionDocumentId), context) as IDocument; + } + + public IContentStream GetContentStream() + { + if (objectId == null || StreamId == null) + { + return null; + } + + return session.Binding.GetObjectService().GetContentStream(session.RepositoryInfo.Id, objectId, StreamId, null, null, null); + } + } +} \ No newline at end of file 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=1067465&r1=1067464&r2=1067465&view=diff ============================================================================== --- incubator/chemistry/dotcmis/trunk/DotCMIS/client/client-types.cs (original) +++ incubator/chemistry/dotcmis/trunk/DotCMIS/client/client-types.cs Sat Feb 5 16:27:31 2011 @@ -43,7 +43,7 @@ namespace DotCMIS.Client public ISession Session { get { return session; } } - public bool IsBaseType { get { return objectType.ParentTypeId == null; } } + public bool IsBaseType { get { return objectType.ParentTypeId == null || objectType.ParentTypeId.Length == 0; } } public IObjectType GetBaseType() { Modified: incubator/chemistry/dotcmis/trunk/DotCMIS/const.cs URL: http://svn.apache.org/viewvc/incubator/chemistry/dotcmis/trunk/DotCMIS/const.cs?rev=1067465&r1=1067464&r2=1067465&view=diff ============================================================================== --- incubator/chemistry/dotcmis/trunk/DotCMIS/const.cs (original) +++ incubator/chemistry/dotcmis/trunk/DotCMIS/const.cs Sat Feb 5 16:27:31 2011 @@ -91,7 +91,7 @@ namespace DotCMIS public const string IsImmutable = "cmis:isImmutable"; public const string IsLatestVersion = "cmis:isLatestVersion"; public const string IsMajorVersion = "cmis:isMajorVersion"; - public const string isLatestMajorVersion = "cmis:isLatestMajorVersion"; + public const string IsLatestMajorVersion = "cmis:isLatestMajorVersion"; public const string VersionLabel = "cmis:versionLabel"; public const string VersionSeriesId = "cmis:versionSeriesId"; public const string IsVersionSeriesCheckedOut = "cmis:isVersionSeriesCheckedOut";