cancel
Showing results for 
Search instead for 
Did you mean: 

Actions or Behaviors for Custm Content Model?

simo2010
Champ in-the-making
Champ in-the-making
Hi all,
i have the following requirements, but i don't know the right way to accomplisch them:
System:
-Alfresco EE 3.3.2 bundle
-Windows 2003 R2 server 32-Bit
-SDK3.3
-A CIFS Folder
Requirements:
- A custom Content Model (have already defined and successfull deployed) for PDF documents
<?xml version="1.0" encoding="UTF-8"?>

<!– Custom Model –>

<!– Note: This model is pre-configured to load at startup of the Repository.
    So, all custom –>
<!– types and aspects added here will automatically be registered –>

<model name="ivm:invoiceModel" xmlns="http://www.alfresco.org/model/dictionary/1.0">

    <!– Optional meta-data about the model –>
    <description>Invoice Custom Model FH Mainz</description>
    <author>M. Noubough</author>
    <version>1.0</version>

    <imports>
        <!– Import Alfresco Dictionary Definitions –>
        <import uri="http://www.alfresco.org/model/dictionary/1.0"
            prefix="d" />
        <!– Import Alfresco Content Domain Model Definitions –>
        <import uri="http://www.alfresco.org/model/content/1.0" prefix="cm" />
    </imports>

    <!– Introduction of new namespaces defined by this model –>
    <!– NOTE: The following namespace custom.model should be changed to reflect
        your own namespace –>
    <namespaces>
        <namespace uri="http://www.dialog-semiconductor.com/model/content/1.0"
            prefix="ivm" />
    </namespaces>
    <types>

        <type name="ivm:inVoice">
            <title>Invoice FH Mainz</title>
            <parent>cm:content</parent>
            <properties>
                <property name="ivm:Number">
                    <title>Rechnungsnummer</title>
                    <type>d:text</type>
                    <mandatory>true</mandatory>
                   
                </property>
                <property name="ivm:Amount">
                    <title>Betrag</title>
                    <type>d:text</type>
                    <mandatory>true</mandatory>
               
                </property>
                <property name="ivmSmiley Very Happyate">
                    <title>Datum</title>
                    <type>d:date</type>
                    <mandatory>true</mandatory>
                </property>
                <property name="ivm:customerNumber">
                    <title>Kundennummer</title>
                    <type>d:text</type>
                    <mandatory>true</mandatory>
                   
                </property>
                <property name="ivmSmiley Tongueayment">
                    <title>Zahlungsfrist</title>
                    <type>d:date</type>
                    <mandatory>true</mandatory>
                   
                </property>

                <property name="ivm:distributor">
                    <title>Lieferant</title>
                    <type>d:text</type>
                    <mandatory>true</mandatory>
                   
                </property>

                <property name="ivm:distributorNumber">
                    <title>Lieferanten-Nr.</title>
                    <type>d:text</type>
                    <mandatory>true</mandatory>
                </property>
            </properties>
        </type>
    </types>
</model>

- A external System put periodically two related documents on the CIFS folder: the one document contains a few properties (key/value)-pairs like a java property file or   .ini file under Windows and these properties correspond to the properties of the custom content model i have deployed previously , whreas the other document is a PDF file.

Now, i want to extract the value of each property from the first document and add them to the related (custom content model)-property of the second (PDF) file each time a pair of documents (metada file and related PDF) is entered the CIFS folder. After a PDF document has all required properties set, the related metadata document must be delete automaticaly from the CIFS Folder.

which Alfresco API or mechanism is the best  for such scenario (actions behaviors …?). the actions must run in background

any one can help me please. is urgent.

thanks.
6 REPLIES 6

iblanco
Confirmed Champ
Confirmed Champ
I've done something similar with an XML instead.

I think you should make an action:

An action that executed on a PDF custom type node checks if there is a "ini" file corresponding to the PDF (for example you could use the same name for both the PDF and the INI) and if so it parses it and updates the values of the PDF. After that it should delete the INI file.

Then in the folder use rules:
1- When PDF comes in specialise to custom type
2- When custom type comes in execute the action

The only "caveat" is that you must put the INI file before the PDF in order for this to work.

simo2010
Champ in-the-making
Champ in-the-making
Hi iblanco,
thank you for reply. I have done the steps you described, and this works fine. But i have a problem with the PDF file:
Here is my Action class:
public class InvoiceDataActionExecuter extends ActionExecuterAbstractBase {
   /**
    * The node service
    */
   
   
   private NodeService nodeService;
   private ContentService contentService;
   private ServiceRegistry serviceRegistry;
   private FileFolderService fileFolderservice;
   private SearchService searchService;


   
   /*
    * this method reads the jpl file and extracts the
    */
   
   
   private List<String> readJPLFile(NodeRef ref) {

      contentService = serviceRegistry.getContentService();
      List<String> list = new ArrayList<String>();
      if (contentService != null) {
         ContentReader reader = contentService.getReader(ref,
               ContentModel.PROP_CONTENT);
         if (reader != null) {
            InputStream is = reader.getContentInputStream();
            BufferedReader bf = new BufferedReader(
                  new InputStreamReader(is));
            String line = null;
            int count = 0;
            try {
               if(bf!=null){
               while ((line = bf.readLine()) != null) {
                  count++;
                  System.out.println(line);
                  if (count > 7) {
                     System.out.println(line);
                     line = line.substring(line.indexOf('=') + 2);
                     System.out.println("dies ist line: " + line);

                     //line = line.replaceAll("\"", "");
                     line=line.substring(1, line.lastIndexOf('"'));
                     
                     list.add(line);

                     System.out.println(line);
                  }
               }
            }
            } catch (IOException e) {
               // TODO Auto-generated catch block
               e.printStackTrace();
            }finally{
               
               try {
                  bf.close();
                  is.close();
               } catch (IOException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
               }
            }
         }

      }
      return list;

   }

   @Override
   protected void executeImpl(Action action, NodeRef actionedUponNodeRef) {

      if (this.nodeService.exists(actionedUponNodeRef) == true) {
         fileFolderservice = serviceRegistry.getFileFolderService();
         FileInfo infos = fileFolderservice.getFileInfo(actionedUponNodeRef);
         String pdfFileName = infos.getName();
         System.out.println("Actioned File:" +pdfFileName);
         pdfFileName = pdfFileName.substring(0, pdfFileName.indexOf('.'))
               + ".jpl";
         System.out.println("JPL File:"+pdfFileName);
         StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE,
               "SpacesStore");
         searchService = serviceRegistry.getSearchService();
         resultSet = searchService.query(storeRef,
               SearchService.LANGUAGE_LUCENE,
               "PATH:\"/app:company_home/cm:Dialog_Company\"");
         System.out.println("Node Reference: "+resultSet.getNodeRef(0));
         NodeRef nodeRef=resultSet.getNodeRef(0);
         resultSet.close();
         
         NodeRef fileRef=this.nodeService.getChildByName(nodeRef, ContentModel.ASSOC_CONTAINS, pdfFileName);
         System.out.println("File Ref: "+fileRef);
         
         if (resultSet != null) {

      
            ArrayList<String> properties=(ArrayList<String>) readJPLFile(fileRef);
            
            if(properties!=null && !properties.isEmpty()){
               
            Map<QName,Serializable> properties1   =new HashMap<QName,Serializable>();
            
            QName[] contentProperties = new QName[InvoiceModelProperties.PROPERTIES_SIZE];
      
            contentProperties[0]=InvoiceModelProperties.PROP_DISTRIBUTOR;
            contentProperties[1]=InvoiceModelProperties.PROP_DISTRIBUTOR_NUMBER;
            contentProperties[2]=InvoiceModelProperties.PROP_NUMBER;
            contentProperties[3]=InvoiceModelProperties.PROP_DATE;
            contentProperties[4]=InvoiceModelProperties.PROP_CUSTOMER_NUMBER;
            contentProperties[5]=InvoiceModelProperties.PROP_AMOUNT;
            contentProperties[6]=InvoiceModelProperties.PROP_PAYMENT;
            
            for(int i=0; i<contentProperties.length; i++){
               properties1.put(contentProperties[i], properties.get(i));
            }
            if(!properties1.isEmpty()){
               this.nodeService.setProperties(actionedUponNodeRef, properties1);
            }
         
               
      
            }
               
         }

      }

      
   }

   
   @Override
   protected void addParameterDefinitions(List<ParameterDefinition> paramList) {
      // do Nothing

   }

   
   public void setServiceRegistry(ServiceRegistry serviceRegistry) {
      this.serviceRegistry = serviceRegistry;
   }

   private ResultSet resultSet;

   public FileFolderService getService() {
      return fileFolderservice;
   }

   public void setService(FileFolderService service) {
      this.fileFolderservice = service;
   }

   public ContentService getContentService() {
      return contentService;
   }

   public void setContentService(ContentService myService) {
      this.contentService = myService;
   }

   public NodeService getNodeService() {
      return nodeService;
   }

   public ServiceRegistry getServiceRegistry() {
      return serviceRegistry;
   }

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

}

the problem is that after proccessing dei JPL file and set the properties for the PDF file, the PDF file is coruppt, so that i can't open the PDF file. and Alfresco ends with the following Exception:

The node's content is missing:
   node: workspace://SpacesStore/b8a344d7-a00a-453f-a068-77dc18edd789
   reader: null 
Please contact your system administrator.
should i check out the PDF file before run action and the check in?
i don't know what is wrong in my Action class.

please any idea?

gyro_gearless
Champ in-the-making
Champ in-the-making
As a quick guess:

If you use NodeService#setProperties as you do, this will completely replace (not merge) the nodes properties, including the cm:content property  :evil:

Thus, you should update the properties like this:

Map<QName, Serializeable> props = nodeService.getProperties(nodeRef);
props.put(…); // as often as needed
nodeService.putProperties(nodeRef, props);

As a side note, it is a bad habit sending debug messages with System.out.println() - you should rather use the Commons::Logging framework. This is much more flexible in the long run, as it allows to switch off debugging for a component with a single entry in log4js config file, rather than uncommenting dozens of code lines 🙂

Cheers
Gyro

iblanco
Confirmed Champ
Confirmed Champ
Well it seems like Gyro already answered you.
As a side comment say that in your code I think some things could probably been done in an easier way, for example you could get the Store ref just by calling getStoreRef() method on the actioned node and probably using the nodeService you could use getParentAssocs in its 3 parameter version in order to ask for the "cm:contains" assoc that relates the document to a "cm:folder" node.

simo2010
Champ in-the-making
Champ in-the-making
Hi Gyro and iblanco,

@Gyro
As a side note, it is a bad habit sending debug messages with System.out.println()
thank you for your advice on  logging. I usually use log4j, so i have my own log4j.properties file along with the Action class in a jar, that i have deployed under tomcat/weapp/alfresco/WEB-INF/lib directory, but Alfresco ignores it. i am newbie in alfresco and don't know how to deploy custom log4j.properties, so that it extends Alfresco logging. therefore System.out.print() was the only alternative for my to get log messages.
can you help me in order to get logging with log4j.

I have actually an bigger issue:
i have defined a composite rule with 2 actions:
-Action 1: when PDF file comes –> specialize type (SAP Content Model), then
-Action 2: set the  value of custom property SAP_ID (when JPL file exists and SAP_ID length is 32 char then set property and then detete JPL file, otherwise move  the PDF file into a so called "Fault_Folder")

Now, when i add manually the JPL and PDF files in Web Explorer (Add Content), the rule works fine. but when i add the files through CIFS the Action get twice executed and the following occures in tomcat log :
call doAction()…
actioned Node exists
call makeJPLFileName()…
Actioned PDF Document :DFD213236A8953F196B1000C2952CC11.PDF
related JPL Document :DFD213236A8953F196B1000C2952CC11.jpl
get primary Parent of actioned Node…
ID of Parent of actioned Node: dc89752e-8e1e-4301-8fe6-e5e20116dae6
get Reference of JPL File…
Reference of JPL File: 59924d72-6ff8-46ff-a0fb-895df7bbe0cf
addProperty method entered…
call redJPLFile()…
SAP_IP: DFD213236A8953F196B1000C2952CC11 with length of: 32 character
call setProperty() of node service…
delete JPL file after proccessing…

14:49:25,964 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:25,964  DEBUG [smb.protocol.auth] Using Write transaction
14:49:25,964 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:25,979 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:25,979  DEBUG [smb.protocol.auth] Using Write transaction
14:49:25,979 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:25,995 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:25,995  DEBUG [smb.protocol.auth] Using Write transaction
14:49:26,120 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:26,120  DEBUG [smb.protocol.auth] Using Write transaction
call doAction()…
actioned Node exists
call makeJPLFileName()…
Actioned PDF Document :DFD213236A8953F196B1000C2952CC11.PDF
related JPL Document :DFD213236A8953F196B1000C2952CC11.jpl
get primary Parent of actioned Node…
ID of Parent of actioned Node: dc89752e-8e1e-4301-8fe6-e5e20116dae6
get Reference of JPL File…
14:49:26,229  DEBUG [smb.protocol.auth] Using Write transaction
14:49:26,229 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:26,245 User:admin DEBUG [smb.protocol.auth] Using Write transaction
JPL file doesn't exists …
14:49:26,261 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:26,261  DEBUG [smb.protocol.auth] Using Write transaction
14:49:26,276 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:26,276 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:26,276  DEBUG [smb.protocol.auth] Using Write transaction
14:49:26,276 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:26,292 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:26,292  DEBUG [smb.protocol.auth] Using Write transaction
14:49:26,292 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:26,292 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:26,307  DEBUG [smb.protocol.auth] Using Write transaction
14:49:26,307 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:26,307 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:26,307  DEBUG [smb.protocol.auth] Using Write transaction
14:49:26,323 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:26,339 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:26,339  DEBUG [smb.protocol.auth] Using Write transaction
14:49:26,339 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:26,354 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:26,386  DEBUG [smb.protocol.auth] Using Write transaction
14:49:26,386 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:26,401  DEBUG [smb.protocol.auth] Using Write transaction
14:49:26,401 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:26,511 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:26,526  DEBUG [smb.protocol.auth] Using Write transaction
call move method to move PDF file to fault Folder…
move method entered…
get Store Ref of actioned Node…
get Reference of Faut Folder…
14:49:27,339  DEBUG [smb.protocol.auth] Using Write transaction
14:49:27,354  DEBUG [smb.protocol.auth] Using Write transaction
14:49:27,370 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:27,370  DEBUG [smb.protocol.auth] Using Write transaction
14:49:27,386 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:28,604 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:28,604  DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,526 User:admin DEBUG [smb.protocol.auth] Using Write transaction
Fault Folder Reference is: 1069cc4d-8a17-469c-b0c9-ee4a8e1ba08a
call move method of node  Service to move actioned Node…
14:49:30,526 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,573 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,589  DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,589 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,604 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,604  DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,620  ERROR [repo.action.AsynchronousActionExecutionQueueImpl] Failed to execute asynchronous action: Action[ id=b4183d74-7eca-4c16-ad9e-9632c
ee2b810, node=workspace://SpacesStore/b4183d74-7eca-4c16-ad9e-9632cee2b810 ]
java.lang.NullPointerException
        at org.alfresco.repo.domain.hibernate.ChildAssocImpl.setQName(ChildAssocImpl.java:227)
        at org.alfresco.repo.node.db.hibernate.HibernateNodeDaoServiceImpl$14.doInHibernate(HibernateNodeDaoServiceImpl.java:2254)
        at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:406)
        at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:339)
        at org.alfresco.repo.node.db.hibernate.HibernateNodeDaoServiceImpl.writeChildAssocChanges(HibernateNodeDaoServiceImpl.java:2018)
        at org.alfresco.repo.node.db.hibernate.HibernateNodeDaoServiceImpl.updateChildAssoc(HibernateNodeDaoServiceImpl.java:2262)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
        at org.alfresco.repo.transaction.TransactionalDaoInterceptor.invoke(TransactionalDaoInterceptor.java:62)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
        at org.alfresco.repo.domain.hibernate.DirtySessionMethodInterceptor.invoke(DirtySessionMethodInterceptor.java:413)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
        at org.alfresco.repo.transaction.SingleEntryTransactionResourceInterceptor.invokeInternal(SingleEntryTransactionResourceInterceptor.java:157)
        at org.alfresco.repo.transaction.SingleEntryTransactionResourceInterceptor.invoke(SingleEntryTransactionResourceInterceptor.java:132)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
        at $Proxy8.updateChildAssoc(Unknown Source)
        at org.alfresco.repo.node.db.DbNodeServiceImpl.moveNode(DbNodeServiceImpl.java:2232)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
        at org.alfresco.repo.tenant.MultiTNodeServiceInterceptor.invoke(MultiTNodeServiceInterceptor.java:104)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
        at $Proxy10.moveNode(Unknown Source)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.alfresco.repo.service.StoreRedirectorProxyFactory$RedirectorInvocationHandler.invoke(StoreRedirectorProxyFactory.java:215)
        at $Proxy11.moveNode(Unknown Source)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
        at org.alfresco.repo.node.MLPropertyInterceptor.invoke(MLPropertyInterceptor.java:303)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
        at org.alfresco.repo.node.MLPropertyInterceptor.invoke(MLPropertyInterceptor.java:303)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
        at org.alfresco.repo.node.NodeRefPropertyMethodInterceptor.invoke(NodeRefPropertyMethodInterceptor.java:269)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
        at org.alfresco.repo.node.NodeRefPropertyMethodInterceptor.invoke(NodeRefPropertyMethodInterceptor.java:269)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
        at $Proxy10.moveNode(Unknown Source)
        at lab.ApplySapActionExecutor.moveIncompleteSAPdocument(Unknown Source)
        at lab.ApplySapActionExecutor.doAction(Unknown Source)
        at lab.ApplySapActionExecutor.executeImpl(Unknown Source)
        at org.alfresco.repo.action.executer.ActionExecuterAbstractBase.execute(ActionExecuterAbstractBase.java:133)
        at org.alfresco.repo.action.ActionServiceImpl.directActionExecution(ActionServiceImpl.java:726)
        at org.alfresco.repo.action.executer.CompositeActionExecuter.executeImpl(CompositeActionExecuter.java:66)
        at org.alfresco.repo.action.executer.ActionExecuterAbstractBase.execute(ActionExecuterAbstractBase.java:133)
        at org.alfresco.repo.action.ActionServiceImpl.directActionExecution(ActionServiceImpl.java:726)
        at org.alfresco.repo.action.ActionServiceImpl.executeActionImpl(ActionServiceImpl.java:658)
        at org.alfresco.repo.action.AsynchronousActionExecutionQueueImpl$ActionExecutionWrapper$1$1.execute(AsynchronousActionExecutionQueueImpl.java:
494)
        at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:325)
        at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:232)
        at org.alfresco.repo.action.AsynchronousActionExecutionQueueImpl$ActionExecutionWrapper$1.doWork(AsynchronousActionExecutionQueueImpl.java:503
)
        at org.alfresco.repo.security.authentication.AuthenticationUtil.runAs(AuthenticationUtil.java:508)
        at org.alfresco.repo.action.AsynchronousActionExecutionQueueImpl$ActionExecutionWrapper.run(AsynchronousActionExecutionQueueImpl.java:506)
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
        at java.lang.Thread.run(Thread.java:619)
14:49:30,620 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,636 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,651  DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,651  DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,651  DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,651 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,667 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,667 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,667 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,667  DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,683  DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,683 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,698 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,714  DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,714 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,729 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,745 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,745  DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,745 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,745 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,745  DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,761 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,761  DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,761 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,761 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,776  DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,776 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,776 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,776  DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,808  DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,808 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,823 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,839 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,839  DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,854 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,854  DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,854 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,854  DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,854 User:admin DEBUG [smb.protocol.auth] Using Write transaction
14:49:30,870 User:admin DEBUG [smb.protocol.auth] Using Write transaction

i understand the NullpointerException, because JPL file was deleted, but i can't understand why the doAction method get twice executed. I copy the 2 files simultaneously to the CIFS folder (Drag & drop). that means JPL exists at execution time (and the SAP_ID field is exaclly 32 char). No reason to move the PDF file.

here is my updated Action Class (sorry still with bad logging from System.out):
package lab;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

import org.alfresco.model.ContentModel;
import org.alfresco.repo.action.executer.ActionExecuterAbstractBase;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.model.FileExistsException;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.search.ResultSet;
import org.alfresco.service.cmr.search.SearchService;
import org.apache.log4j.Logger;

public class ApplySapActionExecutor extends ActionExecuterAbstractBase {
   private NodeService nodeService;
   private ContentService contentService;
   private ServiceRegistry serviceRegistry;
   private static final Logger sLogger = Logger
         .getLogger(ApplySapActionExecutor.class);

   private void doAction(NodeRef actionedUponNodeRef) {

      if (this.nodeService.exists(actionedUponNodeRef) == true) {

         
         System.out.println("call makeJPLFileName()…");
         String jplFileName = this.makeJPLFileName(actionedUponNodeRef);

         System.out.println("get primary Parent of actioned Node…");
         ChildAssociationRef childAss = this.nodeService
               .getPrimaryParent(actionedUponNodeRef);
         NodeRef parent = childAss.getParentRef();

         sLogger.info("ID of Parent of actioned Node: " + parent.getId());
         System.out.println("ID of Parent of actioned Node: "
               + parent.getId());
         try {
            //wait 2 s for JPL file
            Thread.sleep(2000);
            System.out.println("get Reference of JPL File…");
            NodeRef jpl = this.nodeService.getChildByName(parent,
                  ContentModel.ASSOC_CONTAINS, jplFileName);
            if (jpl != null) {
               System.out.println("Reference of JPL File: " + jpl.getId());

               this.setProperty(jpl, actionedUponNodeRef);

            } else {
               
               System.out.println("JPL file doesn't exists …");
               System.out
                     .println("call move method to move PDF file to fault Folder…");
               
               //JPL file does not exists—> move PDF file to fault folder
               this.moveIncompleteSAPdocument(actionedUponNodeRef);
            }
         } catch (InterruptedException e) {

            System.out
                  .println("call move method in catch block  to move PDF file to fault Folder…");
            this.moveIncompleteSAPdocument(actionedUponNodeRef);
            e.printStackTrace();
         }

      }

   }

   private void moveIncompleteSAPdocument(final NodeRef actionedUponNodeRef) {
      System.out.println("move method entered…");
      System.out.println("get Store Ref of actioned Node…");
      StoreRef storeRef = actionedUponNodeRef.getStoreRef();

      System.out.println("get Reference of Faut Folder…");
      ResultSet resultSet = this.serviceRegistry.getSearchService().query(
            storeRef, SearchService.LANGUAGE_LUCENE,
            "PATH:\"/app:company_home/cm:Fault_Folder\"");
      NodeRef faultFolder = resultSet.getNodeRef(0);
      if (faultFolder != null)
         System.out.println("Fault Folder Reference is: "
               + faultFolder.getId());

      try {
         System.out
               .println("call move method of node  Service to move actioned Node…");

         ChildAssociationRef assoc = this.nodeService.moveNode(
               actionedUponNodeRef, faultFolder,
               ContentModel.ASSOC_CONTAINS, null);
         if (assoc != null) {
            System.out.println("ChildAssociation Ref is: "
                  + assoc.toString());
         } else {
            System.out.println("Node can't be moved …");
         }
      } catch (FileExistsException e) {

         e.printStackTrace();
      } finally {
         resultSet.close();
      }

   }
   
   //make construct JPL file name

   private String makeJPLFileName(NodeRef actionedUponNodeRef) {
      String jplFileName = null;
      String pdfFileName = null;

      pdfFileName = (String) this.nodeService.getProperty(
            actionedUponNodeRef, ContentModel.PROP_NAME);
      sLogger.info("Actioned PDF Document :" + pdfFileName);
      System.out.println("Actioned PDF Document :" + pdfFileName);
      jplFileName = pdfFileName.substring(0, pdfFileName.lastIndexOf('.'))
            + ".jpl";
      sLogger.info("related JPL Document :" + jplFileName);
      System.out.println("related JPL Document :" + jplFileName);
      return jplFileName;

   }

   //set  value of  custom property SAP ID
   private void setProperty(final NodeRef ref,
         final NodeRef actionedUponNodeRef) {
      System.out.println("addProperty method entered…");
      ArrayList<String> properties;
      try {
         System.out.println("call redJPLFile()…");
         properties = (ArrayList<String>) this.readJPLFile(ref);

         if (properties != null && !properties.isEmpty()) {
            final String sapId = properties.get(0);
            if (sapId.length() < 32 || sapId.length() > 32) {
               System.out
                     .println("Length of SAP_ID was less than 32 char… ");
               this.moveIncompleteSAPdocument(actionedUponNodeRef);
               return;
            }
            System.out.println("call setProperty() of node service…");
            this.nodeService.setProperty(actionedUponNodeRef,
                  SAPMetaDataModelProperties.PROP_SAP_ID,
                  properties.get(0));

         }
         // this.moveIncompleteSAPdocument(actionedUponNodeRef);
      } catch (IOException e) {

         e.printStackTrace();
      } finally {
         if (ref != null) {
            //finally delete the JPL file
            System.out.println("delete JPL file after proccessing…");
            nodeService.addAspect(ref, ContentModel.ASPECT_TEMPORARY, null);
            nodeService.deleteNode(ref);
         }
      }
   }

   
   private List<String> readJPLFile(NodeRef ref) throws IOException {
      serviceRegistry.getCheckOutCheckInService();
      contentService = serviceRegistry.getContentService();
      List<String> list = new ArrayList<String>();
      if (contentService != null) {
         ContentReader reader = contentService.getReader(ref,
               ContentModel.PROP_CONTENT);
         if (reader != null) {
            InputStream is = reader.getContentInputStream();
            BufferedReader bf = new BufferedReader(
                  new InputStreamReader(is));
            String line = null;
            int count = 0;
            try {
               if (bf != null) {
                  while ((line = bf.readLine()) != null) {
                     count++;

                     if (count == 3) {

                        line = line.substring(line.indexOf('=') + 1);
                        sLogger.info("SAP_IP: " + line
                              + " with length of: " + line.length()
                              + " character");
                        System.out.println("SAP_IP: " + line
                              + " with length of: " + line.length()
                              + " character");
                        list.add(line);

                     }
                  }
               }
            } catch (IOException e) {
               sLogger.error(e.getMessage());
               e.printStackTrace();
            } finally {
               bf.close();
               is.close();

            }
         }
      }
      return list;

   }

   /**
    * @see org.alfresco.repo.action.executer.ActionExecuterAbstractBase#executeImpl(org.alfresco.service.cmr.action.Action,
    *      org.alfresco.service.cmr.repository.NodeRef)
    */
   @Override
   protected void executeImpl(Action action, NodeRef actionedUponNodeRef) {
      System.out.println("call doAction()…");
      doAction(actionedUponNodeRef);

   }

   /**
    * @see org.alfresco.repo.action.ParameterizedItemAbstractBase#addParameterDefinitions(java.util.List)
    */
   @Override
   protected void addParameterDefinitions(List<ParameterDefinition> paramList) {
      // No parameters so do nothing
   }

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

   public void setServiceRegistry(ServiceRegistry serviceRegistry) {
      this.serviceRegistry = serviceRegistry;
   }

}

what is wrong?
please help me.

thanks

iblanco
Confirmed Champ
Confirmed Champ
Sorry, I'll be out of the office for a couple of weeks and can't check it very thoroughly. Are you sure the rule is firing just over PDF files ?

Maybe the CIFS protocol does use a temporary PDF file or something like that ? Could you try to log the name of the actioned node ? That would show you if it is really acting upong the right node, or just print the nodeRef for the actioned node to see if it is fireng twice in the same node.

Behaviours do have such problems as executing twice (unless you specify it to be executed jsut once per transaction), but I'm not aware of such a problem with the rules engine.