Example #1
0
        private cmisTypeDefinitionType ToTypeDefinition(Kooboo.CMS.Content.Models.Schema schema, bool includePropertyDefinitions)
        {
            cmisTypeDefinitionType typeDefinition = new cmisTypeDocumentDefinitionType();

            //typeDefinition.baseId = BaseObjectTypeId.CmisDocument;
            typeDefinition.controllableACL    = false;
            typeDefinition.controllablePolicy = false;
            typeDefinition.creatable          = true;
            typeDefinition.description        = null;
            typeDefinition.displayName        = schema.Name;
            typeDefinition.fileable           = true;
            typeDefinition.fulltextIndexed    = false;
            typeDefinition.id = schema.Name;
            typeDefinition.includedInSupertypeQuery = false;
            typeDefinition.localName      = schema.Repository.Name;
            typeDefinition.localNamespace = null;
            typeDefinition.parentId       = null;
            typeDefinition.queryable      = true;
            typeDefinition.queryName      = schema.Name;
            //typeDefinition.ContentStreamAllowed = ContentStreamAllowed.Allowed;
            if (includePropertyDefinitions)
            {
                typeDefinition.Items = DefaultDefinitionTypes(schema).Concat(schema.AllColumns.Select(it => ToPropertyDefinition(schema, it)).Where(it => it != null)).ToArray();
            }

            return(typeDefinition);
        }
Example #2
0
        private cmisPropertyDefinitionType ToPropertyDefinition(Kooboo.CMS.Content.Models.Schema schema, Kooboo.CMS.Content.Models.Column column)
        {
            cmisPropertyDefinitionType def = null;

            #region Create PropertyDefinition object

            switch (column.DataType)
            {
            case Kooboo.CMS.Common.DataType.Int:
                var intDef = new cmisPropertyIntegerDefinitionType();

                if (!string.IsNullOrEmpty(column.DefaultValue))
                {
                    int defaultValue;
                    if (int.TryParse(column.DefaultValue, out defaultValue))
                    {
                        intDef.defaultValue = new cmisPropertyInteger()
                        {
                            value = new[] { defaultValue.ToString() }
                        };
                    }
                }
                if (column.SelectionItems != null)
                {
                    int value;
                    intDef.choice = column.SelectionItems.Where(it => int.TryParse(it.Value, out value))
                                    .Select(it => new { it.Text, Value = int.Parse(it.Value) }).Select(it => new cmisChoiceInteger()
                    {
                        displayName = it.Text,
                        value       = new[] { it.Value.ToString() }
                    }).ToArray();

                    intDef.openChoice = intDef.choice.Length > 0;
                }
                def = intDef;
                def.propertyType = enumPropertyType.integer;
                break;

            case Kooboo.CMS.Common.DataType.Decimal:
                var decDef = new cmisPropertyDecimalDefinitionType();

                if (!string.IsNullOrEmpty(column.DefaultValue))
                {
                    decimal defaultValue;
                    if (decimal.TryParse(column.DefaultValue, out defaultValue))
                    {
                        decDef.defaultValue = new cmisPropertyDecimal()
                        {
                            value = new[] { defaultValue }
                        };
                    }
                }
                if (column.SelectionItems != null)
                {
                    decimal value;
                    decDef.choice = column.SelectionItems.Where(it => decimal.TryParse(it.Value, out value))
                                    .Select(it => new { it.Text, Value = decimal.Parse(it.Value) }).Select(it => new cmisChoiceDecimal()
                    {
                        displayName = it.Text,
                        value       = new decimal[] { it.Value }
                    }).ToArray();
                    decDef.openChoice = decDef.choice.Length > 0;
                }
                def = decDef;
                def.propertyType = enumPropertyType.@decimal;
                break;

            case Kooboo.CMS.Common.DataType.DateTime:

                var dateTimeDef = new cmisPropertyDateTimeDefinitionType();

                if (!string.IsNullOrEmpty(column.DefaultValue))
                {
                    DateTime defaultValue;
                    if (DateTime.TryParse(column.DefaultValue, out defaultValue))
                    {
                        dateTimeDef.defaultValue = new cmisPropertyDateTime()
                        {
                            value = new DateTime[] { defaultValue }
                        };
                    }
                }
                if (column.SelectionItems != null)
                {
                    DateTime value;
                    dateTimeDef.choice = column.SelectionItems.Where(it => DateTime.TryParse(it.Value, out value))
                                         .Select(it => new { it.Text, Value = DateTime.Parse(it.Value) }).Select(it => new cmisChoiceDateTime()
                    {
                        displayName = it.Text,
                        value       = new DateTime[] { it.Value }
                    }).ToArray();
                    dateTimeDef.openChoice = dateTimeDef.choice.Length > 0;
                }
                def = dateTimeDef;
                def.propertyType = enumPropertyType.datetime;
                break;

            case Kooboo.CMS.Common.DataType.Bool:
                var boolDef = new cmisPropertyBooleanDefinitionType();

                if (!string.IsNullOrEmpty(column.DefaultValue))
                {
                    bool defaultValue;
                    if (bool.TryParse(column.DefaultValue, out defaultValue))
                    {
                        boolDef.defaultValue = new cmisPropertyBoolean()
                        {
                            value = new bool[] { defaultValue }
                        };
                    }
                }
                if (column.SelectionItems != null)
                {
                    bool value;
                    boolDef.choice = column.SelectionItems.Where(it => bool.TryParse(it.Value, out value))
                                     .Select(it => new { it.Text, Value = bool.Parse(it.Value) }).Select(it => new cmisChoiceBoolean()
                    {
                        displayName = it.Text,
                        value       = new bool[] { it.Value }
                    }).ToArray();

                    boolDef.openChoice = boolDef.choice.Length > 0;
                }
                def = boolDef;
                def.propertyType = enumPropertyType.boolean;
                break;

            case Kooboo.CMS.Common.DataType.String:
            default:
                var strDef = new cmisPropertyStringDefinitionType();
                strDef.maxLength = column.Length.ToString();
                if (!string.IsNullOrEmpty(column.DefaultValue))
                {
                    strDef.defaultValue = new cmisPropertyString()
                    {
                        value = new string[] { column.DefaultValue }
                    };
                }
                if (column.SelectionItems != null)
                {
                    strDef.choice = column.SelectionItems.Select(it => new cmisChoiceString()
                    {
                        displayName = it.Text,
                        value       = new string[] { it.Value }
                    }).ToArray();
                    strDef.openChoice = strDef.choice.Length > 0;
                }
                def = strDef;
                def.propertyType = enumPropertyType.@string;
                break;
            }
            #endregion

            if (def != null)
            {
                def.cardinality    = enumCardinality.single;
                def.description    = column.Tooltip;
                def.displayName    = column.Label;
                def.id             = column.Name;
                def.inherited      = false;
                def.localName      = column.Name;
                def.localNamespace = null;
                def.orderable      = true;
                def.queryable      = true;
                def.queryName      = column.Name;
                def.required       = !column.AllowNull;
                def.updatability   = enumUpdatability.readwrite;
            }
            return(def);
        }
Example #3
0
        private IEnumerable <cmisPropertyDefinitionType> DefaultDefinitionTypes(Kooboo.CMS.Content.Models.Schema schema)
        {
            yield return(new cmisPropertyStringDefinitionType()
            {
                id = CmisPropertyDefinitionId.BaseTypeId,
                localName = CmisPropertyDefinitionId.BaseTypeId,
                propertyType = enumPropertyType.@string,
                cardinality = enumCardinality.single,
                inherited = false,
                orderable = true,
                queryable = true,
                required = true,
                updatability = enumUpdatability.readwrite
            });

            yield return(new cmisPropertyStringDefinitionType()
            {
                id = CmisPropertyDefinitionId.ObjectTypeId,
                localName = "SchemaName",
                propertyType = enumPropertyType.@string,
                cardinality = enumCardinality.single,
                inherited = false,
                orderable = true,
                queryable = true,
                required = true,
                updatability = enumUpdatability.readwrite
            });

            yield return(new cmisPropertyStringDefinitionType()
            {
                id = CmisPropertyDefinitionId.CreatedBy,
                localName = "UserId",
                propertyType = enumPropertyType.@string,
                cardinality = enumCardinality.single,
                inherited = false,
                orderable = true,
                queryable = true,
                required = true,
                updatability = enumUpdatability.readwrite
            });

            yield return(new cmisPropertyDateTimeDefinitionType()
            {
                id = CmisPropertyDefinitionId.CreationDate,
                localName = "UtcCreationDate",
                propertyType = enumPropertyType.datetime,
                cardinality = enumCardinality.single,
                inherited = false,
                orderable = true,
                queryable = true,
                required = true,
                updatability = enumUpdatability.readwrite
            });

            yield return(new cmisPropertyDateTimeDefinitionType()
            {
                id = CmisPropertyDefinitionId.LastModificationDate,
                localName = "UtcLastModificationDate",
                propertyType = enumPropertyType.datetime,
                cardinality = enumCardinality.single,
                inherited = false,
                orderable = true,
                queryable = true,
                required = true,
                updatability = enumUpdatability.readwrite
            });

            yield return(new cmisPropertyStringDefinitionType()
            {
                id = CmisPropertyDefinitionId.Name,
                localName = "UserKey",
                propertyType = enumPropertyType.@string,
                cardinality = enumCardinality.single,
                inherited = false,
                orderable = true,
                queryable = true,
                required = true,
                updatability = enumUpdatability.readwrite
            });

            yield return(new cmisPropertyStringDefinitionType()
            {
                id = CmisPropertyDefinitionId.ObjectId,
                localName = "UUID",
                propertyType = enumPropertyType.@string,
                cardinality = enumCardinality.single,
                inherited = false,
                orderable = true,
                queryable = true,
                required = true,
                updatability = enumUpdatability.readwrite
            });


            yield return(new cmisPropertyStringDefinitionType()
            {
                id = CmisPropertyDefinitionId.ParentId,
                localName = "parentUUID",
                propertyType = enumPropertyType.@string,
                cardinality = enumCardinality.single,
                inherited = false,
                orderable = true,
                queryable = true,
                required = true,
                updatability = enumUpdatability.readwrite
            });
        }