cancel
Showing results for 
Search instead for 
Did you mean: 

Create site from Java api and set Dashlets to dashboard

bvandersmissen
Champ in-the-making
Champ in-the-making

Hi guys,

I have followed the following guide https://angelborroy.wordpress.com/2017/12/28/how-to-create-a-site-for-alfresco-using-java-api/

In doing so i got an empty dashboard after setting some user permissions.

private void createDefaultDashboard(SiteInfo siteInfo) {
     

behaviourFilter.disableBehaviour(ContentModel.TYPE_CONTENT);

NodeService nodeService = serviceRegistry.getNodeService();


    NodeService nodeService = serviceRegistry.getNodeService();
    FileFolderService fileFolderService = serviceRegistry.getFileFolderService();
    ContentService contentService = serviceRegistry.getContentService();
     
    FileInfo surfConfig = fileFolderService.create(siteInfo.getNodeRef(), "surf-config", ContentModel.TYPE_FOLDER);
    Map<QName, Serializable> properties = new HashMap<QName, Serializable>();
    properties.put(ContentModel.PROP_CASCADE_HIDDEN, Boolean.TRUE);
    properties.put(ContentModel.PROP_CASCADE_INDEX_CONTROL, Boolean.TRUE);
    nodeService.addAspect(surfConfig.getNodeRef(), ContentModel.ASPECT_HIDDEN, properties);
    // Hint from Bertrand Forest
    properties = new HashMap<QName, Serializable>();
    properties.put(ContentModel.PROP_IS_INDEXED, Boolean.FALSE);
    properties.put(ContentModel.PROP_IS_CONTENT_INDEXED, Boolean.FALSE);
    nodeService.addAspect(surfConfig.getNodeRef(), ContentModel.ASPECT_INDEX_CONTROL, properties);
     
    FileInfo pages = fileFolderService.create(surfConfig.getNodeRef(), "pages", ContentModel.TYPE_FOLDER);
    FileInfo site = fileFolderService.create(pages.getNodeRef(), "site", ContentModel.TYPE_FOLDER);
    FileInfo siteName = fileFolderService.create(site.getNodeRef(), siteInfo.getShortName(), ContentModel.TYPE_FOLDER);
     
    Map<QName, Serializable> props = new HashMap<QName, Serializable>(1);
    props.put(ContentModel.PROP_NAME, "dashboard.xml"); 

    NodeRef node = nodeService.createNode(
                            siteName.getNodeRef(),
                        ContentModel.ASSOC_CONTAINS,
                        QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "dashboard.xml"),
                        ContentModel.TYPE_CONTENT,
                        props).getChildRef();
                         
    ContentWriter writer = contentService.getWriter(node, ContentModel.PROP_CONTENT, true);
    writer.setMimetype(MimetypeMap.MIMETYPE_XML);
    writer.setEncoding("UTF-8");
    // TODO Create dashboard.xml file by using an external file resource instead of a hand-coded String
    writer.putContent("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
            "<page>\n" +
            "      <title>Collaboration Site Dashboard</title>\n" +
            "      <title-id>page.siteDashboard.title</title-id>\n" +
            "      <description>Collaboration site's dashboard page</description>\n" +
            "      <description-id>page.siteDashboard.description</description-id>\n" +
            "      <authentication>user</authentication>\n" +
            "      <template-instance>dashboard-2-columns-wide-left</template-instance>\n" +
            "      <properties>\n" +
            "        <sitePages>[{\"pageId\":\"dashboard\"},{\"pageId\": \"documentlibrary\"}]</sitePages>\n" +
            "      <theme/><dashboardSitePage>true</dashboardSitePage></properties>\n" +
            "    <page-type-id>generic</page-type-id></page>");
     
}
Now i want to add Dashlets to the created site-dashboard.
We have to create a /components folder and write an .xml file to it in order for the site to pick up these dashlets.
Can someone help me with how the .xml file has to look like? And if i need to make any changes to my share page to make it work.
 
0 REPLIES 0