9 Jan 2012
Alfresco tutorial: Custom content types including Share config and CMIS
It is hard to believe that the original version of my “Working With Custom Content Types” tutorial for Alfresco is almost five years old. That page has had over 37,000 unique visits since it was posted. It makes sense that it would be popular–creating a content model, exposing it to the user interface, and then performing CRUD functions against the repository through code are the first steps for most Alfresco development projects.
The fundamentals of content modeling haven’t changed since 2007, but since the original tutorial was posted the Alfresco Share web client has replaced Alfresco Explorer as the preferred user interface and the Content Management Interoperability Services (CMIS) API has become the first choice for writing remote code against the repository. That, combined with the influx of newcomers to the platform and a continued demand for how-to’s on the basics motivated me to revise the tutorial.
The second edition moves the Alfresco Explorer configuration to the Appendix and replaces it with steps for doing the same thing in Alfresco Share. I also moved the Java Web Services API to the Appendix and replaced that with Java examples that leverage the Apache Chemistry OpenCMIS API to create, update, query, and delete content in the repository. I’m executing the same queries as the first edition, just implemented using CMIS, so if you want to compare Lucene queries to CMIS Query Language, this is one place to do it.
I tested the document and the code against Alfresco 4.0.c Community. It may work on earlier versions, but no promises. It will probably work on Alfresco 4.0 Enterprise when it becomes available.
My goal is to revise the rest of the Alfresco Developer Series tutorials for Alfresco 4 over the next month or two so stay tuned.


[...] I’ve recently published a second edition of this tutorial that updates the original with Alfresco Share and [...]
[...] code that accompanies the tutorial builds on the content types tutorial, so it includes the SomeCo content model and the user interface configuration needed to expose that [...]
Hi jeff,
thanks for great tutorial,
I downloaded the code of your example, I changed my settings using build.properties file:
# Used by the CMIS Web Services and examples
alfresco.sdk.dir = C :/ Documents and Settings/silverio.giancristof/workspace/alfresco-sdk-4.0.b
# Used by the content model, Explorer config, config examples and Share
alfresco.webapp.dir = C :/ tomcat/Instance1/webapps/alfresco
share.webapp.dir = C :/ tomcat/Instance1/webapps/share
But nothing happens on Alfresco that I do not see the changes when i try change type in any document. What is wrong?
Silverio,
Did you run “ant deploy” after changing the settings in build.properties? If so, go look in your Alfresco and Share webapps. In $TOMCAT_HOME/webapps/alfresco you should see the unpacked WAR. Within that, you should see an extension directory under $TOMCAT_HOME/webapps/alfresco/WEB-INF/classes/alfresco that contains things like the model directory, web-client-config-custom.xml, etc. Over in $TOMCAT_HOME/webapps/share you should see the unpacked Share WAR. Within that, you should see a web-extension directory under $TOMCAT_HOME/webapps/share/WEB-INF/classes/alfresco that contains share-config-custom.xml.
If those are missing, something is wrong with your build. If those are there but the custom types aren’t showing up, try restarting Tomcat and watching the log for errors that might give you a hint as to what is wrong.
Jeff
Hi Jeff,
on eclipse i make right click on build.xml and run ant and i see BUILD SUCCESSFUL, but i don’t see unpacked Share WAR in $TOMCAT_HOME/webapps/share
Sorry sorry Jeff, i’m stupid man
,
I have deployed and now I see the directories added.
Thanks a lot.
Great tutorial!
Just a question.. i created a new content model but i cant hide any properties of the original cm:content from which i derived my own model (title or description). Hide option in share-config-custom.xml doesnt work for me.
Any suggestion?
Thanks in advance
Daniele,
Have you tried adding a form config to share-config-custom.xml and removing the “show” element and the “field” element for the properties you want to hide?
Jeff
Hi Jeff,
I followed your tutorial and had no problem until Localizing Strings part. After restarting tomcat, Share can’t be loaded (HTTP Status 404). I think I don’t see any errors in log.
When I removed the custom-slingshot-application-context.xml file, Share is back to normal.
many thanks Jeff, just the sort of tutorial I needed to get a handle on the flexibility of Alfresco and whether it suits our organisation.
Really appreciate your accuracy and ‘down to earth’ descriptions.
All seems fine in 4.0.d
cheers
Hi Jeff,
Great tutorial, thanks.
I have a quick question — I’m trying to setup a peer association with a piece of custom content that represents an internal legal entity.
With the association picker, I am able to click “select” and choose an association of that type. However, I can’t actually browse with the association picker itself — I can only pick content of the appropriate type if it’s in the folder that the association picker opens in.
I’ve implemented a {doclib} tag, which allows me to start in a certain place and choose entities in the top-level of the doclib, but I’m obviously missing something because I can’t “browse” to that location as I would expect. No amount of double clicking helps.
This manifests itself in Chrome and IE.
Any thoughts?
Thanks,
Chris
Ah-ha! Solved the above! After much hand-wringing, I think this was possibly because I had a mismatched version of alfresco between my tomcat and alfresco instances. Whoops.
Hi Jeff,
I read your article and you wrote about many ways to modify Share interface to use new content type but haven’t mentioned “Create content” function.
My question is “Is it possible to add newly created content type and add it inside Create content menu and create it with dummy Word document or PDF as a content?”.
I tried to add function of creating basic cm:content node with word document as a mime type but it fails. It creates node but mime type of document is Undefined. Creating google documents works but I’m not sure how to use that with my custom content type.
Thank you,
John
Thankx for your article
but i tried your examples it’s working fine on alfresco webclient
but when i run the examples classes
i got an exception
——————————————————————————–
Finding content of type:doc
Exception in thread “main” org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException: 04300068 Request failed 500 /solr/alfresco/cmis?q=select+*+from+sc%3Adoc&wt=json&fl=*%2Cscore&rows=100&df=TEXT&start=0&locale=en_US&fq=%7B%21afts%7DAUTHORITY_FILTER_FROM_JSON&fq=%7B%21afts%7DTENANT_FILTER_FROM_JSON
at org.apache.chemistry.opencmis.client.bindings.spi.atompub.AbstractAtomPubService.convertStatusCode(AbstractAtomPubService.java:452)
at org.apache.chemistry.opencmis.client.bindings.spi.atompub.AbstractAtomPubService.post(AbstractAtomPubService.java:570)
at org.apache.chemistry.opencmis.client.bindings.spi.atompub.DiscoveryServiceImpl.query(DiscoveryServiceImpl.java:142)
at org.apache.chemistry.opencmis.client.runtime.SessionImpl$3.fetchPage(SessionImpl.java:557)
at org.apache.chemistry.opencmis.client.runtime.util.AbstractIterator.getCurrentPage(AbstractIterator.java:132)
at org.apache.chemistry.opencmis.client.runtime.util.CollectionIterator.hasNext(CollectionIterator.java:48)
at com.someco.cmis.examples.SomeCoCMISDataQueries.getQueryResults(SomeCoCMISDataQueries.java:106)
at com.someco.cmis.examples.SomeCoCMISDataQueries.doExamples(SomeCoCMISDataQueries.java:47)
at com.someco.cmis.examples.SomeCoCMISDataQueries.main(SomeCoCMISDataQueries.java:35)
—————————————————————————-
im using Alfresco Version :Community – v4.0.0 (4003)
on windows 7
any solution for this?
thanks you
Hi Jeff,
I have the same question as John Scarab about the create
content menu and adding custom types to this. Can you give
an guidance on how to do this in Alfresco 4 Share.
Thanks for all the great insights into Alfresco,
Jon
Hi,
The advanced search part doesn’t work on 4.0.d.
Log contains lines like “DEBUG [org.alfresco.repo.forms.processor.node.TypeFormProcessor] Ignoring unrecognised field “sc:product”
The generated query contains the custom fields as e.g. “sc_product” not as “prop_sc_product” and hence querying for special fields doesn’t return values.
Do you have an idea how to fix this?
Thanks,
Alex
Hi,
I need help for preview for content model.I am using alfresco 4.0.2.0 enterprise trial version.While I create my custom type,the preview is not reading my content as I use d:text instead of d:content.I read some of the comments that web preview/preview is hardcoded for content type.Can anybody help me how to customize the preview for my custom type insetad of default content type.
sradha,
You should search the Alfresco Forums for other topics related to this and if they don’t answer your question, create a new topic.
Jeff
Jeff,
Thanks for this excellent article! Unfortunately, I have found the Alfresco web documentation rather difficult to follow. I was not able to use any of the documentation on the Alfresco website to understand how to set up my own content model. However, your article on custom content models got me up and running in a day, with a much better understanding of how these things work!
Naturally, having built my own basic custom content model following your example, I now have some questions about taking this further:
- Does Alfresco support dependent property constraints? e.g. the values available in one constraint depend on the value selected for a previous constraint.
- Similar to the above… Can I have dynamic metadata forms in Alfresco? e.g. the properties shown depend on values selected for prior properties. I have a “my:filetype” property that is constrained to “document” or “image”. When I set the value to “document”, the form shows the “my:doctype” property, from which I can select “final report”, or “guideline”. When I set the value to “image”, the form shows the “my:imagetype” property.
- How do I report a bug I found when commas are used in LIST constraints?
Thanks so much! I’m glad it helped.
Not out-of-the-box but you can add this yourself with custom form components and client-side JavaScript.
Not out-of-the-box, see previous answer.
Go to http://issues.alfresco.com. Before you create a new bug, make sure you can reproduce it on an out-of-the-box installation (with your custom list constraint, of course) and attach your model any client configuration files you’ve created, screenshots, and a description of the problem.
Jeff
Hi Jeff
the tutorial was great, thank you.
I was wondering if with Share it is still possible to create dynamic custom model.
We would be able to create/edit new models without restarting Alfresco and based on this wiki page
http://wiki.alfresco.com/wiki/Data_Dictionary_Guide#Step_by_Step_Model_Definition
the old Alfresco interface allows us to do that.
Does it work for Share?
if so, Is there any wiki page saying where to place Share config files under Alfresco repository folders?
thank you
you can find here the correct wiki page
http://wiki.alfresco.com/wiki/Dynamic_Models
Share and the old Explorer web application use the same repository so when you create a dynamic model using the approach you referenced, Share can leverage it. The model goes in the same folder as identified in that wiki page–when you go to the Repository view you are seeing the exact same folder structure that exists if you were to log in to the Alfresco Explorer UI.
The trick is that when you do a hot-deployed model on the explorer side, there is a UI console used to refresh your custom web client XML configuration file. I don’t believe that exists on the Share side. However, starting with 4.0 (I think) there is the concept of modules (not to be confused with modules deployed using the MMT). I haven’t tried it, but you might be able to hot-deploy your content model and then hot-deploy a Share module that adds in the custom forum configuration you need to display your model.
You also might take a look at the form management add-on and see if it helps you at all.
I don’t have time to look at this issue in depth any time soon so if you poke around and find enlightenment, please be sure to come back and share it.
Jeff
The form management add on doesn’t seem to set the visibility of the forms that it creates in share, unfortunately.
The tutorial on modules http://blogs.alfresco.com/wp/ddraper/2011/07/22/how-to-add-content-to-an-alfresco-share-page/ also seemed to suggest that you need to deploy a jar containing the configuration and restart the server before the module was displayed on the “hot deploy” page http://localhost:8081/share/service/modules/deploy . Is there a way I can add module configuration to the repository instead of on the server so that I can hot deploy it?
Hi Jeff,
I have Alfresco Community 3.4.d and I followed your instructions to create two metadata fields but I’m not able to create an advanced search for them because they are not shown in the advanced search form.
How can I do it?
Hi Jeff,
I am using alfresco 4.2.a on windows 7. I have compiled your example code. when running:
java SomeCoCMISDataCreate I get an exception with root folder. I creaated a forlder as C:\alfrescotest and used as root. What is the right value for “root folder” .
Thanks
Hassan,
Sorry that it isn’t clear. The root folder the class wants passed in as an argument is the root folder in the Alfresco repository where it will create test data. So, for example, you might create a folder in the root of the repository (using Alfresco Explorer or Alfresco Share or a CMIS client of some sort) called “cmis-demo”. That’s the name of the folder you’ll pass in to the class.
Jeff
Hi jeff . Great Work!!!!!!!
i have created one custom content model has one doc type along with some properties. Now i want to view see these properties after uploading the document in to the share repository. I want this without applying rule to space or manully i.e using Change Type.
Is it possible through configuring in share-config-custom.xml? Is it possible the how?
[...] ecmarchitect.com [...]
satish,
The most common way to do this is by configuring a rule on a folder that runs the “specialize type” action.
Jeff
Hi, I tryed your code from second edition of custom model creation – and it dosen’t work with share 4.2.c. I can see aspects in web client but in share there is nothing.
Hi Jeff,
Do you have any turorial or guide on how add custom content type in Create-Content menu in Share and start using it? I have followed your article and created custom content type and added definition in “share-documentlibrary-config.xml” to display in “Create Content Menu” but after creating content its not taking the Mimetype that I specified.
Please help me…
Raj
Is there a change to version 4.2 of Alfresco that affects the display of custom types and aspects in folder rules? Following your guide in a previous version (4.0.e) worked fine, but in 4.2.c the new types and aspect don’t show up in the rules form.
I also noticed that it only works if you use the share-config-custom.xml which is placed within tomcat/shared/classes/alfresco/web-extension and not in the tomcat/webaps/share/WEB-INF/classes/alfresco/web-extension.
Thanx.
can you please tell me how to retrive data from alfresco repository with some source code
Jagadish,
Did you read the tutorial referenced in this blog post? It contains the answer.
Jeff