Problem with setting integer custom property when uploading document Using CMIS

cancel
Showing results for 
Search instead for 
Did you mean: 
santolovic
Active Member

Problem with setting integer custom property when uploading document Using CMIS

Jump to solution

While uploading document to Alfresco Content services using CMIS we are passing Metadata as Alfresco Custom Properties along with it. All Custom propertis are being accepted and document content uploaded, but values for some custom properties are not being set. Their values are shown as none. For example custom properties such as string, DateTime and long are bein set along with their values, but Custom property value for int (integer) is not being set in ACS(value is shown as (None).

1 Solution

Accepted Solutions
santolovic
Active Member

Re: Problem with setting integer custom property when uploading document Using CMIS

Jump to solution

I have found solution and you can see it in source code I have sent in previous post. I converted C# property to type long instead of  int and pass it to Alfresco property which is (in Alfresco Content service model) type of int.

View solution in original post

3 Replies
angelborroy
Alfresco Employee

Re: Problem with setting integer custom property when uploading document Using CMIS

Jump to solution

Can you share some source code?

The description of your problem doesn't fit with any other issue related with CMIS I've heard of before...

Hyland Developer Evangelist
santolovic
Active Member

Re: Problem with setting integer custom property when uploading document Using CMIS

Jump to solution
public static AlfrescoSearchItem UploadDocument(string fileName, string filePath, string nodeName, SaveVersion version = null)
        { 
IDocument remoteDocument = null;

                IOperationContext oc = session.CreateOperationContext();
                oc.IncludeAcls = true;

                IFolder folder = session.GetRootFolder(oc);

                folder = (IFolder)session.GetObject(nodeName);

                IDictionary<string, object> properties = new Dictionary<string, object>();
                properties.Add(alfObjectType, $"D:{alfModelPrefix}:{alfModelType}");
                properties.Add(PropertyIds.Name, fileName);
                foreach (var prop in version.VersionProperties)
                {
                    if (!(prop.Name == DMS.pathMetaData))
                    {
                        SetAlfrescoProperty(prop, properties);
                    }
                }

                ContentStream contentStream = new ContentStream();
                contentStream.FileName = fileName;
                contentStream.MimeType = System.Web.MimeMapping.GetMimeMapping(fileName);
                contentStream.Stream = System.IO.File.OpenRead(filePath);

                remoteDocument = folder.CreateDocument(properties, contentStream, null);
}

 private static void SetAlfrescoProperty(VersionProperty prop, IDictionary<string, object> properties)
        {

            var alfrescoPropName = mappingProps.Where(x => x.CTXPropName == prop.Name).Select(x => x.AlfrescoPropName).FirstOrDefault();
            var alfrescoPropType = mappingProps.Where(x => x.CTXPropName == prop.Name).Select(x => x.PropTypeName).FirstOrDefault();
            switch (alfrescoPropType)
            {
                case "int":
                    long intConverted;
                    if (long.TryParse(prop.Value, out intConverted))
                    {
                        properties.Add(alfrescoPropName, intConverted);
                    }
                    else
                    {
                        var exc = new Exception($"Bad 'int' format in File property: {prop.Name} with value={prop.Value}");
                        exc.Data.Add(prop.Name.ToString(), prop.Value.ToString());
                        throw exc;

                    }
                    break;
                case "float":
                    float floatConverted;
                    if (float.TryParse(prop.Value, out floatConverted))
                    {
                        properties.Add(alfrescoPropName, floatConverted);
                    }
                    else
                    {
                        var exc = new Exception($"Bad 'float' format in File property: {prop.Name} with value={prop.Value}");
                        exc.Data.Add(prop.Name.ToString(), prop.Value.ToString());
                        throw exc;
                    }
                    break;
                case "long":
                    long longConverted;
                    if (long.TryParse(prop.Value, out longConverted))
                    {
                        properties.Add(alfrescoPropName, longConverted);
                    }
                    else
                    {
                        var exc = new Exception($"Bad 'long' format in File property: {prop.Name} with value={prop.Value}");
                        exc.Data.Add(prop.Name.ToString(), prop.Value.ToString());
                        throw exc;
                    }

                    break;
                case "double":
                    double doubleConverted;
                    if (double.TryParse(prop.Value, out doubleConverted))
                    {
                        properties.Add(alfrescoPropName, doubleConverted);
                    }
                    else
                    {
                        var exc = new Exception($"Bad 'double' format in File property: {prop.Name} with value={prop.Value}");
                        exc.Data.Add(prop.Name.ToString(), prop.Value.ToString());
                        throw exc;
                    }
                    break;
                case "dateTime":
                    DateTime dateTimeconverted;
                    if (DateTime.TryParse(prop.Value, out dateTimeconverted))
                    {
                        properties.Add(alfrescoPropName, dateTimeconverted);
                    }
                    else
                    {
                        var exc = new Exception($"Bad 'DateTime' format in File property: {prop.Name} with value={prop.Value}");
                        exc.Data.Add(prop.Name.ToString(), prop.Value.ToString());
                        throw exc;
                    }
                    break;
                case "boolean":
                    bool boolConverted;
                    if (bool.TryParse(prop.Value, out boolConverted))
                    {
                        properties.Add(alfrescoPropName, boolConverted);
                    }
                    else
                    {
                        var exc = new Exception($"Bad 'boolean' format in File property: {prop.Name} with value={prop.Value}");
                        exc.Data.Add(prop.Name.ToString(), prop.Value.ToString());
                        throw exc;
                    }
                    break;
                default:
                    properties.Add(alfrescoPropName, prop.Value);
                    break;
            }
        }
santolovic
Active Member

Re: Problem with setting integer custom property when uploading document Using CMIS

Jump to solution

I have found solution and you can see it in source code I have sent in previous post. I converted C# property to type long instead of  int and pass it to Alfresco property which is (in Alfresco Content service model) type of int.