cancel
Showing results for 
Search instead for 
Did you mean: 

Obtain a List with a constraint list allowed values

falcon
Champ in-the-making
Champ in-the-making
Hi,
I have defined a custom type metadata, like this:

<constraints>
   <constraint name="my:constraintList" type="LIST">
      <parameter name="allowedValues">
         <list>
            <value>OPTION 1</value>
            <value>OPTION 2</value>
            <value>OPTION 3</value>
         </list>
      </parameter>
      <parameter name="caseSensitive">
         <value>false</value>
      </parameter>
   </constraint>
</constraints>
<types>
<type name="my:typeTest">
   <title>TEST TYPE</title>
   <parent>cm:content</parent>
      <properties>
      
         <property name="my:propertyTest">
            <title>TEST PROPERTY</title>
            <type>d:text</type>
            <mandatory>false</mandatory>
            <constraints>
              <constraint ref="my:constraintList" />
           </constraints>
         </property>
                  </properties>
</type>
</types>

How can I have a List in Java or Javascritp of the allowed values of my constraint to send it by a webscript?

Thanks for help Smiley Happy
11 REPLIES 11

jayjayecl
Confirmed Champ
Confirmed Champ

/**
     * Method returns a list of constraint values for the given property.
     *
     * @param dictionaryService
     *            - might be null, in this case the default dictionaryService
     *            (send by this.getDictionaryService()) will be used
     * @param qname
     *            - property
     * @return
     */
    public static ListOfValuesConstraint getListOfValuesConstraint(
            DictionaryService dictionaryService, QName qname) {

        ListOfValuesConstraint lovConstraint = null;
        PropertyDefinition propertyDef = null;

        // get the property definition for the item
        if (dictionaryService == null) {
            propertyDef = getDictionaryService().getProperty(qname);
        } else {
            propertyDef = dictionaryService.getProperty(qname);
        }

        if (propertyDef != null) {
            // go through the constaints and see if it has the
            // list of values constraint
            List<ConstraintDefinition> constraints = propertyDef
                    .getConstraints();

            for (ConstraintDefinition constraintDef : constraints) {
                Constraint constraint = constraintDef.getConstraint();

                if (constraint instanceof ListOfValuesConstraint) {
                    lovConstraint = (ListOfValuesConstraint) constraint;
                    break;
                }
            }
        }

        return lovConstraint;
    }

call it with :
getListOfValuesConstraint(dictionaryService, QName.createQName(
            "yourURI",
            "propertyTest");

falcon
Champ in-the-making
Champ in-the-making
Thanks for your reply!

I dont understand where I can find DictionaryService.

Can you give me an example please?

jayjayecl
Confirmed Champ
Confirmed Champ
this bean will be injected by Spring IoC layer… see faces-config-beans.xml, or any file in tomcat/shared/classes/alfresco/extension that ends up with "-context.xml" to see how services are built

falcon
Champ in-the-making
Champ in-the-making
I have it!

Thanks for reply Smiley Happy (and for your patience)

jayjayecl
Confirmed Champ
Confirmed Champ
No problem

good luck

wesse
Champ in-the-making
Champ in-the-making
Is there any way of using the translation functionality for a List constrains ?
i.e  is there a <label> tag you can use or something ?

<value label="id-aaa">aaaa</value>

/Mikael

mwildam
Champ in-the-making
Champ in-the-making
I also want to obtain the list of constraint values, however, the obove mentioned line:
propertyDef.getConstraints();
I don't have a getContraints member in PropertyDefinition class. I use the remote WebService API from Alfresco 3.2.
What am I doing wrong?

ricvieira
Champ in-the-making
Champ in-the-making
I also need to get a list of values from a contraint using WebServices API, but I cant find it anywhere

Can someone help please ?

tnx