/*
* 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 PortCMIS.Data.Extensions;
using PortCMIS.Enums;
using System;
using System.Collections.Generic;
using System.IO;
using System.Numerics;
using System.Text;
namespace PortCMIS.Data
{
///
/// Repository Info implementation.
///
public class RepositoryInfo : ExtensionsData, IRepositoryInfo
{
///
/// Constructor.
///
public RepositoryInfo()
{
}
///
/// Copy Constructor.
///
public RepositoryInfo(IRepositoryInfo source)
{
Id = source.Id;
Name = source.Name;
Description = source.Description;
VendorName = source.VendorName;
ProductName = source.ProductName;
ProductVersion = source.ProductVersion;
RootFolderId = source.RootFolderId;
Capabilities = source.Capabilities;
AclCapabilities = source.AclCapabilities;
LatestChangeLogToken = source.LatestChangeLogToken;
CmisVersionSupported = source.CmisVersionSupported;
ThinClientUri = source.ThinClientUri;
ChangesIncomplete = source.ChangesIncomplete;
ChangesOnType = source.ChangesOnType;
PrincipalIdAnonymous = source.PrincipalIdAnonymous;
PrincipalIdAnyone = source.PrincipalIdAnyone;
ExtensionFeatures = source.ExtensionFeatures;
Extensions = source.Extensions;
}
///
public string Id { get; set; }
///
public string Name { get; set; }
///
public string Description { get; set; }
///
public string VendorName { get; set; }
///
public string ProductName { get; set; }
///
public string ProductVersion { get; set; }
///
public string RootFolderId { get; set; }
///
public IRepositoryCapabilities Capabilities { get; set; }
///
public IAclCapabilities AclCapabilities { get; set; }
///
public string LatestChangeLogToken { get; set; }
///
public string CmisVersionSupported { get; set; }
///
public CmisVersion CmisVersion
{
get
{
if (CmisVersionSupported == null)
{
return CmisVersion.Cmis_1_0;
}
else
{
CmisVersion? cmisVersion = CmisVersionSupported.GetCmisEnum();
if (cmisVersion == null)
{
return CmisVersion.Cmis_1_0;
}
else
{
return (CmisVersion)cmisVersion;
}
}
}
}
///
public string ThinClientUri { get; set; }
///
public bool? ChangesIncomplete { get; set; }
///
public IList ChangesOnType { get; set; }
///
public string PrincipalIdAnonymous { get; set; }
///
public string PrincipalIdAnyone { get; set; }
///
public IList ExtensionFeatures { get; set; }
///
public override string ToString()
{
return "RepositoryInfo: " + Id;
}
}
///
/// Repository Capabilities implementation.
///
internal class RepositoryCapabilities : ExtensionsData, IRepositoryCapabilities
{
///
public CapabilityContentStreamUpdates? ContentStreamUpdatesCapability { get; set; }
///
public CapabilityChanges? ChangesCapability { get; set; }
///
public CapabilityRenditions? RenditionsCapability { get; set; }
///
public bool? IsGetDescendantsSupported { get; set; }
///
public bool? IsGetFolderTreeSupported { get; set; }
///
public CapabilityOrderBy? OrderByCapability { get; set; }
///
public bool? IsMultifilingSupported { get; set; }
///
public bool? IsUnfilingSupported { get; set; }
///
public bool? IsVersionSpecificFilingSupported { get; set; }
///
public bool? IsPwcSearchableSupported { get; set; }
///
public bool? IsPwcUpdatableSupported { get; set; }
///
public bool? IsAllVersionsSearchableSupported { get; set; }
///
public CapabilityQuery? QueryCapability { get; set; }
///
public CapabilityJoin? JoinCapability { get; set; }
///
public CapabilityAcl? AclCapability { get; set; }
///
public ICreatablePropertyTypes CreatablePropertyTypes { get; set; }
///
public INewTypeSettableAttributes NewTypeSettableAttributes { get; set; }
}
internal class CreatablePropertyTypes : ExtensionsData, ICreatablePropertyTypes
{
///
public ISet CanCreate { get; set; }
}
internal class NewTypeSettableAttributes : ExtensionsData, INewTypeSettableAttributes
{
///
public bool? CanSetId { get; set; }
///
public bool? CanSetLocalName { get; set; }
///
public bool? CanSetLocalNamespace { get; set; }
///
public bool? CanSetDisplayName { get; set; }
///
public bool? CanSetQueryName { get; set; }
///
public bool? CanSetDescription { get; set; }
///
public bool? CanSetCreatable { get; set; }
///
public bool? CanSetFileable { get; set; }
///
public bool? CanSetQueryable { get; set; }
///
public bool? CanSetFulltextIndexed { get; set; }
///
public bool? CanSetIncludedInSupertypeQuery { get; set; }
///
public bool? CanSetControllablePolicy { get; set; }
///
public bool? CanSetControllableAcl { get; set; }
}
internal class AclCapabilities : ExtensionsData, IAclCapabilities
{
///
public SupportedPermissions? SupportedPermissions { get; set; }
///
public AclPropagation? AclPropagation { get; set; }
///
public IList Permissions { get; set; }
///
public IDictionary PermissionMapping { get; set; }
}
internal class PermissionDefinition : ExtensionsData, IPermissionDefinition
{
///
public string Id { get; set; }
///
public string Description { get; set; }
}
internal class PermissionMapping : ExtensionsData, IPermissionMapping
{
///
public string Key { get; set; }
///
public IList Permissions { get; set; }
}
///
/// Extension Feature implementation.
///
public class ExtensionFeature : ExtensionsData, IExtensionFeature
{
///
public string Id { get; set; }
///
public string Url { get; set; }
///
public string CommonName { get; set; }
///
public string VersionLabel { get; set; }
///
public string Description { get; set; }
///
public IDictionary FeatureData { get; set; }
}
///
/// Base type definition implementation.
///
public abstract class AbstractTypeDefinition : ExtensionsData, ITypeDefinition
{
private List propertyDefintionList = new List();
private Dictionary propertyDefintionDict = new Dictionary();
private string parentTypeId;
///
public string Id { get; set; }
///
public string LocalName { get; set; }
///
public string LocalNamespace { get; set; }
///
public string DisplayName { get; set; }
///
public string QueryName { get; set; }
///
public string Description { get; set; }
///
public BaseTypeId BaseTypeId { get; set; }
///
public string ParentTypeId
{
get { return parentTypeId; }
set { parentTypeId = (value == null || value.Length == 0 ? null : value); }
}
///
public bool? IsCreatable { get; set; }
///
public bool? IsFileable { get; set; }
///
public bool? IsQueryable { get; set; }
///
public bool? IsFulltextIndexed { get; set; }
///
public bool? IsIncludedInSupertypeQuery { get; set; }
///
public bool? IsControllablePolicy { get; set; }
///
public bool? IsControllableAcl { get; set; }
///
public IPropertyDefinition this[string propertyId]
{
get
{
IPropertyDefinition propertyDefinition = null;
propertyDefintionDict.TryGetValue(propertyId, out propertyDefinition);
return propertyDefinition;
}
}
///
public IList PropertyDefinitions
{
get
{
return propertyDefintionList;
}
}
///
public ITypeMutability TypeMutability { get; set; }
///
/// Initializes the type definition object.
///
/// the type definition
protected void Initialize(ITypeDefinition typeDefinition)
{
Id = typeDefinition.Id;
LocalName = typeDefinition.LocalName;
LocalNamespace = typeDefinition.LocalNamespace;
DisplayName = typeDefinition.DisplayName;
QueryName = typeDefinition.QueryName;
Description = typeDefinition.Description;
BaseTypeId = typeDefinition.BaseTypeId;
ParentTypeId = typeDefinition.ParentTypeId;
IsCreatable = typeDefinition.IsCreatable;
IsFileable = typeDefinition.IsFileable;
IsQueryable = typeDefinition.IsQueryable;
IsFulltextIndexed = typeDefinition.IsFulltextIndexed;
IsIncludedInSupertypeQuery = typeDefinition.IsIncludedInSupertypeQuery;
IsControllablePolicy = typeDefinition.IsControllablePolicy;
IsControllableAcl = typeDefinition.IsControllableAcl;
if (typeDefinition.PropertyDefinitions != null)
{
foreach (IPropertyDefinition propDef in typeDefinition.PropertyDefinitions)
{
AddPropertyDefinition(propDef);
}
}
}
///
/// Adds a property type definition.
///
/// the property type definition
public void AddPropertyDefinition(IPropertyDefinition propertyDefinition)
{
if (propertyDefinition == null || propertyDefinition.Id == null)
{
return;
}
propertyDefintionList.Add(propertyDefinition);
propertyDefintionDict[propertyDefinition.Id] = propertyDefinition;
}
///
public override string ToString()
{
return "TypeDefinition: " + BaseTypeId + " (" + Id + ")";
}
}
///
/// Type mutability implementation.
///
public class TypeMutability : ExtensionsData, ITypeMutability
{
///
public bool? CanCreate { get; set; }
///
public bool? CanUpdate { get; set; }
///
public bool? CanDelete { get; set; }
}
///
/// Document type definition implementation.
///
public class DocumentTypeDefinition : AbstractTypeDefinition, IDocumentTypeDefinition
{
///
public bool? IsVersionable { get; set; }
///
public ContentStreamAllowed? ContentStreamAllowed { get; set; }
}
///
/// Folder type definition implementation.
///
public class FolderTypeDefinition : AbstractTypeDefinition, IFolderTypeDefinition
{
}
///
/// Policy type definition implementation.
///
public class PolicyTypeDefinition : AbstractTypeDefinition, IPolicyTypeDefinition
{
}
///
/// Item type definition implementation.
///
public class ItemTypeDefinition : AbstractTypeDefinition, IItemTypeDefinition
{
}
///
/// Secondary type definition implementation.
///
public class SecondaryTypeDefinition : AbstractTypeDefinition, ISecondaryTypeDefinition
{
}
///
/// Relationship type definition implementation.
///
public class RelationshipTypeDefinition : AbstractTypeDefinition, IRelationshipTypeDefinition
{
///
public IList AllowedSourceTypeIds { get; set; }
///
public IList AllowedTargetTypeIds { get; set; }
}
///
/// Type Definition List implementation.
///
public class TypeDefinitionList : ExtensionsData, ITypeDefinitionList
{
///
public IList List { get; set; }
///
public bool? HasMoreItems { get; set; }
///
public BigInteger? NumItems { get; set; }
}
///
/// Type Definition Container implementation.
///
public class TypeDefinitionContainer : ExtensionsData, ITypeDefinitionContainer
{
///
public ITypeDefinition TypeDefinition { get; set; }
///
public IList Children { get; set; }
}
///
/// Property definition implementation.
///
public abstract class PropertyDefinition : ExtensionsData, IPropertyDefinition
{
///
public string Id { get; set; }
///
public string LocalName { get; set; }
///
public string LocalNamespace { get; set; }
///
public string DisplayName { get; set; }
///
public string QueryName { get; set; }
///
public string Description { get; set; }
///
public PropertyType PropertyType { get; set; }
///
public Cardinality? Cardinality { get; set; }
///
public Updatability? Updatability { get; set; }
///
public bool? IsInherited { get; set; }
///
public bool? IsRequired { get; set; }
///
public bool? IsQueryable { get; set; }
///
public bool? IsOrderable { get; set; }
///
public bool? IsOpenChoice { get; set; }
}
///
/// Choice implementation.
///
public class Choice : IChoice
{
///
public string DisplayName { get; set; }
///
public IList Value { get; set; }
///
public IList> Choices { get; set; }
}
///
/// Boolean property definition implementation.
///
public class PropertyBooleanDefinition : PropertyDefinition, IPropertyBooleanDefinition
{
///
public IList DefaultValue { get; set; }
///
public IList> Choices { get; set; }
}
///
/// DataTime property definition implementation.
///
public class PropertyDateTimeDefinition : PropertyDefinition, IPropertyDateTimeDefinition
{
///
public IList DefaultValue { get; set; }
///
public IList> Choices { get; set; }
///
public DateTimeResolution? DateTimeResolution { get; set; }
}
///
/// Decimal property definition implementation.
///
public class PropertyDecimalDefinition : PropertyDefinition, IPropertyDecimalDefinition
{
///
public IList DefaultValue { get; set; }
///
public IList> Choices { get; set; }
///
public decimal? MinValue { get; set; }
///
public decimal? MaxValue { get; set; }
///
public DecimalPrecision? Precision { get; set; }
}
///
/// HTML property definition implementation.
///
public class PropertyHtmlDefinition : PropertyDefinition, IPropertyHtmlDefinition
{
///
public IList DefaultValue { get; set; }
///
public IList> Choices { get; set; }
}
///
/// ID property definition implementation.
///
public class PropertyIdDefinition : PropertyDefinition, IPropertyIdDefinition
{
///
public IList DefaultValue { get; set; }
///
public IList> Choices { get; set; }
}
///
/// Integer property definition implementation.
///
public class PropertyIntegerDefinition : PropertyDefinition, IPropertyIntegerDefinition
{
///
public IList DefaultValue { get; set; }
///
public IList> Choices { get; set; }
///
public BigInteger? MinValue { get; set; }
///
public BigInteger? MaxValue { get; set; }
}
///
/// String property definition implementation.
///
public class PropertyStringDefinition : PropertyDefinition, IPropertyStringDefinition
{
///
public IList DefaultValue { get; set; }
///
public IList> Choices { get; set; }
///
public BigInteger? MaxLength { get; set; }
}
///
/// URI property definition implementation.
///
public class PropertyUriDefinition : PropertyDefinition, IPropertyUriDefinition
{
///
public IList DefaultValue { get; set; }
///
public IList> Choices { get; set; }
}
///
/// Object Data implementation.
///
public class ObjectData : ExtensionsData, IObjectData
{
///
public string Id
{
get
{
return GetFirstValue(PropertyIds.ObjectId) as string;
}
}
///
public BaseTypeId? BaseTypeId
{
get
{
string baseTypeId = GetFirstValue(PropertyIds.BaseTypeId) as string;
if (baseTypeId == null)
{
return null;
}
return baseTypeId.GetCmisEnum();
}
}
///
public IProperties Properties { get; set; }
///
public IAllowableActions AllowableActions { get; set; }
///
public IList Relationships { get; set; }
///
public IChangeEventInfo ChangeEventInfo { get; set; }
///
public IAcl Acl { get; set; }
///
public bool? IsExactAcl { get; set; }
///
public IPolicyIdList PolicyIds { get; set; }
///
public IList Renditions { get; set; }
///
private object GetFirstValue(string id)
{
if (Properties == null) { return null; }
IPropertyData property = Properties[id];
if (property == null)
{
return null;
}
return property.FirstValue;
}
}
///
/// Object List implementation.
///
public class ObjectList : ExtensionsData, IObjectList
{
///
public IList Objects { get; set; }
///
public bool? HasMoreItems { get; set; }
///
public BigInteger? NumItems { get; set; }
}
///
/// Object In Folder Data implementation.
///
public class ObjectInFolderData : ExtensionsData, IObjectInFolderData
{
///
public IObjectData Object { get; set; }
///
public string PathSegment { get; set; }
}
///
/// Object In Folder List implementation.
///
public class ObjectInFolderList : ExtensionsData, IObjectInFolderList
{
///
public IList Objects { get; set; }
///
public bool? HasMoreItems { get; set; }
///
public BigInteger? NumItems { get; set; }
}
///
/// Object In Folder Container implementation.
///
public class ObjectInFolderContainer : ExtensionsData, IObjectInFolderContainer
{
///
public IObjectInFolderData Object { get; set; }
///
public IList Children { get; set; }
}
///
/// Object Parent Data implementation.
///
public class ObjectParentData : ExtensionsData, IObjectParentData
{
///
public IObjectData Object { get; set; }
///
public string RelativePathSegment { get; set; }
}
///
/// Properties implementation.
///
public class Properties : ExtensionsData, IProperties
{
private List propertyList = new List();
private Dictionary propertyDict = new Dictionary();
///
public IPropertyData this[string propertyId]
{
get
{
IPropertyData property = null;
propertyDict.TryGetValue(propertyId, out property);
return property;
}
}
///
/// Constructor.
///
public Properties() { }
///
/// Copy constructor.
///
/// source properties object
public Properties(IProperties properties)
{
if (properties == null)
{
throw new ArgumentNullException("properties");
}
AddProperties(properties.PropertyList);
Extensions = properties.Extensions;
}
///
public IList PropertyList
{
get
{
return propertyList;
}
}
///
/// Adds a collection of properties.
///
/// the collection of properties to add
protected void AddProperties(ICollection properties)
{
if (properties != null)
{
foreach (IPropertyData property in properties)
{
AddProperty(property);
}
}
}
///
/// Adds a property.
///
/// the property to add.
public void AddProperty(IPropertyData property)
{
if (property == null || property.Id == null)
{
return;
}
propertyList.Add(property);
propertyDict[property.Id] = property;
}
///
/// Replaces a property.
///
/// the property to replace
public void ReplaceProperty(IPropertyData property)
{
if (property == null || property.Id == null)
{
return;
}
RemoveProperty(property.Id);
propertyList.Add(property);
propertyDict[property.Id] = property;
}
///
/// Removes a property.
///
/// the ID of the property that should be removed
public void RemoveProperty(string id)
{
if (id == null)
{
return;
}
int idx = propertyList.FindIndex(pd => pd.Id == id);
if (idx > -1)
{
propertyList.RemoveAt(idx);
}
propertyDict.Remove(id);
}
///
public override string ToString()
{
StringBuilder sb = new StringBuilder();
foreach (IPropertyData prop in propertyList)
{
if (sb.Length == 0) { sb.Append("["); }
else { sb.Append(", "); }
sb.Append(prop.ToString());
}
sb.Append("]");
return sb.ToString();
}
}
///
/// Property Data implementation.
///
public class PropertyData : ExtensionsData, IPropertyData
{
private IList