Automation Chain + setproperty + NOT mandatory Blob : Set Document BLOB properties with workflow var but got null problem

Hello,

I want to set a Document var of type blob with a workflow var, in an automation chain, after selection of this var in a workflow form.

This workflow var is not mandatory and that is the problem.

1) If I try “Update Property” but got an object is null exception and nuxeo was in a right mess.

2) I try to set this variable with a condition like setting workflow var, But nuxeo tells me that the update properties only allow “scalar”…

@{WorkflowVariables["wkToto"] != null?WorkflowVariables["wkToto"]:""}

3) So I try “run script” but I couldn't get the “current document”… :-(

if (WorkflowVariables["wkToto"]  != null){
Document.doc.setPropertyValue("amoi:toto",WorkflowVariables["wkToto"]) ;
}

Do you know how to SET a document BLOB even if it's NULL with workflow var ?

thanks

1 votes

2 answers

3340 views

ANSWER



I did a custom operation save blob from workflow to document attached to workflow in my nuxeo ide and sent it to studio

@Operation(id=SaveBlobToInputDocument.ID, category=Constants.CAT_SERVICES, label="SaveBlobToInputDocument", description="Guarda blob en el inputdocument. Usar esta cadena solo en documentos con workflows activos")
public class SaveBlobToInputDocument {

    public static final String ID = "SaveBlobToInputDocument";
    private static final Log log = LogFactory.getLog(SaveBlobToInputDocument.class);
    @Context
    protected CoreSession session;


    @Param(name = "workflow_var", required = true)
    protected String workflowVar;

    @Param(name = "type_document", required = true)
    protected String typeDocument;

    @Param(name = "title_document", required = false)
    protected String titleDocument; 

    @Context
    protected OperationContext ctx; 

    @OperationMethod(collector = DocumentModelCollector.class)  
    public DocumentModel run(DocumentModel input) throws ClientException  {
        if(workflowVar != null && !workflowVar.trim().equals("")&& typeDocument!= null && !typeDocument.trim().equals("")){
            @SuppressWarnings("unchecked")
            Object obj =((Map<String, Serializable>)ctx.get(Constants.VAR_WORKFLOW)).get(workflowVar);                          
            if (obj != null && obj instanceof Blob){                    
                Blob blob= (Blob) obj;
                DocumentModel blobDocument = session.createDocumentModel(typeDocument);
                blobDocument.setPropertyValue(Constantes.XPATH_FILECONTENT,(Serializable) blob);
                blobDocument.setPropertyValue(Constantes.XPATH_FILENAME,(Serializable)FileUtils.getCleanFileName(blob.getFilename()));
                if(titleDocument != null && !titleDocument.equals("")){
                    blobDocument.setPropertyValue(Constantes.XPATH_TITLE, titleDocument);   
                }               
                try {
                    blobDocument.setPathInfo(input.getPathAsString(),Framework.getService(PathSegmentService.class).generatePathSegment(blobDocument));
                    session.createDocument(blobDocument);           
                } catch (Exception e) {
                    throw new RuntimeException("Runtime: "+e);
                }
            }
        }
        else
        {
            log.warn("workflowVar o typeDocument estan vacios o nulos SaveBlobToInputDocument");
        }
        return input;
    }    
}
0 votes



thanks, that's great!
06/14/2013

Think to check the answers that what useful for you
06/14/2013

I also would like to know when my answer has errors or if there is a better way to do that. Thanks. I only want to help
06/14/2013

please create a new question for a new question.
06/14/2013


Hello Me,

I don't know why the basic “update property” don't work with blob…

Nevertheless, this is the answer:

Automation Chain:

  • Document is in input.

  • Do A Run Script

    if (WorkflowVariables[“varamoiwk”] != null){ Document.doc.setPropertyValue(“monxpath:mavalaupdate”,WorkflowVariables[“varamoiwk”]) ; }

  • Do A “Document Save” (This was missing ;-) )

This is an exemple of an other Run Script: http://doc.nuxeo.com/pages/viewpage.action?pageId=2392665

0 votes