Class MandatoryOnOtherFieldValueConstraint

java.lang.Object
com.apgar.common.lib.constraint.BundledConstraint
com.apgar.common.lib.constraint.MandatoryOnOtherFieldValueConstraint
All Implemented Interfaces:
com.orchestranetworks.schema.Constraint<Object>, com.orchestranetworks.schema.ConstraintOnNull, com.orchestranetworks.schema.JavaBeanVersion

public class MandatoryOnOtherFieldValueConstraint extends BundledConstraint implements com.orchestranetworks.schema.Constraint<Object>, com.orchestranetworks.schema.ConstraintOnNull
Constraint that sets mandatory the field it is defined on if the parameter mandatoringField field has the same value as the parameter mandatoringValue.

The error message and/or information message created in the error.properties and text.properties files respectively will be displayed if the constraint is not verified.

  • error.properties to be set: constraint.com.apgar.common.lib.constraint.MandatoryOnOtherFieldValueConstraint Field '{0}' is mandatory when field '{1}' = '{2}'
  • text.properties to be set: constraint.com.apgar.common.lib.constraint.MandatoryOnOtherFieldValueConstraint Mandatory when field '{0}' = '{1}'

Supported types: string, int, integer, decimal, boolean

This constraint is defined in the XSD under the field and takes for argument the path of the second mandatoring field and the mandatoring value.

 <xs:element name="sampleField" minOccurs="0" maxOccurs="1">
     <xs:annotation>
         <xs:documentation xml:lang="en-US">
             <osd:label>Sample Field</osd:label>
         </xs:documentation>
         <xs:appinfo>
             <osd:otherFacets>
             <osd:constraint class="com.apgar.common.lib.constraint.MandatoryOnOtherFieldValueConstraint">
                 <mandatoringField>./field</mandatoringField>
                 <mandatoringValue>value</mandatoringValue>
             </osd:constraint>
             </osd:otherFacets>
         </xs:appinfo>
     </xs:annotation>
 </xs:element>
 
Author:
APGAR Consulting
  • Constructor Details

    • MandatoryOnOtherFieldValueConstraint

      public MandatoryOnOtherFieldValueConstraint()
  • Method Details

    • checkOccurrence

      public void checkOccurrence(Object value, com.orchestranetworks.instance.ValueContextForValidation valueContext) throws com.orchestranetworks.schema.InvalidSchemaException
      Performs constraint check and raise warning/error accordingly
      Specified by:
      checkOccurrence in interface com.orchestranetworks.schema.Constraint<Object>
      Throws:
      com.orchestranetworks.schema.InvalidSchemaException
      See Also:
      • Constraint.checkOccurrence(java.lang.Object, com.orchestranetworks.instance.ValueContextForValidation)
    • setup

      public void setup(com.orchestranetworks.schema.ConstraintContext context)
      Preliminary check of parameters and formatting to perform constraint check
      Specified by:
      setup in interface com.orchestranetworks.schema.Constraint<Object>
      See Also:
      • Constraint.setup(com.orchestranetworks.schema.ConstraintContext)
    • checkNull

      public void checkNull(com.orchestranetworks.instance.ValueContextForValidation valueContext) throws com.orchestranetworks.schema.InvalidSchemaException
      Performs constraint check in case of both null and raise warning/error accordingly
      Specified by:
      checkNull in interface com.orchestranetworks.schema.ConstraintOnNull
      Throws:
      com.orchestranetworks.schema.InvalidSchemaException
      See Also:
      • ConstraintOnNull.checkNull(com.orchestranetworks.instance.ValueContextForValidation)
    • toUserDocumentation

      public String toUserDocumentation(Locale locale, com.orchestranetworks.instance.ValueContext valueContext) throws com.orchestranetworks.schema.InvalidSchemaException
      Returns constraint message
      Specified by:
      toUserDocumentation in interface com.orchestranetworks.schema.Constraint<Object>
      Throws:
      com.orchestranetworks.schema.InvalidSchemaException
    • getMandatoringField

      public com.orchestranetworks.schema.Path getMandatoringField()
      Gets the mandatoring field path
      Returns:
      the mandatoring field path
    • setMandatoringField

      public void setMandatoringField(String mandatoringField)
      Sets the mandatoring field
      Parameters:
      mandatoringField - the mandatoringField to set
    • getMandatoringValue

      public Object getMandatoringValue()
      Gets the mandatoring value
      Returns:
      mandatoringValue
    • setMandatoringValue

      public void setMandatoringValue(String mandatoringValue)
      Sets the mandatoring value according to its type
      Parameters:
      mandatoringValue - mandatoringValue