4

I'm integrating an applet on a workflow in the Alfresco. I created a new button org/alfresco/components/form/controls/workflow/activiti-transitions.ftl here

  ...

    <button onclick="changePDF(); this.disabled=true; return false;"> Change </button>
    <div id="pdfTexto" style="width:1000px;height:1000px"></div>
        <div class="applet">
            <script type="text/javascript">
                deploy();
            </script>
        </div>
    </#if>

And this button change (through the javascript of the applet) calls the functionality of the applet that is make changes in the file of the respective workflow. After this, I want to put "Approved" like the button accept standard does. But, I only want to make this after the changes make effect. My applet returns a "ok" when the changes are completed (the POST request is completed), after this, I want to put "Approved" and redirect to the same page that "accept" button redirects. In resume, after "ok", make what the accept button does.

My applet updates the content of an exiting document with: http://localhost:8080/share/proxy/alfresco/api/upload ...

How can I make this? Any hints for a better solution then the below?

Evolution: I'm trying to make this:

 var form = new FormData();
     form.append("prop_wf_reviewOutcome","Approve");
     form.append("prop_bpm_comment","good");
     form.append("prop_transitions","Next");
     var requestTask = new XMLHttpRequest();
         requestTask[Alfresco.util.CSRFPolicy.getHeader()] = Alfresco.util.CSRFPolicy.getToken();
         requestTask.open("POST", "http://localhost:8080/share/proxy/alfresco/api/task/"+ taskidVar+ "/formprocessor" + "?" + Alfresco.util.CSRFPolicy.getParameter() + "=" + encodeURIComponent(Alfresco.util.CSRFPolicy.getToken()));
         requestTask.send(form);

But lack redirect the page as the "Approve" button.

PRVS
  • 1,612
  • 4
  • 38
  • 75
  • what exactly does the applet? Update the property of the document ? Or update its content ? – Marco Altieri Feb 13 '16 at 17:08
  • Sorry, i forget this information. My applet updates the content of an exiting document. I edit my question. @MarcoAltieri – PRVS Feb 13 '16 at 17:13

1 Answers1

5

First of all, you need to define your behaviour:

package com.someco.alfresco.policy;

import org.alfresco.model.ContentModel;
import org.alfresco.repo.content.ContentServicePolicies;
import org.alfresco.repo.policy.Behaviour;
import org.alfresco.repo.policy.JavaBehaviour;
import org.alfresco.repo.policy.PolicyComponent;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class DocumentUpdatePolicy implements ContentServicePolicies.OnContentUpdatePolicy {
    private final Log logger = LogFactory.getLog(getClass());

    private PolicyComponent policyComponent;    
    private NodeService nodeService;    

    public void init() {
        this.policyComponent.bindClassBehaviour(
                QName.createQName(NamespaceService.ALFRESCO_URI, "onContentUpdate"),
                ContentModel.TYPE_CONTENT,
                new JavaBehaviour(this, "onContentUpdate", Behaviour.NotificationFrequency.EVERY_EVENT));
    }

    @Override
    public void onContentUpdate(NodeRef nodeRef, boolean newContent) {

        logger.debug("Called on: " + nodeRef);
        if (null == nodeRef || !nodeService.exists(nodeRef)) {
            logger.error("Wrong nodeRef");
            /* This can happen in some circumstances */
            /* Do you want to just ignore it or do something ? You decide */
            return;
        }

        /* Here goes the code to update the task */
    }

    public void setPolicyComponent(final PolicyComponent policyComponent) {
        this.policyComponent = policyComponent;
    }

    public void setNodeService(NodeService nodeService) {
        this.nodeService = nodeService;
    }


}

Than you need to initialise it in your custom Spring context:

<bean id="onDocumentUpdatePolicy" class="com.someco.alfresco.policy.DocumentUpdatePolicy">
    <property name="policyComponent">
        <ref bean="policyComponent" />
    </property>
    <property name="nodeService">
        <ref bean="NodeService" />
    </property>
</bean>
Marco Altieri
  • 3,726
  • 2
  • 33
  • 47
  • Try this, just to start and then you can add the code for the task – Marco Altieri Feb 13 '16 at 17:56
  • Hum, I was trying to do in javascript file of the applet..So, I have to make a java class apart right? Where I have to put my custom spring context and this class? Server-side? I'm asking this because in my workflow, I modify the PDF when the workflow is created too and then, only when the applet button is pressed, in each user's task. That is, I just wanted this onContentUpdate fired on user tasks rather than on creating workflow (which is also a content update). There are some kind of restrictions so that it does not fire in the creation of the workflow? I think that is the only problem. – PRVS Feb 13 '16 at 19:42
  • And one more question... Sorry i'm confused about the funcionality of this. And I have to call this behaviour in the javascript of the applet? My question is, how can I know that "task done" is for the specific user that make the changes? I have to communicate between this and the applet? And to redirect the page? I'm confused about that. – PRVS Feb 13 '16 at 19:55
  • The behaviour will be called automatically by Alfresco. It is a listener that intercepts events in the repository. The one I wrote, is listening for content update. If the content is updated also in other ways, the behaviour will be called. To avoid this, what you can do is to check that a property is set. For example, you can say that the applet will set a "someco:documentStatus" to "Final". The behaviour will check that the property is set to "Final" before doing anything. – Marco Altieri Feb 13 '16 at 20:03
  • If you are sure that when the document is in a workflow, only the applet will update it, you do not need the status: you can just check that the document is in a workflow package. – Marco Altieri Feb 13 '16 at 20:03
  • Before trying to go further, you have to familiarise with behaviours. Do some experiments with the behaviour I wrote. – Marco Altieri Feb 13 '16 at 20:04
  • When I start workflow, the applet make a change on the content of the document, then, only the applet does. So, I can just check that the document is in a workflow package, right? Because in the creation of the workflow, when I check that the document is in a workflow, if already changed in the creation, i think that works. right? But the most important... I'm trying but, I think this is not called... I'm trying to make "system.out.println" but I don't see anything... is in the server-side that I have to call this right?I create the java but, where I create the new context?Maybe it's the error – PRVS Feb 13 '16 at 20:31
  • I tried to create on alfresco/module/${project.artifactId}/context/service-context.xml and then create a module-context.xml inside alfresco/module/${project.artifactId}, to import resource above (service-context.xml) . But this not works. – PRVS Feb 13 '16 at 20:51
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/103393/discussion-between-marco-altieri-and-prvs). – Marco Altieri Feb 13 '16 at 22:09
  • You see anything on pom.xml? I edit my question a Lil bit because of "Approved" instead "task done" and I put on the chat New tries – PRVS Feb 14 '16 at 08:45
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/103416/discussion-between-marco-altieri-and-prvs). – Marco Altieri Feb 14 '16 at 11:11
  • Done. I redirect to the page: http://localhost:8080/share/page/task-details?taskId=activiti$23558&nodeRef=workspace://SpacesStore/fbe95107-a6a4-468b-a0e9-a3eaaad88b80 Thanks ;) – PRVS Feb 15 '16 at 20:55