Open CMIS and Java Upload for Custom Types

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

Open CMIS and Java Upload for Custom Types

Just downloaded latest community edition. Installed fine, UI working, documents uploading etc.

Figured out how to use the Model Manager to create a ‘model’ called ‘Document’. Within this model I created a ‘custom type’ called ‘dcSmiley TongueCN’ with a display name of ‘PCN’. Against the custom type I created 2 properties both with a datatype of ‘text’.

In the web UI, in the ‘Repository’ I can upload a file. I can then navigate to the new file, and change the type to the custom type I just created i.e. PCN. I can then see that the properties panel changes and I can populate these metadata fields as needed.

My question relates to how I do this via CMIS. In Java I have been able to code a connector to IBM FileNet and upload a file. For this I use this property something like :-

props.put(PropertyIds.OBJECT_TYPE_ID, “cmisSmiley TongueCN”)

This works fine. However for Alfresco it doesn’t. If I set it to use the returned queryName for the custom type returned in a list from session.getTypeChildren("cmis:document”, true) i.e. dcSmiley TongueCN

props.put(PropertyIds.OBJECT_TYPE_ID, “dcSmiley TongueCN”)

If fails saying CmisObjectNotFoundException Type ‘dcSmiley TongueCN’ is unknown!

However I can get the file to upload successfully if I use the base:-

props.put(PropertyIds.OBJECT_TYPE_ID, “cmis:document”)

Issue is there is no metadata fields associated as this is the base class.

So my question, what props do I need to set for me to be able to set the custom type of my file to PCN and map the metadata properties to it.

7 Replies
angelborroy
Expert

Re: Open CMIS and Java Upload for Custom Types

Jeff Potts‌ gathered a collection resources on CMIS: CMIS Resource Center | ECM Architect 

To upload an create custom content types in Alfresco, refer Working With Custom Content Types in Alfresco | ECMArchitect | Alfresco Developer Tutorials 

Software Engineer in Alfresco Search Team.
bendavies
Active Member

Re: Open CMIS and Java Upload for Custom Types

Thanks Angel BorroyI had actually looked at this documentation, but negated to notice the presence of the 'D:' to denote document.

So for anyone else out there who hits this issue in Alfresco, remember to add 'D:' i.e. :-

props.put(PropertyIds.OBJECT_TYPE_ID, “D:dcSmiley TongueCN”)

Many thanks.

jpotts
Advanced II

Re: Open CMIS and Java Upload for Custom Types

Thanks for the links, Angel. Glad it seems to have helped, Ben!

bendavies
Active Member

Re: Open CMIS and Java Upload for Custom Types

Thanks to all. Great to see the community works well. I have now completed coding the upload using OpenCMIS apart from the issue below. Thanks for the help here.

Honestly, I'm not sure if this is the right place to post for all the issues here, but I do think one relates to the upload via OpenCMIS. Wondering if any of you have any pearls of wisdom here?

In Chrome the PDF I upload via OpenCMIS looks fine. I can open the PDF whether it has come via OpenCMIS or browser upload. However in both Firefox and the latest iOS mobile app I have issues rendering the document.

For Firefox it happens all the time regardless of how I upload. It complains about 'Having no PDF content'. It then jumps to a Google Docs page. This happens whether I upload using Open CMIS or the browser upload functionality. See screen shot below. I therefore think this isn't OpenCMIS related, more browser specific so lets park that for now.

However, on iOS Alfresco App I can render PDFs that have been uploaded via the web browser, but those I uploaded via OpenCMIS return a grey background with the file name i.e. 'Penalty Charge Notice {Rest of File Name} pm data' (see screen shot). This happens whether I use a custom type or not. So any PDF I upload with OpenCMIS will not render in the app. FYI - If I take the same file that was uploaded via OpenCMIS and upload manually via web UI, it works fine. It still works if then manually 'Change Type' in the web UI to the same one I am setting via CMIS upload. So its not a PDF issue.

This leads me to think I am missing something when I do the upload on OpenCMIS for the iOS rendering issue.

FYI I use the following to create the content stream, so the MIME should be set fine. I did a debug and its definitely setting this to 'application/pdf' :

ContentStream contentStream = s.getObjectFactory().createContentStream(
                    tmpDocFile.getName(),
                    tmpDocFile.length(),
                    MimeTypes.getMIMEType(tmpDocFile),
                    inputStream
            );

Do a need to change or add to the properties I am using.

Chrome v70.0.3538.102 (Official Build) (64-bit) on Mac OS 10.12.6 (Sierra).

Firefox v63.0.3 (64-bit) on Mac OS 10.12.6 (Sierra).

Mobile Apple iOS 11.4.1 (15G77) with Alfresco App v2.6.

  

angelborroy
Expert

Re: Open CMIS and Java Upload for Custom Types

When a document is uploaded to Alfresco using Share client, a rendition in PDF format is generated. However, if you are using CMIS to upload documents, that rendition to PDF is not fired.

There are different approaches to solve this issue. Probably easier is to configure an Alfresco Rule in the repository to Transform and Copy Contents to PDF every time a new document is uploaded from CMIS Client.

Software Engineer in Alfresco Search Team.
bendavies
Active Member

Re: Open CMIS and Java Upload for Custom Types

Thanks. Very new to Alfresco. Any guidance or documentation you could point me to on how to do this would be appreciated.

angelborroy
Expert

Re: Open CMIS and Java Upload for Custom Types

You can define rules on a folder by using Alfresco Share web app.

Defining rules for a folder | Alfresco Documentation 

Software Engineer in Alfresco Search Team.