AnsweredAssumed Answered

Please help ActionExecuter and catching ConstraintViolation

Question asked by alexr on Oct 8, 2008
Latest reply on Feb 22, 2010 by lee
On a Alfresco 2.2 Enterprise/MySQL installation, I have encountered two issues while developing a Alfresco Java application to import a large number of documents (several thousands).
The import is started by an inbound content rule on an added csv-file (delimited data).
One csv-file contains multiple lines of metadata corresponding to the batch of documents to be imported.

The inbound content rule calls ImportFilesActionExecuter.


public class ImportFilesActionExecuter extends
      ActionExecuterAbstractBase implements InitializingBean


with the following method:

protected void executeImpl(final Action ruleAction, final NodeRef actionedUponNodeRef) {
….//all the processing actions have been put here.
}



I have encountered two issues when importing files.


1) Only the exception on a Constraint Violation (Integrity Check error) by a nodeService.SetProperty can not be caught
for some reason. I have tried the standard catch(Exception e), catch(Throwable th), catch(ConstraintException e)
,catch(IntegrityException) etc. The result is always the same. The exception is not caught, but the result
is that the overall action fails with no results, whereas there are a great number of files that should have
been processed correctly. How can I catch a ConstraintViolation (error on setting a property value not in the constraint-list)?
Why does catch(Exception e) not work? It should catch any exception.
 

        //** Set Test Property
   ArrayList<Serializable> valueList = new ArrayList<Serializable>(st.countTokens());
   int i = 0;
   while (st.hasMoreTokens()) {
                 valueList.add(st.nextToken()); i++;
   }                                             
   try   
   {
     nodeService.setProperty(docFound, ImportFilesActionExecuter.KEYWORD_PROPERTY_NAME , valueList);
   }
   catch(Exception e)
   {     
      //Do something here
   }      
                                    
        /** Alternatives
   catch(Throwable th) 
        catch(ConstraintException ce)
   catch(IntegrityException ie)
        **/


2) The other issue is that this ActionExecuter class (as default used for Content Rules) processes
all "transactions" as a single action. I read on the WiKi that an ActionExecuter is meant for processing
1 (one) content item (i.e. actioned upon noderef).
If so how can I still realize to make a Java class that is started by an inbound content rule triggered by
the addition of a CSV-file to a FolderSpace with the inbound rule. The Java class should processes all documents immediately (committing immediately all transactions per document)
at the moment the action is called (set property, change type, move document etc.), also having control over logging ad hoc on each individual
document and not having all the transactions being committed(executed) at the end of processing resulting in
either a total success or total failure (in case one un-catchable exception occurs).

(I already tried to implement a UserTransaction via the ServiceRegistry using :

UserTransaction trx = serviceRegistry.getTransactionService().getUserTransaction();

and then

     trx.begin()
    //action here
     trx.commit();

etc.

However that doesn't work either. The transactions still are only committed at the end of the ActionExecuter class)


Can anybody please help me with these issues.

Regards,

Alex

Outcomes