Alfresco tutorial: Custom content types including Share config and CMIS

UPDATE (2014): I’ve moved the tutorial and the source code to GitHub. The HTML version of the tutorial is here. It has been updated for Maven and AMPs.

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 %

51 comments

  1. Cheers says:

    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?

  2. jpotts says:

    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

  3. Cheers says:

    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

  4. Daniele says:

    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

  5. jpotts says:

    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

  6. Supta says:

    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.

  7. chris says:

    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

  8. Chris Clearfield says:

    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

  9. Chris Clearfield says:

    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. 🙂

  10. John Scarab says:

    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

  11. Malek says:

    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

  12. Jon Morgan says:

    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

  13. Alex says:

    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

  14. sradha says:

    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.

  15. Brian says:

    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?

  16. jpotts says:

    Thanks so much! I’m glad it helped.

    – Does Alfresco support dependent property constraints? e.g. the values available in one constraint depend on the value selected for a previous constraint.

    Not out-of-the-box but you can add this yourself with custom form components and client-side JavaScript.

    – Similar to the above… Can I have dynamic metadata forms in Alfresco? e.g. the properties shown depend on values selected for prior properties.

    Not out-of-the-box, see previous answer.

    – How do I report a bug I found when commas are used in LIST constraints?

    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

  17. Tatiana says:

    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

  18. jpotts says:

    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

  19. Amy says:

    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?

  20. Francesc Arbó says:

    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?

  21. Hassan Guled says:

    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

  22. jpotts says:

    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

  23. satish says:

    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?

  24. jpotts says:

    satish,

    The most common way to do this is by configuring a rule on a folder that runs the “specialize type” action.

    Jeff

  25. Pawel says:

    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.

  26. Raj says:

    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

  27. Vassilis says:

    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.

  28. Rutaveej Shah says:

    Hi jeff!
    I am using alfresco share.Currently using alfresco community edition.I am created a new content type such as docuemnt no.I want that at the time of upload the document no should be automatically generated.
    What should i do for that?

  29. jpotts says:

    Rutaveej,

    I am not clear on what you are trying to do. It sounds like you have created a new content type. You would like documents to be specialized to that type automatically when they are uploaded. If that is the case, the easiest thing to do is to create a rule on the folder. Set the rule action to “Specialize Type” and choose your custom type from the list of types. If your type isn’t in the list, go back and look at the custom types tutorial.

    Jeff

  30. Rutaveej says:

    Hi jeff!
    Thank you for last time reply.
    I am using alfresco share.
    I am creating a new content model.There are some properties in new content model.Now i want that when user upload the file after clicking on the upload file button the “Edit Properties” form should be pop up and after filling that properties file should be uploaded.What should i do for that?

    Please provide idea on this.

    Thank you in advance.

  31. Simon says:

    Hey Jeff,

    Thanks for the great tutorial. I’m somehow can’t seem to get the custom content to show up in share. I have followed your instructions to the letter, putting the model and the model-context files in tomcat\webapps\alfresco\WEB-INF\classes\alfresco\extension and the share-config-custom file in tomcat\webapps\share\WEB-INF\classes\alfresco\web-extension.

    I can only see the added types in the “select property” dialog in the “create rule” menu as seen here http://imgur.com/KXR3wqQ and in the “advanced search” menu.

    I’m using 4.2.c and i know some people have had trouble adding custom types in that version. Have you got any suggestions as to what i could do to fix this problem? Thanks again for the tutorial

  32. jpotts says:

    Simon,

    I only recently tested the workflow tutorial on 4.2.c and found a problem, which I’ve fixed. I’ll test out the custom content types tutorial on 4.2.c as soon as I can (maybe later today) to make sure that everything works as I expect. If it works for me we’ll move on to troubleshooting your specific case.

    If you have fixed it since posting let me know what the problem was.

    Jeff

  33. Simon says:

    Hello again,

    I got it to work on a different alfresco server whose version is also 4.2.c. It would appear the problem is specific to my case. I still can’t figure it out though. Most likely i’ll end up scrapping the original server, but if you’ve found anything please let me know. Thanks again

  34. jpotts says:

    I tested the code against 4.2.c and it tests fine on my setup so I agree it seems to be environmental.

    Thanks for reading and let me know if you find other issues.

    Jeff

  35. Simon says:

    I finally got it to work! It seemed to be related to the “Model Designer” add-on. I removed it and now everything is fine.

  36. Shailaja says:

    Jeff,
    Thanks for the step by step description in your document. However I am not able to login to share with the extension folder created in C:\alfresco\tomcat\webapps\alfresco\WEB-INF\classes\alfresco\extension . Am I suppose to change any settings?

  37. jpotts says:

    Shailaja,

    Please give me a little more context into what you are doing. And note that the alfresco/extension directory is for extensions to the core repository (the /alfresco webapp) while the alfresco/web-extension directory is for extensions to the Share tier (the /share web app).

    Jeff

  38. shailaja says:

    I am getting this error Aug 11, 2013 10:20:43 PM org.apache.catalina.core.StandardContext listenerStart
    SEVERE: Exception sending context initialized event to listener instance of class org.alfresco.web.app.ContextLoaderListener
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘someco.dictionaryBootstrap’ defined in file [C:\Alfresco\tomcat\shared\classes\alfresco\extension\someco-model-context.xml]: Invocation of init method failed; nested exception is org.alfresco.service.cmr.dictionary.DictionaryException: 07110000 Could not find bootstrap model alfresco/extension/scModel.xml
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1420)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
    at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:276)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:197)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
    at org.alfresco.web.app.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:63)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4206)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4705)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:799)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:601)
    at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:675)
    at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:601)
    at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:502)
    at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1317)
    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:324)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1065)

  39. jpotts says:

    It cannot find your model file. Does it exist in that location? If it does, maybe it is malformed XML?

  40. Hi All,

    I’m attempting to port the SomeCo example application to an AMP using the Maven Alfresco SDK:

    https://artifacts.alfresco.com/nexus/content/repositories/alfresco-docs/alfresco-lifecycle-aggregator/latest/archetypes/alfresco-amp-archetype/index.html

    I’ve hit a problem to do with the build of the web client code and I’m hoping that someone might give me a pointer or two on solving my problem.

    The steps I’m doing are:

    (1) mvn archetype:generate -DarchetypeCatalog=https://artifacts.alfresco.com/nexus/content/groups public/archetype-catalog.xml -Dfilter=org.alfresco.maven.archetype:

    — which downloads the SDK dependencies and the sample AMP Maven archetype.

    (2) I’m testing that the base archetype builds and functions correctly, as detailed here:

    https://artifacts.alfresco.com/nexus/content/repositories/alfresco-docs/alfresco-lifecycle-aggregator/latest/archetypes/alfresco-amp-archetype/advanced-usage.html

    So far so good, the archetype builds and works out-of-the-box.

    (3) Next, I’m adding the someco directories and files to my project structure, as described here,

    http://wiki.alfresco.com/wiki/Maven_For_Dummies

    … but of course, trying to stay close to the new Maven archetype structure as this article is out of date.

    (4) I hit a problem when I attempt to build the project, caused by having either of the following two entries in src/main/config/module-context.xml:

    classpath:alfresco/module/${artifactId}/ui/web-client-config.xml

    alfresco.module.${artifactId}.messages.webclient

    These entries in module-content.xml appear to require that I add the following to my pom.xml, in order to get the project to build:

    ${alfresco.groupId}
    alfresco-web-client
    4.2.c

    The project now builds, but then I get the following run time error when I attempt to do ‘mvn test’:

    org.alfresco.demoamp.test.DemoComponentTest Time elapsed: 0.56 sec <<< ERROR!
    org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from URL location [classpath:alfresco/application-context-core.xml]
    Offending resource: class path resource [alfresco/application-context.xml]; nested exception is org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from URL location [classpath:alfresco/tx-cache-context.xml]
    Offending resource: class path resource [alfresco/application-context-core.xml]; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Parser configuration exception parsing XML from class path resource [alfresco/tx-cache-context.xml]; nested exception is javax.xml.parsers.ParserConfigurationException: Unable to validate using XSD: Your JAXP provider [org.apache.xerces.jaxp.DocumentBuilderFactoryImpl@2e5bbd6] does not support XML Schema. Are you running on Java 1.4 with Apache Crimson? Upgrade to Apache Xerces (or Java 1.5) for full XSD support.

    — The error is confusing, because, afaik, org.apache.xerces.jaxp.DocumentBuilderFactoryImpl does
    support XML schema

    — My build environment is as follows:

    Alfresco Maven SDK v4.2.c

    — I'm running on the following JDK with Eclipse Kepler:

    Java(TM) SE Runtime Environment (build 1.7.0_25-b15)
    Java HotSpot(TM) 64-Bit Server VM (build 23.25-b01, mixed mode)

    — My development platform is a workstation running Red Hat Enterprise Linux Server release 6.4 (Santiago)

    — I'm getting the same error using Eclipse Juno on Java 1.6.

    — This problem only seems to affect web client code. The SomeCo content model seems to work OK with the new Maven Archetype.

    Has anyone else successfully built the someco example with the Alfresco Maven SDK and/or encountered and solved the same problem as me?

    Hope you can help?

    –Robin

Comments are closed.