如何使用 WebScript 从数据列表中获取关联?
How to get associations from the data list by using WebScript?
在Alfresco One 5.x Developer's Guide there is an example of the data list.
我想在我的项目中使用这个功能。例如,有一些业务流程的执行者是预定义的。每个部门都有自己的一套业务流程。可以读取传入合同的元数据(来自电子邮件或扫描仪 - 并不重要)并自动 运行 业务流程,具体取决于部门。数据列表的概念在我看来很合适...
问题是我无法获得关联。在我的例子中,这是类型 cm:person
.
例如数据列表模型定义描述如下:
<?xml version="1.0" encoding="UTF-8"?>
<model name="mspdl:MSpredefinedAssigneesDataListModel" xmlns="http://www.alfresco.org/model/dictionary/1.0">
<description>...</description>
<author>...</author>
<version>...</version>
<imports>
<import uri="http://www.alfresco.org/model/dictionary/1.0" prefix="d"/>
<import uri="http://www.alfresco.org/model/content/1.0" prefix="cm"/>
<import uri="http://www.alfresco.org/model/datalist/1.0" prefix="dl" />
</imports>
<namespaces>
<namespace uri="http://www.....com/model/datalist/3.0" prefix="mspdl"/>
</namespaces>
<types>
<type name="mspdl:assigneesListItem">
<title>...</title>
<parent>dl:dataListItem</parent>
<properties>
<property name="mspdl:serviceName">
<type>d:text</type>
<mandatory>true</mandatory>
</property>
</properties>
<associations>
<association name="mspdl:projectMember1">
<source>
<mandatory>true</mandatory>
<many>false</many>
</source>
<target>
<class>cm:person</class>
<mandatory>true</mandatory>
<many>false</many>
</target>
</association>
<association name="mspdl:projectMember2">
<source>
<mandatory>true</mandatory>
<many>false</many>
</source>
<target>
<class>cm:person</class>
<mandatory>true</mandatory>
<many>false</many>
</target>
</association>
...
<association name="mspdl:projectMemberN">
<source>
<mandatory>true</mandatory>
<many>false</many>
</source>
<target>
<class>cm:person</class>
<mandatory>true</mandatory>
<many>false</many>
</target>
</association>
</associations>
</type>
</types>
</model>
我尝试检索关联的网络脚本:
public class DataListAssignmentsRetriever extends DeclarativeWebScript {
private final String DATA_LIST_SITE_CONTAINER = "dataLists";
private final String NAMESPACE_URI = "http://www.......com/model/datalist/3.0";
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status) {
QName ASSOC_NAME_PROJECT_MEMBER_1 = QName.createQName(NAMESPACE_URI, "projectMember1");
List<AssociationRef> temp00List = serviceRegistry.getNodeService().getSourceAssocs(dataListNodeRef, ASSOC_NAME_PROJECT_MEMBER_1);
// temp00List.size() == 0 ???
List<AssociationRef> temp01List = serviceRegistry.getNodeService().getTargetAssocs(dataListNodeRef, ASSOC_NAME_PROJECT_MEMBER_1);
// temp01List.size() == 0 ???
List<ChildAssociationRef> temp02List = serviceRegistry.getNodeService().getChildAssocs(dataListNodeRef);
// temp02List == 1 < -- Allows to find just only the property 'serviceName'.
List<ChildAssociationRef> temp03List =
serviceRegistry.getNodeService().getChildAssocs(dataListNodeRef, RegexQNamePattern.MATCH_ALL, ASSOC_NAME_PROJECT_MEMBER_1);
// temp03List.size() == 0 ???
List<AssociationRef> temp04List.size() =
serviceRegistry.getNodeService().getSourceAssocs(dataListNodeRef, RegexQNamePattern.MATCH_ALL);
// temp04List.size() == 0 ???
List<AssociationRef> temp05List = serviceRegistry.getNodeService().getTargetAssocs(nodeRef, RegexQNamePattern.MATCH_ALL);
// temp05List.size() == 0 ???
...
}
}
服务 serviceRegistry
已正确注入。
我做错了什么?如何从数据列表中获取关联?
如果能提供信息,我将不胜感激。感谢大家。
已更新。
NodeRef
我的数据列表是 workspace://SpacesStore/b136bebc-fe2c-40fb-aec6-93d9fd22533d
。当我在节点浏览器中搜索它时,我得到以下信息:
因此,我浏览了 link 并看到以下内容:关联缺失。
然后我查看对子元素的引用(显示在屏幕截图的顶部)并查看以下内容:
当我通过这个 link 时,我看到了我的联想:
已更新。
感谢咨询,Gagravarr and ratik.singhal _。通过使用以下代码,我可以获得对数据列表项的引用:
List<ChildAssociationRef> childAssociationRefs = serviceRegistry.getNodeService().getChildAssocs(
dataListNodeRef,
ContentModel.ASSOC_CONTAINS,
RegexQNamePattern.MATCH_ALL
);
NodeRef dataListItemNodeRef = childAssociationRefs.get(0).getChildRef();
在这里我可以看到属性和关联:
属性:
协会:
我可以使用以下代码访问属性:
Map<QName, Serializable> properties = serviceRegistry.getNodeService().getProperties(dataListItemNodeRef);
Iterator iterator = properties.entrySet().iterator();
while(iterator.hasNext()) {
Map.Entry keyValuePairs = (Map.Entry)iterator.next();
Object key = keyValuePairs.getKey();
Object value = keyValuePairs.getValue();
...
}
但是如何获取关联呢?...
Angel Borroy gave an excellent example 对我有帮助:
当然,Gagravarr 举了一个很好的例子:
解决方案可能如下所示:
...
NodeRef dataListContainer =
siteService.getContainer("contracts-site", "dataLists");
List<ChildAssociationRef> dataListsNodes =
nodeService.getChildAssocs(dataListContainer);
for(ChildAssociationRef dataList : dataListsNodes) {
if (dataList.getTypeQName().isMatch(ContentModel.ASSOC_CONTAINS)) {
if(nodeService.getProperty(
dataList.getChildRef(),
ContentModel.PROP_TITLE).toString().equals("Data list title here")) {
List<ChildAssociationRef> childAssocsRef =
nodeService.getChildAssocs(dataList.getChildRef());
for(ChildAssociationRef childAssocRef : childAssocsRef) {
List<AssociationRef> customAssocs = nodeService.getTargetAssocs(
childAssocRef.getChildRef(),
QName.createQName(DATALIST_MODEL_URI, "projectMember1"));
NodeRef nodeRef = customAssocs.get(0).getTargetRef();
if(ContentModel.TYPE_PERSON.equals(nodeService.getType(nodeRef))) {
nodeService.getProperty(nodeRef, ContentModel.PROP_USERNAME);
}
...
}
} else continue;
}
}
...
这解决了我的问题。
在Alfresco One 5.x Developer's Guide there is an example of the data list.
我想在我的项目中使用这个功能。例如,有一些业务流程的执行者是预定义的。每个部门都有自己的一套业务流程。可以读取传入合同的元数据(来自电子邮件或扫描仪 - 并不重要)并自动 运行 业务流程,具体取决于部门。数据列表的概念在我看来很合适...
问题是我无法获得关联。在我的例子中,这是类型 cm:person
.
例如数据列表模型定义描述如下:
<?xml version="1.0" encoding="UTF-8"?>
<model name="mspdl:MSpredefinedAssigneesDataListModel" xmlns="http://www.alfresco.org/model/dictionary/1.0">
<description>...</description>
<author>...</author>
<version>...</version>
<imports>
<import uri="http://www.alfresco.org/model/dictionary/1.0" prefix="d"/>
<import uri="http://www.alfresco.org/model/content/1.0" prefix="cm"/>
<import uri="http://www.alfresco.org/model/datalist/1.0" prefix="dl" />
</imports>
<namespaces>
<namespace uri="http://www.....com/model/datalist/3.0" prefix="mspdl"/>
</namespaces>
<types>
<type name="mspdl:assigneesListItem">
<title>...</title>
<parent>dl:dataListItem</parent>
<properties>
<property name="mspdl:serviceName">
<type>d:text</type>
<mandatory>true</mandatory>
</property>
</properties>
<associations>
<association name="mspdl:projectMember1">
<source>
<mandatory>true</mandatory>
<many>false</many>
</source>
<target>
<class>cm:person</class>
<mandatory>true</mandatory>
<many>false</many>
</target>
</association>
<association name="mspdl:projectMember2">
<source>
<mandatory>true</mandatory>
<many>false</many>
</source>
<target>
<class>cm:person</class>
<mandatory>true</mandatory>
<many>false</many>
</target>
</association>
...
<association name="mspdl:projectMemberN">
<source>
<mandatory>true</mandatory>
<many>false</many>
</source>
<target>
<class>cm:person</class>
<mandatory>true</mandatory>
<many>false</many>
</target>
</association>
</associations>
</type>
</types>
</model>
我尝试检索关联的网络脚本:
public class DataListAssignmentsRetriever extends DeclarativeWebScript {
private final String DATA_LIST_SITE_CONTAINER = "dataLists";
private final String NAMESPACE_URI = "http://www.......com/model/datalist/3.0";
@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status) {
QName ASSOC_NAME_PROJECT_MEMBER_1 = QName.createQName(NAMESPACE_URI, "projectMember1");
List<AssociationRef> temp00List = serviceRegistry.getNodeService().getSourceAssocs(dataListNodeRef, ASSOC_NAME_PROJECT_MEMBER_1);
// temp00List.size() == 0 ???
List<AssociationRef> temp01List = serviceRegistry.getNodeService().getTargetAssocs(dataListNodeRef, ASSOC_NAME_PROJECT_MEMBER_1);
// temp01List.size() == 0 ???
List<ChildAssociationRef> temp02List = serviceRegistry.getNodeService().getChildAssocs(dataListNodeRef);
// temp02List == 1 < -- Allows to find just only the property 'serviceName'.
List<ChildAssociationRef> temp03List =
serviceRegistry.getNodeService().getChildAssocs(dataListNodeRef, RegexQNamePattern.MATCH_ALL, ASSOC_NAME_PROJECT_MEMBER_1);
// temp03List.size() == 0 ???
List<AssociationRef> temp04List.size() =
serviceRegistry.getNodeService().getSourceAssocs(dataListNodeRef, RegexQNamePattern.MATCH_ALL);
// temp04List.size() == 0 ???
List<AssociationRef> temp05List = serviceRegistry.getNodeService().getTargetAssocs(nodeRef, RegexQNamePattern.MATCH_ALL);
// temp05List.size() == 0 ???
...
}
}
服务 serviceRegistry
已正确注入。
我做错了什么?如何从数据列表中获取关联?
如果能提供信息,我将不胜感激。感谢大家。
已更新。
NodeRef
我的数据列表是 workspace://SpacesStore/b136bebc-fe2c-40fb-aec6-93d9fd22533d
。当我在节点浏览器中搜索它时,我得到以下信息:
因此,我浏览了 link 并看到以下内容:关联缺失。
然后我查看对子元素的引用(显示在屏幕截图的顶部)并查看以下内容:
当我通过这个 link 时,我看到了我的联想:
已更新。
感谢咨询,Gagravarr and ratik.singhal _。通过使用以下代码,我可以获得对数据列表项的引用:
List<ChildAssociationRef> childAssociationRefs = serviceRegistry.getNodeService().getChildAssocs(
dataListNodeRef,
ContentModel.ASSOC_CONTAINS,
RegexQNamePattern.MATCH_ALL
);
NodeRef dataListItemNodeRef = childAssociationRefs.get(0).getChildRef();
在这里我可以看到属性和关联:
属性:
协会:
我可以使用以下代码访问属性:
Map<QName, Serializable> properties = serviceRegistry.getNodeService().getProperties(dataListItemNodeRef);
Iterator iterator = properties.entrySet().iterator();
while(iterator.hasNext()) {
Map.Entry keyValuePairs = (Map.Entry)iterator.next();
Object key = keyValuePairs.getKey();
Object value = keyValuePairs.getValue();
...
}
但是如何获取关联呢?...
Angel Borroy gave an excellent example 对我有帮助:
当然,Gagravarr 举了一个很好的例子:
解决方案可能如下所示:
...
NodeRef dataListContainer =
siteService.getContainer("contracts-site", "dataLists");
List<ChildAssociationRef> dataListsNodes =
nodeService.getChildAssocs(dataListContainer);
for(ChildAssociationRef dataList : dataListsNodes) {
if (dataList.getTypeQName().isMatch(ContentModel.ASSOC_CONTAINS)) {
if(nodeService.getProperty(
dataList.getChildRef(),
ContentModel.PROP_TITLE).toString().equals("Data list title here")) {
List<ChildAssociationRef> childAssocsRef =
nodeService.getChildAssocs(dataList.getChildRef());
for(ChildAssociationRef childAssocRef : childAssocsRef) {
List<AssociationRef> customAssocs = nodeService.getTargetAssocs(
childAssocRef.getChildRef(),
QName.createQName(DATALIST_MODEL_URI, "projectMember1"));
NodeRef nodeRef = customAssocs.get(0).getTargetRef();
if(ContentModel.TYPE_PERSON.equals(nodeService.getType(nodeRef))) {
nodeService.getProperty(nodeRef, ContentModel.PROP_USERNAME);
}
...
}
} else continue;
}
}
...
这解决了我的问题。