I am trying to connect external database from alfresco to get constraint like below way.
<bean id="DataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${jdbcDriver}" />
<property name="url" value="${jdbcUrl}" />
<property name="username" value="${jdbcUserName}" />
<property name="password" value="${jdbcPassword}" />
</bean>
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<constructor-arg ref="DataSource" />
</bean>
<bean id="documentDAOImpl" class="com.dao.DocumentDAOImpl">
<property name="jdbcTemplate" ref="jdbcTemplate" />
</bean>
<bean id="batchTypeConstraints" class="com.constraints.BatchTypeConstraints">
<property name="documentDAOImpl" ref="documentDAOImpl" />
</bean>
public class BatchTypeConstraints extends ListOfValuesConstraint implements Serializable {
private DocumentDAOImpl documentDAOImpl;
public DocumentDAOImpl getDocumentDAOImpl() {
return documentDAOImpl;
}
public void setDocumentDAOImpl(DocumentDAOImpl documentDAOImpl) {
this.documentDAOImpl = documentDAOImpl;
}
@Override
public void setAllowedValues(List allowedValues) {
}
@Override
public void setCaseSensitive(boolean caseSensitive) {
}
public void initialize() {
super.setCaseSensitive(false);
this.getDataFromDb();
}
protected void getDataFromDb() {
try {
List<MetaDataModel> pShortNames = documentDAOImpl.getAllBatchByWorkFlowType();
List<String> allowedValue = new ArrayList<String>();
for (MetaDataModel pShortName : pShortNames) {
allowedValue.add(pShortName.getName());
}
super.setAllowedValues(allowedValue);
} catch (Exception e) {
e.printStackTrace();
}
}
}
It's giving me null pointer error at this line :
List<MetaDataModel> pShortNames = documentDAOImpl.getAllBatchByWorkFlowType();
I think data base is not connecting.
How Can i connect ?
How did you register that constraint with the model? Did you use the class name as the type of the constraint in the data model? Then that is the cause for the problem - when you use the class name as the type, the class is instantiated using the default constructor without any parameters passed into it. So instead of using your defined bean, it uses an unitialized instance where of course the field for your DAO is null. You need to use a registered constraint to reference your Spring bean.
Like this way,
<constraint name="mbs:batchTypeAspectList" type="com.mbs.constraints.BatchTypeConstraints">
<parameter name="allowedValues">
<list>
</list>
</parameter>
</constraint>
How to use registered constraint ? Can you Give me some idea?
See the Alfresco code for smart folders:
Hi,
I have defined constraint as per above link but it is giving me error.
Bean :
<bean id="batchType" class="com.mbs.constraints.BatchTypeConstraints" init-method="initialize">
<property name="shortName">
<value>batchType</value>
</property>
<property name="documentDAOImpl" ref="documentDAOImpl" />
</bean>
Constraint :
<constraint name="mbs:batchTypeAspectList"
type="REGISTERED">
<parameter name="registeredName">
<value>batchType</value>
</parameter>
</constraint>
Error :
There is no constraint registered by name 'batchType'.
I am using SDK2 for customization.
Please read again what I have linked. The constraint been needs to be registered with the constraint registry, which are set as properties on the bean. The bean class (which I did not link but would have been easy to find) extends from AbstractConstraint which contains all the logic and properties for registration.
Still Error.
<bean id="batchType" class="com.mbs.constraints.BatchTypeConstraints" init-method="initialize">
<property name="shortName">
<value>batchType</value>
</property>
<property name="registry">
<ref bean="cm:constraintRegistry" />
</property>
<property name="sorted" value="true" />
<property name="documentDAOImpl" ref="documentDAOImpl" />
</bean>
Can you guide me how can i implement?
Ask for and offer help to other Alfresco Content Services Users and members of the Alfresco team.
Related links:
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.