Thursday, February 7, 2013

Alfresco Repo : Create datalist using Java API

Create datalist using Java API

Step 1 : First create the site using siteService.
Step 2: Create the datalist container using siteService or SiteServiceImpl.
Step 3: Create the necessary properties for the datalist.
Step 4: Create the datalist using nodeService.

String DATALIST_CONTAINER = "dataLists";

SiteInfo siteInfo = this.siteService.createSite (TEST_SITE_PRESET, siteName, siteName, DESCRIPTION_TEST_THIS_IS_MY_DESCRIPTION, SiteVisibility.PRIVATE);

//NodeRef dataListContainer = siteService.createContainer(siteName, DATALIST_CONTAINER, ContentModel.TYPE_CONTAINER, null);

//if the datalist container does not exist then it will create a new one based on the create boolean parameter
NodeRef dataListContainer = SiteServiceImpl.getSiteContainer(siteName, DATALIST_CONTAINER, true, siteService, transactionService, taggingService);

Map<QName, Serializable> contentProps = new HashMap<QName, Serializable>();
contentProps.put(ContentModel.PROP_TITLE, "Demo");
contentProps.put(ContentModel.PROP_DESCRIPTION, "Demo Datalist");

nodeService.createNode(dataListContainer, ContentModel.ASSOC_CONTAINS, QName.createQName(DataListModel.DATALIST_MODEL_PREFIX, "Demo"), DataListModel.TYPE_DATALIST, contentProps);

Hope this helps someone.

1 comment:

  1. Hi,

    I need the to create DataLists container as you mentioned here. Is it possible to do it via CMIS or REST ? I cannot use Java API.

    Thank you very much.