08-15-2018 07:10 AM
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 ?
08-15-2018 07:33 AM
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.
08-15-2018 07:51 AM
Like this way,
<constraint name="mbs:batchTypeAspectList" type="com.mbs.constraints.BatchTypeConstraints">
<parameter name="allowedValues">
<list>
</list>
</parameter>
</constraint>
08-15-2018 07:51 AM
How to use registered constraint ? Can you Give me some idea?
08-15-2018 08:34 AM
See the Alfresco code for smart folders:
08-15-2018 09:30 AM
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'.
08-15-2018 09:32 AM
I am using SDK2 for customization.
08-15-2018 11:36 AM
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.
08-15-2018 11:58 AM
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>
08-16-2018 01:17 AM
Can you guide me how can i implement?
Explore our Alfresco products with the links below. Use labels to filter content by product module.