cancel
Showing results for 
Search instead for 
Did you mean: 

Model constraints from a config file

darkredd
Star Contributor
Star Contributor
Good day,

I would like to know if possible, how I can read a config file to populate my model. I have a long list of values (not exhaustive); that need to be put as a constraint in my model. Placing the list directly would create havoc as the list can grow bigger, smaller or change of list display values.

My question is, is there a way to have a config file that can be read into a model dynamically. I need this to be part of a workflow form field.

Any guidance would be much appreciated.
4 REPLIES 4

hardik1512
Star Contributor
Star Contributor
Hello,

I guess what you are looking for is creating a custom constraint. You can create a custom constraint that extends ListOfValuesConstraint and fetches allowedValues from another file.And then you apply this constraint to property in your model file.

You can find an example here.
http://govindaroul.blogspot.in/2013/10/dynamic-list-constraints-in-alfresco.html

Here instead of DB, you can read from file.

Hope this helps.

darkredd
Star Contributor
Star Contributor
Hello Hardik,

Thank you for the reply, it certainly helped. However I am unable to get the data out of the file, if I run the class as a standalone data is retrieved; which led me to suspecting that my path is not conforming to the Alfresco standard.
I place the jar file in the Alfresco/lib folder, and the text file is inside the jar under this structure "src/".
Do you know if there is a specific path to be used in instances as this, perhaps the META-INF folder?
Please share such a declaration if you know.

hardik1512
Star Contributor
Star Contributor
You can try below approach.
1) Upload text file in some folder on alfresco server.
2) Get file nodeRef by using searchservice and lucene query.
3) Use contentservice and contentreader to read data.

darkredd
Star Contributor
Star Contributor
Hardik Thanks for all the replies,

That approach has weaknesses, where the file may be mistakenly deleted from the system or changed. What I have is a file that will be constant for the next 5 years.

Nonetheless, I have been told to use the DB approach for ease of maintenance. I have created the class to fetch data from the DB and the class work as a stand-alone, placed it in the alfresco/WEB-INF/lib folder together with the DB connection driver. Alfresco still cannot register the model with the custom constraint in place. I get the "The list of allowed values is empty", which suggest that the class is not fetching data.

I then realized that it looks like Alfresco is deploying my extensions folder before the alfresco and share apps are deploy which is wrong since the extension should be loaded last. I even implemented the "depends-on" attribute in the bean registration xml. Perhaps I am missing something small.

Below are my declarations:

Constraint class:

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>
<beans>
   <bean id="custom-constraints" class="za.co.dev.constraints.CustomContraints" />
</beans>


Model registration:

<bean id="research.wf.dictionaryBootstrap" parent="dictionaryModelBootstrap" depends-on="custom-constraints">
    <property name="models">
     <list>
   <value>alfresco/extension/ResearchUnitWorkflowModel.xml</value>
     </list>
    </property>
</bean>


Model contraint definition

<constraint name="ru:committees" type="za.co.dev.constraints.CustomContraints">
  <parameter name="allowedValues">
   <list>
   </list>
  </parameter>
</constraint>


I hope these code snippets will shared some light into a mistake I am perhaps making.
Thanks