AnsweredAssumed Answered

[Solved] Property Integrity Checking in Webscript

Question asked by hyperation on Apr 29, 2010
Latest reply on Apr 29, 2010 by hyperation
Hi Everyone,

I am having trouble trying to figure out how to do Property Value Integrity check within a Java-backed web script.

I have a webscript that allows a user to change property values of an object.  The webscript extends DeclarativeWebscript and the executeImpl method has been override with mechanisms to update an object's property.  I have noticed that Alfresco itself does an Integrity Check for property value updates, but it does not invoked during the webscript execution (it does it after). 
So for instance, I have the following constraint:

         <property name="testdoc:test_number">
            <title>Test Number</title>
            <type>d:text</type>
            <mandatory>true</mandatory>
            <constraints>
               <constraint type="MINMAX">
                  <parameter name="minValue">
                     <value>0</value>
                  </parameter>
                  <parameter name="maxValue">
                     <value>9</value>
                  </parameter>
               </constraint>
            </constraints>
         </property>   

In my webscript I run this code:


public class UpdateProperties extends DeclarativeWebScript {

    @Override
    protected Map<String, Object> executeImpl(WebScriptRequest request, Status status) {
     …
        nodeService.setProperty(NODEREF_OF_THE_OBJECT, QNAME_OF_TEST_NUMBER, "9001");
    …
        return model
    }

}

When the webscript is called, it successfully completes and returns from the executeImpl method.  But since the value inputted does not match the constraint declared, the IntegrityChecker (which is ran after the webscript, automatically) prompts an integrity error that looks like:


Invalid property value:
   Node: workspace://SpacesStore/a04691ca-d154-4944-908d-ebf9693475e1
   Type: {testspace}testdoc
   Property: {testdoc}test_number
   Constraint: 03270012 Numeric value '9001' is not in range [0; 9]
at org.alfresco.repo.node.integrity.IntegrityChecker.checkIntegrity(IntegrityChecker.java:667)
at org.alfresco.repo.transaction.AlfrescoTransactionSupport$TransactionSynchronizationImpl.beforeCommit(AlfrescoTransactionSupport.java:689)
at org.springframework.transaction.support.TransactionSynchronizationUtils.triggerBeforeCommit(TransactionSynchronizationUtils.java:48)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.triggerBeforeCommit(AbstractPlatformTransactionManager.java:835)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:645)
at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:632)
at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:314)
at org.alfresco.util.transaction.SpringAwareUserTransaction.commit(SpringAwareUserTransaction.java:467)
at org.alfresco.repo.transaction.RetryingTransactionHelper.doInTransaction(RetryingTransactionHelper.java:349)


What I need is to do is to have the Integrity Check done inside the webscript so I can return the constraint violation back to the caller of the webscript.

Anyone have any suggestions, idea? I'm open for anything.

Thanks
:)

Outcomes