cancel
Showing results for 
Search instead for 
Did you mean: 

How to create a Datalist with java api? Alfresco 4

need
Champ in-the-making
Champ in-the-making
Hi all,

how to create a contact datalist as this example?

http://www.techbits.de/2011/10/18/using-the-javascript-console-creating-and-populating-datalists/

I need to create the datalist with java API. You make me some example?

Regards
9 REPLIES 9

need
Champ in-the-making
Champ in-the-making
Help me please

need
Champ in-the-making
Champ in-the-making
Bump

need
Champ in-the-making
Champ in-the-making
no one is willing to give me a hint?

Thanks a lot

mrogers
Star Contributor
Star Contributor
Bumping topics makes it look like your topic has been answered.

There's a java script example on the link you gave.   You can do the same operations through the Java API.

need
Champ in-the-making
Champ in-the-making
ok I managed to create the DataList with java but now I get an error in tomcat: type: contact {} http://www.alfresco.org/model/datalist/1.0

    Property: {} http://www.alfresco.org/model/datalist/1.0 contactTce
    Constraint: 02160032 The value is not an allowed value

This property is a list constraint type LIST:

This is my example code:

String query = "PATH:\"app:company_home/st:sites/cm:research/cm:dataLists\"";
           StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore");
           ResultSet resultSet = searchService.query(storeRef, SearchService.LANGUAGE_LUCENE, query);
          
           NodeRef listNodeRef = resultSet.getNodeRef(0);
           resultSet.close();
          
           //create dataLists object
           String nameContactList = "Summary";
           Map<QName, Serializable> contentProps = new HashMap<QName, Serializable>();
           contentProps.put(ContentModel.PROP_NAME, nameContactList);
          
          
          
           ChildAssociationRef dataList = nodeService.createNode(listNodeRef,
                 ContentModel.ASSOC_CONTAINS,
                 QName.createQName(NamespaceService.DATALIST_MODEL_PREFIX, nameContactList),
                 TYPE_CONTACTLIST,
                 contentProps);

what's wrong?

Thanks a lot

itnovum
Champ in-the-making
Champ in-the-making
Hi,

for future search-hits, here is a working example based on your code:


NodeRef dataListContainer = siteService.getContainer(siteInfo.getShortName(), "dataLists");

Map<QName, Serializable> contentProps = new HashMap<QName, Serializable>();
contentProps.put(ContentModel.PROP_TITLE, "DataListName");
contentProps.put(ContentModel.PROP_DESCRIPTION, "DataListDescription");
contentProps.put(DataListModel.PROP_DATALIST_ITEM_TYPE, "YOUR DATALIST ITEM TYPE");
nodeService.createNode(dataListContainer, ContentModel.ASSOC_CONTAINS, QName.createQName(DataListModel.DATALIST_MODEL_PREFIX, "DataListName"), DataListModel.TYPE_DATALIST, contentProps);

Greetings

Just expanded the code a bit more.

If the datalist container is null, then create the datalist container first.

So the below code will do the following.
* First create the site using siteService.
*  Create the datalist container using siteService or SiteServiceImpl.
*  Create the necessary properties for the datalist.
* Create the datalist using nodeService.

<java>
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");
contentProps.put(DataListModel.PROP_DATALIST_ITEM_TYPE, "YOUR DATALIST ITEM TYPE");

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

</java>

Thanks
Murali,
http://mralfresco.blogspot.in

jpfi
Champ in-the-making
Champ in-the-making
hi,
be aware that Share won't Know your site, because surf-config objects won't be created if you create a site directly via java API.
Cheers, jan

Hi Jan,
Thanks for pointing out and I've used the code in unit testing.

Thanks
Murali
http://mralfresco.blogspot.in