User Action active in a specific contentView and LifeCycle for selected Document

Hi,

In Nuxeo Studio, I created a “User Action” attached to a specific contentView (category) and I would like the button is active only when the selected documents are in a life cycle validated?

I can not use in this case the “current document has life cycle” because I'm in a contentView but an EL expression like this:

$ {selectedDocument.currentLifeCycleState = 'approved'}

But my syntax is not correct?

Thank you

alt text

0 votes

2 answers

1026 views

ANSWER



Hi,

I publish the final code for users interested

@Name("yourProjectAction")
@Scope(ScopeType.EVENT)
public class yourProjectAction implements Serializable {

private static final long serialVersionUID = 1L;

@In(create = true, required = false)
protected transient CoreSession documentManager;

@In(create = true)
protected NavigationContext navigationContext;

@In(create = true)
protected DocumentsListsManager documentsListsManager;

protected List<DocumentModel> getCurrentlySelectedDocuments() {

    if (navigationContext.getCurrentDocument().isFolder()) {
        return documentsListsManager.getWorkingList(DocumentsListsManager.CURRENT_DOCUMENT_SELECTION);
    } else {
        return null;
    }
}    

public boolean isSelectionAreAllApproved() throws ClientException {

    List<DocumentModel> selectedDocs = getCurrentlySelectedDocuments();
    if (selectedDocs == null) {
      return false;
    }
    for (DocumentModel doc : selectedDocs) {
        if (!doc.getCurrentLifeCycleState().equals("approved")) {
          return false;
        }
    }
    return true;
 }
}
0 votes



Thank you for the community. I marked your answer as the one. Mine is more general.
09/12/2012


There is no way (I think to do with just a simple EL.

The way (not so hard) is to use Nuxeo IDE if you have a bit development skills :

  • I let you look the Nuxeo IDE installation documentation : http://doc.nuxeo.com/x/ZYKE
  • Then you create a new Nuxeo Plugin Project (click on the yellow button > new Nuxeo Plugin name it > next > next )
  • finally create an Action Bean (for instance named YourProjectAction) with the yellow button > next > next
  • create a method into the java class created named isSelectionAreAllApproved

And in it:

    List<DocumentModel> selectedDocs = getCurrentlySelectedDocuments();
    if (selectedDocs != null) {
      return false;
    }
    for (DocumentModel doc : selectedDocs) {
    if (!doc.getCurrentLifeCycleState().equals("approve")) {
      return false;
    }
    return true;

And in your el just fill : yourProjectActions.selectionAreAllApproved

You will have to clean up a bit what have generated the Nuxeo IDE template (create a button hello world => you can look what have been generated to understand a bit more Nuxeo behind the Nuxeo Studio scene). But in your case you will have to :

  • remove the getCurrentlySelectedDocuments, doGet, accept methods in the java class
  • remove the /src/main/resources/OSGI-INF/extensions/org.nuxeo.sample.YourProjectActionsBean.xml xml file
  • remove the /src/main/resources/OSGI-INF/l10n directory
  • remove the /src/main/resources/web directory

To generate the jar => right click on the project name > Nuxeo > Export jar…

To install it into your Nuxeo instance copy it in $Nuxeo_HOME/nxserver/bundles

Hope will help.

1 votes