cancel
Showing results for 
Search instead for 
Did you mean: 

A value for the mandatory parameter script-ref has not been set on the rule item script

magarcia_sm
Star Contributor
Star Contributor
Hi People,
I have the following problem. I have an applet that scans a file and places it in a given Space in Alfresco, when the file enters the space there is a rule that triggers an action to process this file. The code of the actions, and the rule, works fine in Alfresco 3.0 however now we are moving our custom code to Alfresco 4.2.

We have the action bean defined in the action-context.xml as this


<bean id="processFra-action" class="org.alfresco.web.actions.ProcessFraActionExecuter" parent="action-executer" >
      <property name="nodeService">
         <ref bean="NodeService" />
      </property>
      <property name="services">
         <ref bean="ServiceRegistry" />
      </property>
      <property name="facturaService">
         <ref bean="facturaService" />
      </property>
      <property name="authenticationComponent">
         <ref bean="AuthenticationComponent" />
      </property>
      <property name="accountService">
         <ref bean="accountService" />
      </property>
      <property name="lockService">
         <ref bean="LockService" />
      </property>
   </bean>



-This action processes the file.
-Converts the file to PDF.
-Move the file to another space.

The problem I have now with this configuration in Alfresco 4.2 is, that when the tiff file procuced by the applet, gets placed correctly in the destination space, the rule should be triggered, however I get this error and nothing gets done:


ww.alfresco.org/ws/service/content/1.0}ContentFault:<ns1:errorCode>0</ns1:errorCode><ns1:message>01090010 A value for the mandatory parameter script-ref has not been set on the rule item script</ns1:message>
   {http://xml.apache.org/axis/}exceptionName:org.alfresco.repo.webservice.content.ContentFault
   {http://xml.apache.org/axis/}stackTrace:
   at org.alfresco.repo.webservice.content.ContentWebService.write(ContentWebService.java:228)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
   at java.lang.reflect.Method.invoke(Method.java:498)
   at org.apache.axis.providers.java.RPCProvider.invokeMethod(RPCProvider.java:397)
   at org.apache.axis.providers.java.RPCProvider.processMessage(RPCProvider.java:186)
   at org.apache.axis.providers.java.JavaProvider.invoke(JavaProvider.java:323)
   at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
   at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
   at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
   at org.apache.axis.handlers.soap.SOAPService.invoke(SOAPService.java:454)
   at org.apache.axis.server.AxisServer.invoke(AxisServer.java:281)
   at org.apache.axis.transport.http.AxisServlet.doPost(AxisServlet.java:699)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
   at org.apache.axis.transport.http.AxisServletBase.service(AxisServletBase.java:327)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
   at org.alfresco.web.app.servlet.GlobalLocalizationFilter.doFilter(GlobalLocalizationFilter.java:61)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
   at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
   at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
   at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
   at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
   at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
   at java.lang.Thread.run(Thread.java:745)

   {http://xml.apache.org/axis/}hostname:SM-PC


My class extend ActionExecuterAbstractBase.
One tip was to override the method
public void execute(Action action, NodeRef actionedUponNodeRef)
not to perform validation however,it does not work, we are still getting this same situation.
To tell you the truth I dont know excatly what it means when the system says

A value for the mandatory parameter script-ref has not been set on the rule item script


As our code is a JAVA code implemented to be run as action.

Any solution to this problem please?

Thank you very much.
7 REPLIES 7

romschn
Star Collaborator
Star Collaborator
Could you try debugging your Java action class and see at which point it is giving the error?
A step-by-step way could be to first remove the complex processing logic from the action class and see if you are able to retrieve the processing noderef and its relevant details or not. Next, put back your processing logic and try to identify where it is causing failure?

Hope this helps.

Hi there

Just a question, Is it possible to run a JAVA custom action in an alfresco Rule in 4.2?. I mean all the documentation I see about running default actions says that a rule can execute a Java Script, but I dont see anything related to a rule calling a Java Custom Action…. What we have done is creating a new rule in a given space, where first we select the conditions, second we select action, the one we have designed in JAVA and that appears in the pick list…. but this worked fine in 3.0, however it is being a nightmare in 4.2.

Thanks!!

You should be able to call a java action from server side java script. Kindly take a look at following documentation link which has a basic example for it.
http://docs.alfresco.com/4.2/concepts/actions.html

Hope this helps.

Hi there, yes we have followed these steps but still get the same error.

We have created an inbound rule that executes a script with the following code


  var process = actions.create("processFra-action");
  process.execute(document);


We have our action defined in the action-context.xml


<bean id="processFra-action" class="org.alfresco.web.actions.ProcessFraActionExecuter" parent="action-executer" >
      <property name="nodeService">
         <ref bean="NodeService" />
      </property>
      <property name="services">
         <ref bean="ServiceRegistry" />
      </property>
      <property name="facturaService">
         <ref bean="facturaService" />
      </property>
      <property name="authenticationComponent">
         <ref bean="AuthenticationComponent" />
      </property>
      <property name="accountService">
         <ref bean="accountService" />
      </property>
      <property name="lockService">
         <ref bean="LockService" />
      </property>
   </bean>


And this is the JAVA code of our action defined, where we have the executeImpl placed in org.alfresco.web.actions


public class ProcessFraActionExecuter extends ActionExecuterAbstractBase {

    private static Log logger = LogFactory.getLog(ProcessFraActionExecuter.class);

    /**
     * Action constants
     */
    public static final String NAME = "ProcessFra";

    /**
     * Indicates whether the action should be ignored if the actioned upon node is locked
     */
    private boolean ignoreLock = true;

    /**
     * Injected services
     */
    private NodeService mlAwareNodeService;
    private LockService lockService;
    private NodeService nodeService;
    private ServiceRegistry services;
    private AuthenticationComponent authenticationComponent;
    private FacturaService facturaService;
    private AccountService accountService;

    private NodeRef espacioSubirFras;

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

    public NodeService getNodeService() {
        return nodeService;
    }

    public void setServices(ServiceRegistry services) {
        this.services = services;
    }

    public ServiceRegistry getServices() {
        return this.services;
    }

    public void setAuthenticationComponent(AuthenticationComponent authenticationComponent) {
        this.authenticationComponent = authenticationComponent;
    }

    public AuthenticationComponent getAuthenticationComponent() {
        return authenticationComponent;
    }

    public void setFacturaService(FacturaService facturaService) {
        this.facturaService = facturaService;
    }

    public FacturaService getFacturaService() {
        return facturaService;
    }

    public void setAccountService(AccountService accountService) {
        this.accountService = accountService;
    }

    public AccountService getAccountService() {
        return accountService;
    }


  @Override
    protected void executeImpl(
            Action ruleAction,
            NodeRef actionedUponNodeRef) {
        logger.info("Ejecutandose action automaticamente");
        logger.info("actionedUponNodeRef " + actionedUponNodeRef);

        long time = System.currentTimeMillis();

        if (this.nodeService.exists(actionedUponNodeRef) == false) {
            logger.info("Nodo no existe");
            // node doesn't exist - can't do anything
            return;
        }
        // First check that the node is a sub-type of content
        QName typeQName = this.nodeService.getType(actionedUponNodeRef);
        if (this.services.getDictionaryService().isSubClass(typeQName, ContentModel.TYPE_CONTENT) == false) {
            // it is not content, so can't transform
            return;
        }

        ///////////////////////////////////////////////////////////////////////////////////////////////////
//      String usuActual = this.services.getAuthenticationService().getCurrentUserName();
//      logger.info("usuActual " + usuActual);
        try {
            File fileTemp = File.createTempFile("scan_", ".tiff");

            ContentReader cr = this.services.getContentService().getReader(actionedUponNodeRef,
                    ContentModel.PROP_CONTENT);
            cr.getContent(fileTemp);
            //Se obtiene el numero de paginas para contabilizarlas
            FileSeekableStream ss = new FileSeekableStream(fileTemp);
            ImageDecoder dec = ImageCodec.createImageDecoder("tiff", ss, null);
            int count = dec.getNumPages();

            NodeRef pdfNodeRef = null;
            Boolean ocr = (Boolean) this.nodeService.getProperty(actionedUponNodeRef, FacturaModel.Alf_OCRapply);
            String userCIF = (String) this.nodeService.getProperty(actionedUponNodeRef, FacturaModel.Alf_CIFempresa);
            String userName = (String) this.nodeService.getProperty(actionedUponNodeRef, FacturaModel.Alf_UserName);
            logger.info("OCR " + ocr);
            espacioSubirFras = this.nodeService.getPrimaryParent(actionedUponNodeRef).getParentRef();
            ChildAssociationRef parentChildAsoc = this.getNodeService().getPrimaryParent(espacioSubirFras);
            NodeRef empresaNodeRef = parentChildAsoc.getParentRef();

            NodeRef certificado = this.getCertificado();
            File filecert = File.createTempFile("prefCertif", "sufCertif");
            this.services.getFileFolderService().getReader(certificado).getReader().getContent(filecert);

            String clave = new String();
            if ((certificado != null) && (this.getNodeService().hasAspect(certificado, FacturaModel.ASPECT_CERTIFICADO))
                    && (this.getNodeService().getProperty(certificado, FacturaModel.PROP_CLAVE) != null)) {
                clave = (String) this.getNodeService().getProperty(certificado, FacturaModel.PROP_CLAVE);
            }

            if (!this.getNodeService().hasAspect(actionedUponNodeRef, FacturaModel.ASPECT_DETALLE_IVA_ANT)) {
                Map<QName, Serializable> aspectProperties = new HashMap<QName, Serializable>();
                this.getNodeService().addAspect(actionedUponNodeRef, FacturaModel.ASPECT_DETALLE_IVA_ANT, aspectProperties);
            }
            if (!this.getNodeService().hasAspect(actionedUponNodeRef, FacturaModel.ASPECT_DETALLE_IVA_POS)) {
                Map<QName, Serializable> aspectProperties = new HashMap<QName, Serializable>();
                this.getNodeService().addAspect(actionedUponNodeRef, FacturaModel.ASPECT_DETALLE_IVA_POS, aspectProperties);
            }

            long time2 = System.currentTimeMillis();
            if (!ocr) {
                logger.info("Inicio tranform sin OCR " + time2);
                pdfNodeRef = this.doTransform(fileTemp, espacioSubirFras, ocr, userCIF, userName);
                time2 = System.currentTimeMillis() - time2;
                logger.info("Fin tranform sin OCR " + time2);
                if (pdfNodeRef != null) {
                    logger.info("Registro no ocr");
                    this.getAccountService().registerCountNoOCR(userCIF, count);
                    time2 = System.currentTimeMillis() - time2;
                    logger.info("Fin Registro ocr " + time2);

                    logger.info("Type fra");
                    this.getFacturaService().addTypeFra(pdfNodeRef);
                    time2 = System.currentTimeMillis() - time2;
                    logger.info("Type fra " + time2);

                    logger.info("Registro metadatos y firma");
                    this.getFacturaService().addFirmaMetadatosDoc(pdfNodeRef, filecert, clave);
                    time2 = System.currentTimeMillis() - time2;
                    logger.info("Registro metadatos y firma " + time2);

                    logger.info("Mover a revisar");
                    this.getFacturaService().moverRevisar(pdfNodeRef, empresaNodeRef);
                    time2 = System.currentTimeMillis() - time2;
                    logger.info("Mover a revisar " + time2);
                } else {
                    Utils.addErrorMessage(Application.getMessage(
                            FacesContext.getCurrentInstance(), "error_transform_NO_OCR"));
                }

            } else {

                logger.info("Inicio tranform con OCR " + time2);
                pdfNodeRef = this.doTransformOCR(actionedUponNodeRef);
                time2 = System.currentTimeMillis() - time2;
                logger.info("Fin tranform con OCR " + time2);
                if (pdfNodeRef != null) {
                    logger.info("Registro ocr");
                    this.getAccountService().registerCountOCR(userCIF, count);
                    time2 = System.currentTimeMillis() - time2;
                    logger.info("Fin Registro ocr " + time2);

                    logger.info("type fra y lectura datos");
                    String cifDescarte = (String) this.getNodeService().getProperty(certificado, FacturaModel.PROP_CIF_DESCARTE);
                    Boolean applyRE = (Boolean) this.getNodeService().getProperty(certificado, FacturaModel.PROP_APPLY_RE);
                    this.getFacturaService().leerDoc(pdfNodeRef, cifDescarte, applyRE);
                    time2 = System.currentTimeMillis() - time2;
                    logger.info("lectura datos " + time2);

                    logger.info("Registro metadatos y firma");
                    this.getFacturaService().addFirmaMetadatosDoc(pdfNodeRef, filecert, clave);
                    time2 = System.currentTimeMillis() - time2;
                    logger.info("Registro metadatos y firma " + time2);

                    logger.info("Mover a revisar");
                    this.getFacturaService().moverRevisar(pdfNodeRef, empresaNodeRef);
                    time2 = System.currentTimeMillis() - time2;
                    logger.info("Mover a revisar " + time2);
                } else {
                    Utils.addErrorMessage(Application.getMessage(
                            FacesContext.getCurrentInstance(), "error_transform_OCR"));
                }

            }

            //Obtiene el usuario actual y lo cambia internamente por el usuario sistema, que tiene todos los permisos

//         authenticationComponent.setSystemUserAsCurrentUser();
            if (this.services.getNodeService().exists(actionedUponNodeRef)) {
                long time3 = System.currentTimeMillis();
                logger.info("Eliminamos nodo tiff " + time3);
                this.services.getNodeService().deleteNode(actionedUponNodeRef);
                time3 = System.currentTimeMillis() - time3;
                logger.info("Eliminado nodo tiff " + time3);
            }
            //Vuelve a cambiar el usuario sistema al usuario que cerro el mes
//         authenticationComponent.clearCurrentSecurityContext();
//         authenticationComponent.setCurrentUser(usuActual);
//         logger.info("El usuario vuelve a ser "+usuActual);

            if (fileTemp.exists()) {
                fileTemp.delete();
            }

            if (filecert.exists()) {
                filecert.delete();
            }

            time = System.currentTimeMillis() - time;
            Node node = new Node(pdfNodeRef);
            logger.info("Tiempo en procesar factura " + node.getName() + ": " + time);

        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        //////////////////////////////////////////////////////////////////////////////////////////////////

        logger.info("Fin action");
    }



and we keep getting this error message saying that the script-ref is missing…

this did not happen in 3.0 but it does now in 4.2. Are we missing something in the action declaration in 4.2??

Thanks

gravitonian
Star Collaborator
Star Collaborator
Hi,

How does your "protected void addParameterDefinitions(List<ParameterDefinition> paramList)"  implementation look like?

Hi Martin

this is what we have introduced in the "protected void addParameterDefinitions(List paramList)"

@Override
    protected void addParameterDefinitions(List<ParameterDefinition> paramList) {
//      paramList.add(new ParameterDefinitionImpl("script-ref", DataTypeDefinition.TEXT, true, getParamDisplayLabel("script-ref")));
    }


Also what we have found is that we get this error message when in our java code we try to create a pdf Node and then we try ti add some content to the node. I mean, creating the node works fine, however when we try to add conent to that node, the systems returns this error.

In our code we have this

public NodeRef saveInAlfresco(File fileContent, NodeRef containerNodeRef, String userName) throws Exception {

String fileName = fileContent.getName();


NodeRef fileNodeRef = this.nodeService.createNode(
                    containerNodeRef,
                    ContentModel.ASSOC_CONTAINS,
                    QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, fileName),
                    ContentModel.TYPE_CONTENT,
                    props).getChildRef();

// get a writer for the content and put the file
ContentWriter writer = this.serviceRegistry.getContentService().getWriter(fileNodeRef, ContentModel.PROP_CONTENT, true);

// set the mimetype and encoding
writer.setMimetype(MimetypeMap.MIMETYPE_PDF);
writer.setEncoding(Charset.defaultCharset().name());

if (fileContent != null) {

    writer.putContent(fileContent);
    logger.info("Añadimos contenido al nuevo fichero pdf");

}
            return fileNodeRef;
        }


if we remove this line

writer.putContent(fileContent);


the code works fine and no error is returned….. however if we leave the line then is when we get the error track.

Any ideas?, the user that is launching this action has Coordinator rights (write&read) in the space where the node it is being created.

Thanks a lot once more!

gravitonian
Star Collaborator
Star Collaborator
Hi,

Is there a chance you could put together a small example that reproduces the problem on 4.2?
Then file an ALF issue (issues.alfresco.com/jira/browse/ALF) and we can have a look at it.

thanks