11-10-2011 12:57 PM
11-10-2011 01:16 PM
You need to use a Session (org.nuxeo.ecm.directory.Session) connected to the SQL repository which contains all directories and the DirectoryService (org.nuxeo.ecm.directory.api.DirectoryService).
This is a snippet of my code to create a new directory entry :
    DirectoryService dirService = DirectoryHelper.getDirectoryService();
    if (dirService == null) {
        return;
    }
    DocumentModel entry = null;
    Session dirSession = null;
    int id;
    try {
        dirSession = dirService.open(<VOCABULARY_ID>);
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("id", "1");
        map.put("label", "label.country.france");
        map.put("obsolete", "0");
        map.put("ordering", "0");
        entry = dirSession.createEntry(map);
    } finally {
        if (entry == null) {
            dirSession.close();
            throw new ApplicationException("Can't add reference to the directory <VOCABULARY_ID>");
        } else {
            dirSession.commit();
            dirSession.close();
        }
    }
Just take care to close (or commit) the Session correctly.
11-10-2011 01:16 PM
You need to use a Session (org.nuxeo.ecm.directory.Session) connected to the SQL repository which contains all directories and the DirectoryService (org.nuxeo.ecm.directory.api.DirectoryService).
This is a snippet of my code to create a new directory entry :
    DirectoryService dirService = DirectoryHelper.getDirectoryService();
    if (dirService == null) {
        return;
    }
    DocumentModel entry = null;
    Session dirSession = null;
    int id;
    try {
        dirSession = dirService.open(<VOCABULARY_ID>);
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("id", "1");
        map.put("label", "label.country.france");
        map.put("obsolete", "0");
        map.put("ordering", "0");
        entry = dirSession.createEntry(map);
    } finally {
        if (entry == null) {
            dirSession.close();
            throw new ApplicationException("Can't add reference to the directory <VOCABULARY_ID>");
        } else {
            dirSession.commit();
            dirSession.close();
        }
    }
Just take care to close (or commit) the Session correctly.
11-10-2011 01:21 PM
Merci, that's it .
 
					
				
				
			
		
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.