cancel
Showing results for 
Search instead for 
Did you mean: 

No Constraints in PropertyList

ddanninger
Champ in-the-making
Champ in-the-making
Hi,

i try to get a list of a custom Content model. It works so far, but if i want to know the Constraints of a Property its just blank. How comes? Did i do something wrong or is it a bug?

So if i get the JSON Result of the WebScript: "http://192.168.254.128:8080/alfresco/service/api/classes/cx_doc/property/cx_language"

It returns me :

{

    * name: "cx:language"
    * title: "Language"
    * defaultValues: ""
    * dataType: "d:text"
    * multiValued: true
    * mandatory: false
    * enforced: false
    * protected: false
    * indexed: true
    * indexedAtomically: true
    * constraints: [ ]
    * url: "/api/property/cx_language"

}

But i added some Constraints to the Custom Content Model see my Snippets:


…..
…..
…..
<constraint name="cx:languageList" type="LIST">
            <parameter name="allowedValues">
                <list>
                    <value>German</value>
                    <value>English</value>
                    <value>Russian</value>
          <value>Italian</value>
          <value>Turkish</value>
          <value>Czech</value>
          <value>Slovak</value>
          <value>Hungarian</value>
                    <value>Serb</value>
                    <value>Uzbek</value>
                    <value>Spanish</value>
                </list>
            </parameter>
        </constraint>

….
….
….

<property name="cx:language">
               <title>Language</title>
               <type>d:text</type>
               <multiple>true</multiple>
               <constraints>
                  <constraint ref="cx:languageList" />
               </constraints>
            </property>


Does anybody have an idea whats going on in here?

Best regards
Dominik


I use the Alfresco 3.3 Community Version on Debian Lenny
12 REPLIES 12

ddanninger
Champ in-the-making
Champ in-the-making
Hi,
its already a few months ago.

Does nobody has the same Problem ? Even in the Webscripts its commented out to recieve the Constraints and show it in the Output.

How can u recieve the Constraints then?

In 3.3G its possible to use the Form generation Webservice and u could recieve the Constraints then. But if i just want to get the Metadata information of content type its for me not possible to read the constraints. Because the form generation service just can recieve the metadata information of a node.

So how do u do that?

cszamudio
Champ on-the-rise
Champ on-the-rise
Hi,

I'm stuck on this problem as well.  I don't yet see a way to retrieve the lists of constraints on a Property. I've created a LIST for a constraint just as you've done, and I can't retrieve it for the life of me.  I've tried using both the SOAP-based DictionaryService and the web scripts as you've done.  Neither one gives up this information (as far as I can tell).  The SOAP-based DictionaryService does provide one piece of information that's not available from the Web Scripts - the default value.

I'm trying to construct a bulk-load wizard that would allow the user to select from a selection list for populating a property. If you've found a solution, I'd sure be pleased to hear it.

Cheers,
Carlos S. Zamudio

cszamudio
Champ on-the-rise
Champ on-the-rise
I'm thinking there's a bug in the .ftl (below) for generating the constraints output in the JSON format. I can't find any property constraint where this FreeMarker template generates to correct output. Maybe someone with FTL expertise can comment/advise.

Carlos S. Zamudio


<#macro propertyDefJSON propertydefs>
    <#escape x as jsonUtils.encodeJSONString(x)>
    {
        <#if propertydefs.name?exists>
        "name" : "${propertydefs.name.toPrefixString()}",
        </#if>
        <#if propertydefs.title?exists>
        "title" : "${propertydefs.title}",
        </#if>
        <#if propertydefs.description?exists>
        "description" : "${propertydefs.description}",
        </#if>
        <#if propertydefs.defaultValues?exists>
        "defaultValues" : "${propertydefs.defaultValues}",
        <#else>
        "defaultValues" : "",
        </#if>
        <#if propertydefs.dataType?exists>
        "dataType" : "${propertydefs.dataType.name.toPrefixString()}",
        </#if>
        "multiValued" : ${propertydefs.multiValued?string},
        "mandatory" : ${propertydefs.mandatory?string},
        "enforced" : ${propertydefs.mandatoryEnforced?string},
        "protected" : ${propertydefs.protected?string},
        "indexed" : ${propertydefs.indexed?string},
        "indexedAtomically" : ${propertydefs.indexedAtomically?string},
        "constraints" :
        [<#–
        <#if propertydefs.constraints?exists>
            <#list propertydefs.constraints as constraintdefs>
        {
                <#assign keys = constraintdefs.getConstraint()?keys>
                <#list keys as key>
                    <#if key == "expression">
            "${key}" : <#if constraintdefs.getConstraint()[key]?exists>"${constraintdefs.getConstraint()[key]}" <#else>"has no value"</#if>
                    </#if>
                    <#if key_has_next>,</#if>  
                </#list>
        }<#if constraintdefs_has_next>,</#if>
            </#list>
        </#if>–>
        ],
        "url" : "${"/api/property/" + propertydefs.name.toPrefixString()?replace(":","_")}"
    }
    </#escape>
</#macro>

cszamudio
Champ on-the-rise
Champ on-the-rise
OK, obviously as I look a bit closer, the constraints portion of the ftl has been commented out. So, this explains why we get no constraints for any properties.

scouil
Star Contributor
Star Contributor
Hi,

I had the problem too and decided to extend the file above to solve it.
If someone still needs it:


"restricValues" :
[
   <#if propertydefs.constraints?exists>
      <#list propertydefs.constraints as constraintdefs>
         <#list constraintdefs.getConstraint()?keys as key>
            <#if key == "getAllowedValues">
               <#assign vals = constraintdefs.getConstraint().getAllowedValues()>
               <#list vals as val>
   "${val}"
   <#if val_has_next>,</#if>
               </#list>
            </#if>
         </#list>
      </#list>
   </#if>
]

It might not be optimal since I'm not really familiar with alfresco API but… Well… It works.
And it doesn't seem to break anything.

Scouil

ddanninger
Champ in-the-making
Champ in-the-making
Yes thats nice thanks,
but actually i think it would be great that it will be also in the new community release… i got promised in paris on the devcon it will be fixed in the next version but still an open issue in jira

ryanbobko
Champ in-the-making
Champ in-the-making
Just to be clear: did you change the .ftl that comes with Alfresco to get this to work? Is there a solution without modifying Alfresco directly? Thanks.

scouil
Star Contributor
Star Contributor
Yes this was done by modifying one of the default alfresco webservices:
<TOMCAT HOME>\webapps\alfresco\WEB-INF\classes\alfresco\templates\webscripts\org\alfresco\repository\dictionary\propertydefinition.lib.ftl

Since that's a webservice I think that you should be able to create your own webservice similarly and deploy it as a webscript extension but I'm not familiar with the macro system.

cszamudio
Champ on-the-rise
Champ on-the-rise
Just FYI. I ended up replacing the Alfresco version of the .ftl file with the edited version. The fact that someone explicitly commented out parts of the file made me nervous, but I've not seen any problems. Of course, I've had to remember this change whenever I upgraded. (-;