cancel
Showing results for 
Search instead for 
Did you mean: 

Please help ActionExecuter and catching ConstraintViolation

alexr
Champ in-the-making
Champ in-the-making
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
2 REPLIES 2

alexr
Champ in-the-making
Champ in-the-making
Through Alfresco Support (ACT) I found out what transaction to use to make the commit work inside
the ActionExecuter type class:

I have implemented thetransactionService.getNonPropagatingUserTransaction();  for committing the transactions.
That works fine now.

The ConstraintViolation Exceptions still can not be caught (not even by Exception or Throwable), but we modified the ConsistencyChecker behaviour through:

custom-node-service-context.xml:

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>

<!– Beans pertinent to node persistence and services –>
<beans>


   <!– ensures model-compliance of node structures –>
   <bean id="integrityChecker" class="org.alfresco.repo.node.integrity. IntegrityChecker" init-method="init">
      <property name="policyComponent">
         <ref bean="policyComponent"/>
      </property>
      <property name="dictionaryService">
         <ref bean="dictionaryService" />
      </property>
      <property name="nodeService">
         <ref bean="nodeService" />
      </property>
      <property name="enabled">
         <value>true</value>  <!– on/off switch –>
      </property>
      <property name="traceOn">
         <value>false</value>  <!– use only to trace problems –>
      </property>
      <property name="failOnViolation" >
         <value>${integrity.failOnError}</value>
      </property>
      <property name="maxErrorsPerTransaction" >
         <value>100000</value>  <!– limit output (exception and log) to the first N violation messages –>
      </property>
   </bean>

</beans>
—————————-
Changed the following setting in our application.properties:
integrity.failOnError=false
—————————-
Changed the loglevel in the log4j.properties to "WARN"

So now the ConstraintViolation exceptions still aren't caught. But the document with a constraint violation is still processed.
We have to check the alfresco.log after each "import" batch to see what noderef got a ConstraintViolation and these properties changed manually afterwards. Of course hopefully there aren't too many constraint violations during the process of these batches Smiley Happy

Regards,

Alex

lee
Champ in-the-making
Champ in-the-making
Has anyone found a solution to catching integrity violations in a transaction? I have a similar problem where a webscript performs some action on content (for example creating a node or updating the name of a node), however the script will NOT catch any integrity or constraint violations.

Simplest example is a script that creates a node with a name that has a "|" (a pipe char) in it. This will cause an integrity exception that appears in the logs, but the webscript is oblivious to it. I can't catch it either.

I've used this code similar to this:

try{
   props.put(ContentModel.PROP_NAME, "test|pipe");
   nodeService.createNode(parent, assocQName, nodeName, type, props);
}
catch (IntegrityException ie){
   log.error("FOUND INTEGRITY EXCEPTION " + ie);
}
catch(ConstraintException ce){
   log.error("FOUND CONSTRAINTEXCEPTION " + ce);
}

Has anyone found a solution to this?  I suspect it's because the integrity checker runs as a behaviour.. and therefore is outside of the code that can be caught by any try/catch statements.

However, there must be a solution to this, because the web client catches integrity violations during a save of a node. Any suggestions?

Thanks in advance for your help
Lee
Getting started

Tags


Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.