Bean Creation error

cancel
Showing results for 
Search instead for 
Did you mean: 
yuva
Active Member

Bean Creation error

Hi

I am trying to create a filters for data lists,for that i created a DatalistModel.xml, datalist-context.xml and DataListItemPolicies.java files. Now I am error with creating a bean for DataListItemPolicies.java .

Can anyone tell me what's the error with this code.

Error :

-------------------------------------------------------------------------------
Test set: org.alfproject.demoamp.test.DemoComponentTest
-------------------------------------------------------------------------------
Tests run: 3, Failures: 0, Errors: 3, Skipped: 0, Time elapsed: 33.263 sec <<< FAILURE! - in org.alfproject.demoamp.test.DemoComponentTest
testChildNodesCount(org.alfproject.demoamp.test.DemoComponentTest) Time elapsed: 20.009 sec <<< ERROR!
java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'DataListItemPolicies' defined in class path resource [alfresco/extension/datalists/datalist-context.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Class {http://www.alfresco.org/model/datalist/1.0}dataListItem has not been defined in the data dictionary
Caused by: java.lang.IllegalArgumentException: Class {http://www.alfresco.org/model/datalist/1.0}dataListItem has not been defined in the data dictionary

testWiring(org.alfproject.demoamp.test.DemoComponentTest) Time elapsed: 6.537 sec <<< ERROR!
java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'DataListItemPolicies' defined in class path resource [alfresco/extension/datalists/datalist-context.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Class {http://www.alfresco.org/model/datalist/1.0}dataListItem has not been defined in the data dictionary
Caused by: java.lang.IllegalArgumentException: Class {http://www.alfresco.org/model/datalist/1.0}dataListItem has not been defined in the data dictionary

testGetCompanyHome(org.alfproject.demoamp.test.DemoComponentTest) Time elapsed: 5.39 sec <<< ERROR!
java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'DataListItemPolicies' defined in class path resource [alfresco/extension/datalists/datalist-context.xml]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Class {http://www.alfresco.org/model/datalist/1.0}dataListItem has not been defined in the data dictionary
Caused by: java.lang.IllegalArgumentException: Class {http://www.alfresco.org/model/datalist/1.0}dataListItem has not been defined in the data dictionary

DatalistModel.xml :

<?xml version="1.0" encoding="UTF-8"?>

<!-- Definition of Share Data Lists Model -->

<!-- Note: the dl: namespace is defined further on in the document -->
<model name="dl:datalistmodel" xmlns="http://www.alfresco.org/model/dictionary/1.0">

<!-- Meta-data about the model -->
<description>Alfresco Share Data List Model</description>
<author></author>
<version>0.1</version>

<!-- Imports are required to allow references to definitions in other models -->
<imports>
<!-- Import Alfresco Dictionary Definitions -->
<import uri="http://www.alfresco.org/model/dictionary/1.0" prefix="d"/>
<!-- Import Alfresco Content Domain Model Definitions -->
<import uri="http://www.alfresco.org/model/content/1.0" prefix="cm"/>
<!-- Import Alfresco Content Domain Model Definitions -->
<import uri="http://www.alfresco.org/model/system/1.0" prefix="sys" />
</imports>

<!-- Data List Namespace -->
<namespaces>
<namespace uri="http://www.alfresco.org/model/datalist/1.0" prefix="dl"/>
</namespaces>

<constraints>
<constraint name="dl:task_status" type="LIST">
<parameter name="allowedValues">
<list>
<value>Not Started</value>
<value>In Progress</value>
<value>Complete</value>
<value>On Hold</value>
</list>
</parameter>
</constraint>
<constraint name="dlSmiley Tongueriority_value" type="LIST">
<parameter name="allowedValues">
<list>
<value>High</value>
<value>Normal</value>
<value>Low</value>
</list>
</parameter>
</constraint>
<constraint name="dlSmiley Tongueercentage" type="MINMAX">
<parameter name="minValue">
<value>0</value>
</parameter>
<parameter name="maxValue">
<value>100</value>
</parameter>
</constraint>
</constraints>

<types>

<!-- Data List - Container. DO NOT MODIFY -->
<type name="dl:dataList">
<title>Data List container type</title>
<parent>cm:folder</parent>
<properties>
<property name="dl:dataListItemType">
<title>List Item Type</title>
<description>Determines which Data Dictionary type will be used when create new items within the Data List.</description>
<type>d:text</type>
</property>
</properties>
<mandatory-aspects>
<aspect>cm:countable</aspect>
</mandatory-aspects>
</type>

<!-- Data List - Data Item Base Type. DO NOT MODIFY -->
<type name="dl:dataListItem">
<title>Data List parent type</title>
<parent>cm:content</parent>
<mandatory-aspects>
<aspect>cm:versionable</aspect>
<aspect>dl:dataListItemId</aspect>
</mandatory-aspects>
</type>

<!-- Data List - Simple "To do" list -->
<type name="dl:todoList">
<title>To Do List</title>
<parent>dl:dataListItem</parent>
<properties>
<property name="dl:todoTitle">
<title>Title</title>
<type>d:text</type>
<mandatory>true</mandatory>
</property>
<property name="dl:todoDueDate">
<title>Due Date</title>
<type>d:datetime</type>
<mandatory>false</mandatory>
</property>
<property name="dl:todoPriority">
<title>Priority</title>
<type>d:int</type>
<mandatory>false</mandatory>
</property>
<property name="dl:todoStatus">
<title>Status</title>
<type>d:text</type>
<default>Not Started</default>
<constraints>
<constraint ref="dl:task_status" />
</constraints>
</property>
<property name="dl:todoNotes">
<title>Notes</title>
<type>d:text</type>
<mandatory>false</mandatory>
</property>
</properties>
<associations>
<association name="dl:assignee">
<title>Assignee</title>
<source>
<mandatory>false</mandatory>
<many>true</many>
</source>
<target>
<class>cmSmiley Tongueerson</class>
<mandatory>false</mandatory>
<many>false</many>
</target>
</association>
<association name="dl:attachments">
<title>Attachments</title>
<source>
<mandatory>false</mandatory>
<many>true</many>
</source>
<target>
<class>cm:cmobject</class>
<mandatory>false</mandatory>
<many>true</many>
</target>
</association>
</associations>
</type>

<!-- Data List - Simple Tasks List -->
<type name="dl:simpletask">
<title>Task List (Simple)</title>
<parent>dl:dataListItem</parent>
<properties>
<property name="dl:simpletaskDueDate">
<title>Due Date</title>
<type>d:date</type>
<mandatory>false</mandatory>
</property>
<property name="dl:simpletaskPriority">
<title>Priority</title>
<type>d:text</type>
<default>Normal</default>
<constraints>
<constraint ref="dlSmiley Tongueriority_value" />
</constraints>
</property>
<property name="dl:simpletaskStatus">
<title>Status</title>
<type>d:text</type>
<default>Not Started</default>
<constraints>
<constraint ref="dl:task_status" />
</constraints>
</property>
<property name="dl:simpletaskComments">
<title>Comments</title>
<type>d:text</type>
<mandatory>false</mandatory>
</property>
</properties>
<mandatory-aspects>
<aspect>cm:titled</aspect>
</mandatory-aspects>
</type>

<!-- Data List - Advanced Tasks List -->
<type name="dl:task">
<title>Task List (Advanced)</title>
<parent>dl:dataListItem</parent>
<properties>
<property name="dl:taskPriority">
<title>Priority</title>
<type>d:text</type>
<default>Normal</default>
<constraints>
<constraint ref="dlSmiley Tongueriority_value" />
</constraints>
</property>
<property name="dl:taskStatus">
<title>Status</title>
<type>d:text</type>
<default>Not Started</default>
<constraints>
<constraint ref="dl:task_status" />
</constraints>
</property>
<property name="dl:taskComments">
<title>Comments</title>
<type>d:text</type>
<mandatory>false</mandatory>
</property>
</properties>
<associations>
<association name="dl:taskAssignee">
<title>Assignee</title>
<source>
<mandatory>false</mandatory>
<many>true</many>
</source>
<target>
<class>cmSmiley Tongueerson</class>
<mandatory>false</mandatory>
<many>true</many>
</target>
</association>
</associations>
<mandatory-aspects>
<aspect>cm:titled</aspect>
<aspect>cm:attachable</aspect>
<aspect>dl:gantt</aspect>
</mandatory-aspects>
</type>

<!-- Data List - Contact List -->
<type name="dl:contact">
<title>Contacts List</title>
<parent>dl:dataListItem</parent>
<properties>
<property name="dl:contactFirstName">
<title>First Name</title>
<type>d:text</type>
<mandatory>false</mandatory>
</property>
<property name="dl:contactLastName">
<title>Last Name</title>
<type>d:text</type>
<mandatory>false</mandatory>
</property>
<property name="dl:contactEmail">
<title>Email Address</title>
<type>d:text</type>
<mandatory>false</mandatory>
</property>
<property name="dl:contactCompany">
<title>Company</title>
<type>d:text</type>
<mandatory>false</mandatory>
</property>
<property name="dl:contactJobTitle">
<title>Job Title</title>
<type>d:text</type>
<mandatory>false</mandatory>
</property>
<property name="dl:contactPhoneOffice">
<title>Phone (Office)</title>
<type>d:text</type>
<mandatory>false</mandatory>
</property>
<property name="dl:contactPhoneMobile">
<title>Phone (Mobile)</title>
<type>d:text</type>
<mandatory>false</mandatory>
</property>
<property name="dl:contactNotes">
<title>Notes</title>
<type>d:text</type>
<mandatory>false</mandatory>
</property>
</properties>
</type>

<!-- Data List - Contact List -->
<type name="dl:issue">
<title>Issues List</title>
<parent>dl:dataListItem</parent>
<properties>
<property name="dl:issueID">
<title>Issue ID</title>
<type>d:text</type>
</property>
<property name="dl:issueStatus">
<title>Status</title>
<type>d:text</type>
<default>Not Started</default>
<constraints>
<constraint ref="dl:task_status" />
</constraints>
</property>
<property name="dl:issuePriority">
<title>Priority</title>
<type>d:text</type>
<default>Normal</default>
<constraints>
<constraint ref="dlSmiley Tongueriority_value" />
</constraints>
</property>
<property name="dl:issueDueDate">
<title>Due Date</title>
<type>d:date</type>
<mandatory>false</mandatory>
</property>
<property name="dl:issueComments">
<title>Comments</title>
<type>d:text</type>
<mandatory>false</mandatory>
</property>
</properties>
<associations>
<association name="dl:issueAssignedTo">
<title>Assigned To</title>
<source>
<mandatory>false</mandatory>
<many>true</many>
</source>
<target>
<class>cmSmiley Tongueerson</class>
<mandatory>false</mandatory>
<many>true</many>
</target>
</association>
</associations>
<mandatory-aspects>
<aspect>cm:titled</aspect>
<aspect>cm:attachable</aspect>
</mandatory-aspects>
</type>

<!-- Data List - Event List -->
<type name="dl:event">
<title>Event</title>
<parent>dl:dataListItem</parent>
<properties>
<property name="dl:eventLocation">
<title>Location</title>
<type>d:text</type>
<mandatory>false</mandatory>
</property>
<property name="dl:eventNote">
<title>Notes</title>
<type>d:text</type>
<mandatory>false</mandatory>
</property>
<property name="dl:eventStartDate">
<title>Start Date</title>
<type>d:datetime</type>
<mandatory>false</mandatory>
</property>
<property name="dl:eventEndDate">
<title>End Date</title>
<type>d:datetime</type>
<mandatory>false</mandatory>
</property>
<property name="dl:eventRegistrations">
<title>Registrations</title>
<type>d:text</type>
</property>
</properties>
<mandatory-aspects>
<aspect>cm:titled</aspect>
<aspect>cm:attachable</aspect>
</mandatory-aspects>
</type>

<!-- Data List - Event List -->
<type name="dl:location">
<title>Location</title>
<parent>dl:dataListItem</parent>
<properties>
<property name="dl:locationAddress1">
<title>Address 1</title>
<type>d:text</type>
</property>
<property name="dl:locationAddress2">
<title>Address 2</title>
<type>d:text</type>
</property>
<property name="dl:locationAddress3">
<title>Address 3</title>
<type>d:text</type>
</property>
<property name="dl:locationZip">
<title>Zip/Post Code</title>
<type>d:text</type>
</property>
<property name="dl:locationState">
<title>State/County</title>
<type>d:text</type>
</property>
<property name="dl:locationCountry">
<title>Country</title>
<type>d:text</type>
</property>
</properties>
<mandatory-aspects>
<aspect>cm:titled</aspect>
<aspect>cm:attachable</aspect>
</mandatory-aspects>
</type>

<!-- Data List - Meeting Agenda List -->
<type name="dl:meetingAgenda">
<title>Meeting Agenda</title>
<parent>dl:dataListItem</parent>
<properties>
<property name="dl:meetingAgendaRef">
<title>Reference</title>
<type>d:text</type>
</property>
<property name="dl:meetingAgendaTime">
<title>Time (Mins)</title>
<type>d:text</type>
</property>
<property name="dl:meetingAgendaOwner">
<title>Owner</title>
<type>d:text</type>
</property>
</properties>
<mandatory-aspects>
<aspect>cm:titled</aspect>
<aspect>cm:attachable</aspect>
</mandatory-aspects>
</type>

<!-- Data List - Event Agenda List -->
<type name="dl:eventAgenda">
<title>Event Agenda</title>
<parent>dl:dataListItem</parent>
<properties>
<property name="dl:eventAgendaRef">
<title>Reference</title>
<type>d:text</type>
</property>
<property name="dl:eventAgendaStartTime">
<title>Start Time</title>
<type>d:text</type>
</property>
<property name="dl:eventAgendaEndTime">
<title>End Timie</title>
<type>d:text</type>
</property>
<property name="dl:eventAgendaSessionName">
<title>Session Name</title>
<type>d:text</type>
</property>
<property name="dl:eventAgendaPresenter">
<title>Presenter</title>
<type>d:text</type>
</property>
<property name="dl:eventAgendaAudience">
<title>Audience</title>
<type>d:text</type>
</property>
<property name="dl:eventAgendaNotes">
<title>Notes</title>
<type>d:text</type>
</property>
</properties>
<mandatory-aspects>
<aspect>cm:attachable</aspect>
</mandatory-aspects>
</type>
</types>

<aspects>

<aspect name="dl:gantt">
<title>Gantt</title>
<properties>
<property name="dl:ganttStartDate">
<title>Start Date</title>
<type>d:date</type>
</property>
<property name="dl:ganttEndDate">
<title>End Date</title>
<type>d:date</type>
</property>
<property name="dl:ganttPercentComplete">
<title>% Complete</title>
<type>d:int</type>
<mandatory>true</mandatory>
<default>0</default>
<constraints>
<constraint ref="dlSmiley Tongueercentage" />
</constraints>
</property>
</properties>
</aspect>
<aspect name="dl:dataListItemId">
<title>ID</title>
<properties>
<property name="dl:itemId">
<title>ID</title>
<type>d:int</type>
</property>
</properties>
</aspect>
<aspect name="dl:assigneeHelper">
<title>Assignee Names</title>
<properties>
<property name="dl:assigneeFullName">
<title>Assignee Names</title>
<type>d:text</type>
<multiple>true</multiple>
</property>
</properties>
</aspect>

</aspects>

</model>

datalist-context.xml :

<?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="extension.dictionaryBootstrap" parent="dictionaryModelBootstrap" depends-on="dictionaryBootstrap">
<property name="models">
<list>
<!--<value>alfresco/extension/fme/fmeDatalistModel.xml</value>-->
</list>
</property>
</bean>

<!-- Datalist Policy -->
<bean id="DataListItemPolicies" class="alfresco.repo.policy.DataListItemPolicies" init-method="init">
<property name="policyComponent" ref="policyComponent"/>
<property name="nodeService" ref="nodeService" />
<property name="dictionaryService" ref="dictionaryService" />
<property name="versionService" ref="versionService" />
<property name="datalistIDService" ref="datalistIDService" />
</bean>

<bean id="datalistBaseFormFilter" abstract="true" parent="baseFormFilter">
<property name="namespacePrefixResolver">
<ref bean="namespaceService" />
</property>
<property name="behaviourFilter" ref="policyBehaviourFilter" />
<property name="nodeService" ref="nodeService" />
<property name="contentService" ref="contentService" />
<property name="datalistTypes">
<set>
<value>dl:simpletask</value>
<value>dl:contact</value>
<value>dl:eventAgenda</value>
<value>dl:todoList</value>
<value>dl:task</value>
<value>dl:issue</value>
<value>dl:event</value>
<value>dl:location</value>
<value>dl:meetingAgenda</value>
</set>
</property>
</bean>

<bean id="datalistFormFilterNode" class="alfresco.repo.policy.DataListItemPolicies" parent="datalistBaseFormFilter" >
<property name="filterRegistry" ref="nodeFilterRegistry" />
</bean>

<bean id="datalistFormFilterType" class="alfresco.repo.policy.DataListItemPolicies" parent="datalistBaseFormFilter">
<property name="filterRegistry" ref="typeFilterRegistry" />
</bean>

<!-- -->
<!-- Slingshot Data List REST API -->
<!-- -->

<!-- Download a datalist as Excel XLS / XLSX -->
<bean id="webscript.slingshot.datalists.list.get"
class="alfresco.repo.webscripts.datalists.DataListDownloadWebScript"
parent="webscript">
<property name="nodeService" ref="NodeService"/>
<property name="siteService" ref="SiteService"/>
<property name="contentService" ref="ContentService"/>
<property name="personService" ref="PersonService"/>
<property name="namespaceService" ref="namespaceService"/>
<property name="dictionaryService" ref="dictionaryService"/>
<property name="modelOrder">
<!-- These are taken from the forms config for now -->
<map>
<entry key="dl:todoList">
<value>dl:itemId,dl:todoTitle,dl:todoDueDate,dl:todoPriority,dl:todoStatus,dl:todoNotes,dl:assignee,dl:attachments</value>
</entry>
<entry key="dl:task">
<value>dl:itemId,cm:title,cm:description,dl:ganttStartDate,dl:ganttEndDate,dl:taskAssignee,dl:taskPriority,dl:taskStatus,dl:ganttPercentComplete,cm:attachments</value>
</entry>
<entry key="dl:simpletask">
<value>dl:itemId,cm:title,cm:description,dl:simpletaskDueDate,dl:simpletaskPriority,dl:simpletaskStatus</value>
</entry>
<entry key="dl:contact">
<value>dl:itemId,dl:contactFirstName,dl:contactLastName,dl:contactEmail,dl:contactCompany,dl:contactJobTitle,dl:contactPhoneOffice,dl:contactPhoneMobile,dl:contactNotes</value>
</entry>
<entry key="dl:issue">
<value>dl:itemId,cm:title,dl:issueAssignedTo,dl:issueStatus,dl:issuePriority,cm:description,dl:issueDueDate,cm:attachments</value>
</entry>
<entry key="dl:event">
<value>dl:itemId,cm:title,cm:description,dl:eventLocation,dl:eventStartDate,dl:eventEndDate,dl:eventRegistrations,cm:attachments,dl:eventNote</value>
</entry>
<entry key="dl:location">
<value>dl:itemId,cm:title,dl:locationAddress1,dl:locationAddress2,dl:locationAddress3,dl:locationZip,dl:locationState,dl:locationCountry,cm:description,cm:attachments</value>
</entry>
<entry key="dl:meetingAgenda">
<value>dl:itemId,dl:meetingAgendaRef,cm:title,cm:description,dl:meetingAgendaTime,dl:meetingAgendaOwner,cm:attachments</value>
</entry>
<entry key="dl:eventAgenda">
<value>dl:itemId,dl:eventAgendaRef,dl:eventAgendaStartTime,dl:eventAgendaEndTime,dl:eventAgendaSessionName,dl:eventAgendaPresenter,dl:eventAgendaAudience,cm:attachments,dl:eventAgendaNotes</value>
</entry>
</map>
</property>
</bean>

<bean id="datalistIDService" class="alfresco.repo.datalist.DatalistIDServiceImpl">
<property name="nodeService" ref="NodeService" />
</bean>

<bean id="datalistIDServiceSciptFacade" parent="baseJavaScriptExtension" class="alfresco.repo.datalist.DatalistIDServiceScriptFacade">
<property name="extensionName" value="datalistIDService" />
<property name="datalistIDService" ref="datalistIDService" />
<property name="nodeService" ref="NodeService" />
</bean>

</beans>

DataListItemPolicies.java :

package alfresco.repo.policy;

import java.io.Serializable;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;

import org.alfresco.events.VersionType;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.node.MLPropertyInterceptor;
import org.alfresco.repo.node.NodeServicePolicies.OnCreateAssociationPolicy;
import org.alfresco.repo.node.NodeServicePolicies.OnCreateNodePolicy;
import org.alfresco.repo.node.NodeServicePolicies.OnDeleteAssociationPolicy;
import org.alfresco.repo.policy.Behaviour;
import org.alfresco.repo.policy.Behaviour.NotificationFrequency;
import org.alfresco.repo.policy.JavaBehaviour;
import org.alfresco.repo.policy.PolicyComponent;
import org.alfresco.repo.policy.PolicyScope;
import org.alfresco.repo.transaction.AlfrescoTransactionSupport;
import org.alfresco.repo.version.VersionServicePolicies.OnCreateVersionPolicy;
import org.alfresco.service.cmr.dictionary.AssociationDefinition;
import org.alfresco.service.cmr.dictionary.ClassDefinition;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
import org.alfresco.service.cmr.repository.AssociationRef;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.version.VersionService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.service.namespace.RegexQNamePattern;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import alfresco.repo.datalist.DatalistIDService;

public class DataListItemPolicies implements OnCreateVersionPolicy,OnCreateAssociationPolicy,OnCreateNodePolicy,OnDeleteAssociationPolicy{

public static final String DL_NAMESPACE_PREFIX = "dl";
public static final String DL_NAMESPACE = "http://www.alfresco.org/model/datalist/1.0";
public static final QName TYPE_DATA_LIST_ITEM = QName.createQName(DL_NAMESPACE, "dataListItem");
public static final QName ASSOC_ASSIGNEE = QName.createQName(DL_NAMESPACE, "assignee");
public static final QName ASSOC_TASK_ASSIGNEE = QName.createQName(DL_NAMESPACE, "taskAssignee");
public static final QName ASSOC_ISSUED_ASSIGNED_TO = QName.createQName(DL_NAMESPACE, "issueAssignedTo");
public static final QName ASSOC_DL_ATTACHMENTS = QName.createQName(DL_NAMESPACE, "attachments");

public static final QName PROP_ASSIGNEE_FULLNAME = QName.createQName(DL_NAMESPACE, "assigneeFullName");

public static final QName ASPECT_ASSIGNEE_HELPER = QName.createQName(DL_NAMESPACE, "assigneeHelper");


public static final QName ON_CREATE_VERSION_POLICY_QNAME = QName.createQName(NamespaceService.ALFRESCO_URI, "onCreateVersion");

private Behaviour onCreateVersionBehaviour;
private Behaviour onCreateAssociationBehaviour;
private Behaviour onCreateNodePolicy;
private Behaviour onDeleteAssociationBehaviour;

private PolicyComponent policyComponent;
private DictionaryService dictionaryService;
private NodeService nodeService;
private VersionService versionService;
private DatalistIDService datalistIDService;

private static Log logger = LogFactory.getLog(DataListItemPolicies.class);

private static final String KEY_VERSIONED_NODEREFS = "versioned_noderefs";

public void init() {

this.onCreateVersionBehaviour = new JavaBehaviour(this , ON_CREATE_VERSION_POLICY_QNAME.getLocalName(), NotificationFrequency.FIRST_EVENT);
policyComponent.bindClassBehaviour(ON_CREATE_VERSION_POLICY_QNAME, QName.createQName("http://www.alfresco.org/model/datalist/1.0","dataListItem"), this.onCreateVersionBehaviour);
this.onCreateAssociationBehaviour = new JavaBehaviour(this, "onCreateAssociation", NotificationFrequency.FIRST_EVENT);
policyComponent.bindAssociationBehaviour(OnCreateAssociationPolicy.QNAME, TYPE_DATA_LIST_ITEM, ASSOC_ASSIGNEE, this.onCreateAssociationBehaviour);
policyComponent.bindAssociationBehaviour(OnCreateAssociationPolicy.QNAME, TYPE_DATA_LIST_ITEM, ASSOC_TASK_ASSIGNEE, this.onCreateAssociationBehaviour);
policyComponent.bindAssociationBehaviour(OnCreateAssociationPolicy.QNAME, TYPE_DATA_LIST_ITEM, ASSOC_ISSUED_ASSIGNED_TO, this.onCreateAssociationBehaviour);
policyComponent.bindAssociationBehaviour(OnCreateAssociationPolicy.QNAME, TYPE_DATA_LIST_ITEM, ContentModel.ASSOC_ATTACHMENTS, this.onCreateAssociationBehaviour);
policyComponent.bindAssociationBehaviour(OnCreateAssociationPolicy.QNAME, TYPE_DATA_LIST_ITEM, ASSOC_DL_ATTACHMENTS, this.onCreateAssociationBehaviour);

this.onDeleteAssociationBehaviour = new JavaBehaviour(this, "onDeleteAssociation",NotificationFrequency.FIRST_EVENT);
policyComponent.bindAssociationBehaviour(OnDeleteAssociationPolicy.QNAME, TYPE_DATA_LIST_ITEM, ASSOC_ASSIGNEE, this.onDeleteAssociationBehaviour);
policyComponent.bindAssociationBehaviour(OnDeleteAssociationPolicy.QNAME, TYPE_DATA_LIST_ITEM, ASSOC_TASK_ASSIGNEE, this.onDeleteAssociationBehaviour);
policyComponent.bindAssociationBehaviour(OnDeleteAssociationPolicy.QNAME, TYPE_DATA_LIST_ITEM, ASSOC_ISSUED_ASSIGNED_TO, this.onDeleteAssociationBehaviour);
policyComponent.bindAssociationBehaviour(OnDeleteAssociationPolicy.QNAME, TYPE_DATA_LIST_ITEM, ContentModel.ASSOC_ATTACHMENTS, this.onDeleteAssociationBehaviour);
policyComponent.bindAssociationBehaviour(OnDeleteAssociationPolicy.QNAME, TYPE_DATA_LIST_ITEM, ASSOC_DL_ATTACHMENTS, this.onDeleteAssociationBehaviour);

this.onCreateNodePolicy = new JavaBehaviour(this, OnCreateNodePolicy.QNAME.getLocalName(),
NotificationFrequency.FIRST_EVENT);
policyComponent.bindClassBehaviour(OnCreateNodePolicy.QNAME, QName.createQName(
"http://www.alfresco.org/model/datalist/1.0", "dataListItem"), this.onCreateNodePolicy);

}


private void createVersionImpl(NodeRef nodeRef) {
// TODO Auto-generated method stub
@SuppressWarnings("unchecked")
Map<NodeRef, NodeRef> versionedNodeRefs = (Map<NodeRef, NodeRef>) AlfrescoTransactionSupport.getResource(KEY_VERSIONED_NODEREFS);
if (versionedNodeRefs == null || versionedNodeRefs.containsKey(nodeRef) == false)
{
recordCreateVersion(nodeRef);
this.versionService.createVersion(nodeRef, null);
}
}

@SuppressWarnings("unchecked")
private void recordCreateVersion(NodeRef versionableNode)
{
Map<NodeRef, NodeRef> versionedNodeRefs = (Map<NodeRef, NodeRef>)AlfrescoTransactionSupport.getResource(KEY_VERSIONED_NODEREFS);
if (versionedNodeRefs == null)
{
versionedNodeRefs = new HashMap<NodeRef, NodeRef>();
AlfrescoTransactionSupport.bindResource(KEY_VERSIONED_NODEREFS, versionedNodeRefs);
}
versionedNodeRefs.put(versionableNode, versionableNode);
}


@Override
public void onCreateNode(ChildAssociationRef childAssocRef) {
// TODO Auto-generated method stub
this.datalistIDService.setNextId(childAssocRef);
this.nodeService.setProperty(childAssocRef.getChildRef(), ContentModel.PROP_AUTO_VERSION_PROPS, true);
}

@Override
public void onCreateAssociation(AssociationRef nodeAssocRef) {
// TODO Auto-generated method stub
NodeRef nodeRef = nodeAssocRef.getSourceRef();
if (this.nodeService.exists(nodeRef) == true){
this.onCreateAssociationBehaviour.disable();
try{
addAssigneeFullNames(nodeAssocRef);
createVersionImpl(nodeRef);
}finally{
this.onCreateAssociationBehaviour.enable();
}

}
}

private void addAssigneeFullNames(AssociationRef nodeAssocRef) {
// TODO Auto-generated method stub
NodeRef nodeRef = nodeAssocRef.getSourceRef();
NodeRef personRef = nodeAssocRef.getTargetRef();
String firstName = (String) nodeService.getProperty(personRef, ContentModel.PROP_FIRSTNAME);
String lastName = (String) nodeService.getProperty(personRef, ContentModel.PROP_LASTNAME);
String fullName = (firstName == null ? "" : firstName) + (lastName == null ? "" : lastName);
Map<QName, Serializable> fullNames = new HashMap<QName, Serializable>();
Collection<String> allNames = new HashSet<String>();
if (!nodeService.hasAspect(nodeRef, ASPECT_ASSIGNEE_HELPER)){
allNames.add(fullName);
fullNames.put(PROP_ASSIGNEE_FULLNAME, (Serializable) allNames);
nodeService.addAspect(nodeRef, ASPECT_ASSIGNEE_HELPER, fullNames);
}else{
allNames = (Collection<String>) nodeService.getProperty(nodeRef, PROP_ASSIGNEE_FULLNAME);
allNames.add(fullName);
nodeService.setProperty(nodeRef, PROP_ASSIGNEE_FULLNAME,(Serializable) allNames);
}
}


@Override
public void onCreateVersion(QName classRef, NodeRef versionableNode, Map<String, Serializable> versionProperties, PolicyScope nodeDetails) {
// TODO Auto-generated method stub
logger.debug("create version");
versionProperties.put("versionType", VersionType.MAJOR);
defaultOnCreateVersion(classRef, versionableNode, versionProperties, nodeDetails);
if(nodeService.hasAspect(versionableNode, ContentModel.ASPECT_ATTACHABLE)) {
List<AssociationRef> nodeAssocRefs = this.nodeService.getTargetAssocs(versionableNode, RegexQNamePattern.MATCH_ALL);
for (AssociationRef nodeAssocRef : nodeAssocRefs) {
if (nodeAssocRef.getTypeQName().equals(ContentModel.ASSOC_ATTACHMENTS)) {
nodeDetails.addAssociation(classRef, nodeAssocRef);
}
}
/* nodeAssocRefs.forEach((nodeAssocRef->{
if(nodeAssocRef.getTypeQName().equals(ContentModel.ASSOC_ATTACHMENTS)) {
nodeDetails.addAssociation(classRef, nodeAssocRef);
}
}));*/
}

}
@Override
public void onDeleteAssociation(AssociationRef nodeAssocRef) {
// TODO Auto-generated method stub
NodeRef nodeRef = nodeAssocRef.getSourceRef();
if (this.nodeService.exists(nodeRef) == true){
this.onDeleteAssociationBehaviour.disable();
try{
deleteAssigneeFullNames(nodeAssocRef);
createVersionImpl(nodeRef);
}finally{
this.onDeleteAssociationBehaviour.enable();
}
}
}

private void deleteAssigneeFullNames(AssociationRef nodeAssocRef) {
// TODO Auto-generated method stub
NodeRef nodeRef = nodeAssocRef.getSourceRef();
NodeRef personRef = nodeAssocRef.getTargetRef();
String firstName = (String) nodeService.getProperty(personRef, ContentModel.PROP_FIRSTNAME);
String lastName = (String) nodeService.getProperty(personRef, ContentModel.PROP_LASTNAME);
String fullName = (firstName == null ? "": firstName) +" "+ (lastName == null ? "": lastName);
Collection<String> allNames = new HashSet<String>();
if (nodeService.hasAspect(nodeRef, ASPECT_ASSIGNEE_HELPER)){
allNames = (Collection<String>) nodeService.getProperty(nodeRef, PROP_ASSIGNEE_FULLNAME);
allNames.remove(fullName);
nodeService.setProperty(nodeRef, PROP_ASSIGNEE_FULLNAME,(Serializable) allNames);
}
}


protected void defaultOnCreateVersion(QName classRef, NodeRef nodeRef, Map<String, Serializable> versionProperties, PolicyScope nodeDetails) {
ClassDefinition classDefinition = this.dictionaryService.getClass(classRef);
if(classDefinition != null) {
boolean wasMLAware = MLPropertyInterceptor.setMLAware(true);
try {
Map<QName, PropertyDefinition> propertyDefinitions = classDefinition.getProperties();
for(QName propertyName : propertyDefinitions.keySet()) {
Serializable propValue = this.nodeService.getProperty(nodeRef, propertyName);
nodeDetails.addProperty(classRef, propertyName, propValue);
}
}finally {
MLPropertyInterceptor.setMLAware(wasMLAware);
}
}
// Version the associations (child and target)
Map<QName, AssociationDefinition> assocDefs = classDefinition.getAssociations();

if (classDefinition.isContainer()) {
List<ChildAssociationRef> childAssocRefs = this.nodeService.getChildAssocs(nodeRef);
for (ChildAssociationRef childAssocRef : childAssocRefs) {
if (assocDefs.containsKey(childAssocRef.getTypeQName())) {
nodeDetails.addChildAssociation(classDefinition.getName(), childAssocRef);
}
}
}

List<AssociationRef> nodeAssocRefs = this.nodeService.getTargetAssocs(nodeRef, RegexQNamePattern.MATCH_ALL);
for (AssociationRef nodeAssocRef : nodeAssocRefs) {
if (assocDefs.containsKey(nodeAssocRef.getTypeQName())) {
nodeDetails.addAssociation(classDefinition.getName(), nodeAssocRef);
}
}


}

}

1 Reply
krutik_jayswal
Senior Member II

Re: Bean Creation error

It seems that your test cases are getting failure.Try to execute it by skipping the test case and then rewrite then test cases.