I'm attempting to do just that but have a Nuxeo coding (usage) issue.

I have built my plugin that happily deploys and my class is run after the user logs in but on the redirect to 'my' starting page I get an error.

In my 'test' class that replaces StartupHelper I override the initDomainAndFindStartupPage and after finding the domain perform an NXQL query to locate a particular Workspace. I then try and navigateTo this Workspace, the resulting page is an error:

java.lang.IllegalArgumentException: null context
        org.nuxeo.ecm.core.api.AbstractSession.connect(AbstractSession.java:137)
        org.nuxeo.ecm.core.api.CoreInstance.open(CoreInstance.java:105)
        
org.nuxeo.ecm.platform.ui.web.tag.fn.DocumentModelFunctions.hasPermission(DocumentModelFunctions.java:140)
        
org.nuxeo.ecm.platform.ui.web.tag.fn.DocumentModelFunctions.canModify(DocumentModelFunctions.java:173)
        sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        java.lang.reflect.Method.invoke(Method.java:585)
        com.sun.el.parser.AstFunction.getValue(AstFunction.java:114)
        com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:192)


I'm guessing that I need to setup a CoreSession (via CoreInstance) before navigating, but not sure how I should be doing so. Any help?


@Name("myStartupHelper")
public class MyStartupHelper extends StartupHelper {
@In(required = false)
   private Principal currentUser;
/** * @see org.nuxeo.ecm.webapp.helpers.StartupHelper#initDomainAndFindStartupPage(java.lang.String, java.lang.String)
    */
   @Override
public String initDomainAndFindStartupPage(String domainTitle, String viewId) throws ClientException {
//         delegate server init to the default helper
       String result = initServerAndFindStartupPage();

       if (!DOMAINS_VIEW.equals(result)) {
           // something went wrong during server lookup do not try to go
           // further
           return result;
       }
       if (documentManager == null) {
documentManager = navigationContext.getOrCreateDocumentManager();
       }

       // get the domains from selected server
       DocumentModel rootDocument = documentManager.getRootDocument();

       if (!documentManager.hasPermission(rootDocument.getRef(),
               SecurityConstants.READ_CHILDREN)) {
           // user cannot see the root but maybe she can see contained
           // documents thus forwarding her to her dashboard
           return DASHBOARD_VIEW;
       }

       DocumentModelList domains = documentManager.getChildren(rootDocument
               .getRef());

       if (domains.isEmpty()) {
           if (!documentManager.hasPermission(rootDocument.getRef(),
                   SecurityConstants.EVERYTHING)) {
// current user cannot see any domain but maybe she has browsing
               // rights on contained sub workspaces thus use the dashboard
               // view to list the workspaces she can access
               return DASHBOARD_VIEW;
           }

           // current user is a global administrator so if she cannot see a
           // domain that means there is no such domain thus create one by
           // default
           String id = IdUtils.generateId(domainTitle);
           DocumentModel newDomain = documentManager.createDocumentModel(
                   rootDocument.getPathAsString(), id, DOMAIN_TYPE);

           newDomain.setProperty("dublincore", "title", domainTitle);
           documentManager.createDocument(newDomain);
           documentManager.save();
           log.debug("created domain with id: " + id + " , and type: "
                   + DOMAIN_TYPE);

           // refetch the list of domains
           domains = documentManager.getChildren(rootDocument.getRef());
       } else if (domains.size() > 1) {
           // several domains are available, let the user choose
           return DOMAINS_VIEW;
       }

DocumentModel newDoc = findStartupDocument(domains.get(0));
       if (newDoc != null) {
           return navigationContext.navigateToDocument(newDoc, "view");
       } else {
           // select and go to the unique domain
return navigationContext.navigateToDocument(domains.get(0), viewId);
       }
   }

   private DocumentModel findStartupDocument(DocumentModel domain) {
try { String nxql = "SELECT * FROM Document WHERE dc:title='Workspace 1'"; SearchService service = SearchServiceDelegate.getRemoteSearchService();
           ComposedNXQueryImpl query = new ComposedNXQueryImpl(
                           SQLQueryParser.parse(nxql),
                           service.getSearchPrincipal(currentUser));
ResultSet rs = service.searchQuery(query, 0, 2); if (rs.isEmpty() || rs.size() > 1) {
               return null;
           }
           ResultItem resultItem = rs.get(0);
           if (!(resultItem instanceof DocumentResultItem)) {
               return null;
           }
DocumentModel docModel = ((DocumentResultItem)resultItem).getDocumentModel(); if (docModel.getType().equals("Workspace")) {
               return docModel;
           }
} catch (ClientException e) {
           e.printStackTrace();
           return null;
       } catch (SearchException e) {
           e.printStackTrace();
           return null;
       } catch (QueryException e) {
           e.printStackTrace();
           return null;
       }
return null;
   }
}





[EMAIL PROTECTED] a écrit :
Hello,

I would like to know if it's possible to change the starting page when you are
logging in Nuxeo 5.
I mean, is it possible to start in an other directory than "default Domain".
For example I want to start directly in "Workspaces"!

Yes you can build a plugin such as described in the NXSample project and
override the /nxstarup.xhtml association in the pages#PAGES directive of your
deployment-fragment.xml to point to a custom bean such in the same spirit as the
currently used StartupHelper class.



--
Dr. Sean Radford, MBBS, MSc
http://www.tacola.com/

_______________________________________________
ECM mailing list
[email protected]
http://lists.nuxeo.com/mailman/listinfo/ecm

Reply via email to