cancel
Showing results for 
Search instead for 
Did you mean: 

Conditional aspects?

probert
Champ in-the-making
Champ in-the-making
Hi,

I have a document model like this;

<type name="oaciqdt:docLfermAssist">
  <title>lferm-assist</title>
  <parent>oaciqdt:docAssistanceSyndic</parent>
  <mandatory-aspects>
    <aspect>oaciqdt:aspectIntervenant</aspect>
    <aspect>oaciqdt:aspectIdentifiantIntervenant</aspect>
    <aspect>oaciqdt:aspectNumsPermis</aspect>
  </mandatory-aspects>
</type>   

The issue we have is that oaciqdt:aspectNumsPermis should be conditional, e.g. it should be mandatory if a value for the property who is part of that aspect is not null. The aspect is like this:

<aspect name="oaciqdt:aspectNumsPermis">
  <title>License numbers</title>
  <properties>
    <property name="oaciqdt:numsPermis">
      <type>d:text</type>
      <multiple>true</multiple>
      <constraints>
        <constraint name="oaciqdt:numsPermisREGEX" type="REGEX">
          <parameter name="expression"><value>[A-Za-z]{1}[0-9]{4}</value></parameter>
          <parameter name="requiresMatch"><value>true</value></parameter>
        </constraint>
      </constraints>
     </property>
  </properties>
</aspect>

So in short, if oaciqdt:numsPermis is empty, I don't want the validation to occur, but if the value is not empty, the regex should be run.

Looking at the documentation, I don't see how you can define a property to validate only if a value is present, and I don't see how we can make the aspect to be conditional if the value is empty.

Any tricks?
1 REPLY 1

michaelböckling
Champ in-the-making
Champ in-the-making
Hi,

this cannot be done using the regular constraints, this is true. What you could do is register a policy that will trigger whenever a node property changes, there you can check whatever you want in regular Java code.
See here to get you started: http://wiki.alfresco.com/wiki/Policy_Component

Cheers,
Michael