FileNET P8 5.2.1 FP2 - 文档创建的编辑权限
FileNET P8 5.2.1 FP2 - edit permissions on document creation
我们被要求在创建文档时设置权限。
基本上写的代码部分转载如下:
public void onEvent(ObjectChangeEvent event, Id eventId) {
if (event instanceof CreationEvent) {
Document doc = (Document) event.get_SourceObject();
AccessPermissionList permissions = doc.get_Permissions();
String creatorGranteeName = getCreatorGranteeName(doc);
Iterator<AccessPermission> iter = permissions.iterator();
boolean found = false;
while (iter.hasNext()) {
AccessPermission ace = (AccessPermission) iter.next();
if (ace.get_GranteeName().equals(creatorGranteeName)) {
permissions.remove(ace);
// relevant ? is "permission" duplicated ?
doc.set_Permissions(permissions);
break;
}
}
if (!found) return ; // no need to save
doc.save(RefreshMode.REFRESH); // --> triggers CreationEvent -> loop
System.out.println("Saved."); // never reached
}
}
我尝试了两种方式:预处理器或订阅。
Preprocessor 不起作用,因为文档似乎没有完全构建,尤其是关于权限(只设置了管理员)。获取似乎不起作用(这是可以理解的,因为文档尚未存储)。
Susbcription 如果在 doc.save()
行 同步 处理,则崩溃,无论刷新模式是否为 RefreshMode.REFRESH
或 RefreshMode.NO_REFRESH
。
如果它 asynchrounsly 完成,它似乎循环,就好像 doc.save
重新触发 CreationEvent
.
因此,如果我做错了什么,我正在寻求帮助,或者寻求第三种方法(如果存在)。
编辑:添加了块代码,如果没有找到删除权限则跳过保存。
因为名誉不能发表评论,所以必须回答一下
你试过了吗
doc.checkin(AutoClassify.DO_NOT_AUTO_CLASSIFY, CheckinType.MAJOR_VERSION);
之前 doc.save()
更新答案
你也可以试试
而不是 event.get_SourceObject();
`changeEvent.get_SourceObjectId();
Document doc= Factory.Document.fetchInstance(os, documentId, propertyFilter);`
正如@Manjunatha Muniyappa 所说,我通过从对象存储而不是从 CreationEvent 对象获取文档来解决我的问题。 It seems to be recommended by the editor("as a best practice, fetch the persisted source object of the event")。同样通过这种方式不会引发 CreationEvent(我不知道为什么)。
所以解决方案是在创建事件上创建一个异步订阅,与下面的这个处理程序class相关联:
// Only relevant lines are kept.
public class CustomEventAction implements EventActionHandler {
// [...]
public void onEvent(ObjectChangeEvent event, Id eventId) {
if (event instanceof CreationEvent) {
ObjectStore os = event.getObjectStore();
Id id = event.get_SourceObjectId();
FilterElement fe =
new FilterElement(null, null, null, "permissions creator", null);
PropertyFilter pf = new PropertyFilter();
pf.addIncludeProperty(fe);
Document doc = Factory.Document.fetchInstance(os, id, pf);
AccessPermissionList permissions;
String creatorGranteeName = getCreatorGranteeName(doc);
permissions = doc.get_Permissions();
Iterator<AccessPermission> iter = permissions.iterator();
boolean found = false;
while (iter.hasNext()) {
AccessPermission ace = (AccessPermission) iter.next();
if (ace.get_GranteeName().equals(creatorGranteeName)) {
permissions.remove(ace);
found = true;
break;
}
}
if (!found) {
return;
}
doc.save(RefreshMode.REFRESH);
}
}
}
我们被要求在创建文档时设置权限。
基本上写的代码部分转载如下:
public void onEvent(ObjectChangeEvent event, Id eventId) {
if (event instanceof CreationEvent) {
Document doc = (Document) event.get_SourceObject();
AccessPermissionList permissions = doc.get_Permissions();
String creatorGranteeName = getCreatorGranteeName(doc);
Iterator<AccessPermission> iter = permissions.iterator();
boolean found = false;
while (iter.hasNext()) {
AccessPermission ace = (AccessPermission) iter.next();
if (ace.get_GranteeName().equals(creatorGranteeName)) {
permissions.remove(ace);
// relevant ? is "permission" duplicated ?
doc.set_Permissions(permissions);
break;
}
}
if (!found) return ; // no need to save
doc.save(RefreshMode.REFRESH); // --> triggers CreationEvent -> loop
System.out.println("Saved."); // never reached
}
}
我尝试了两种方式:预处理器或订阅。
Preprocessor 不起作用,因为文档似乎没有完全构建,尤其是关于权限(只设置了管理员)。获取似乎不起作用(这是可以理解的,因为文档尚未存储)。
Susbcription 如果在 doc.save()
行 同步 处理,则崩溃,无论刷新模式是否为 RefreshMode.REFRESH
或 RefreshMode.NO_REFRESH
。
如果它 asynchrounsly 完成,它似乎循环,就好像 doc.save
重新触发 CreationEvent
.
因此,如果我做错了什么,我正在寻求帮助,或者寻求第三种方法(如果存在)。
编辑:添加了块代码,如果没有找到删除权限则跳过保存。
因为名誉不能发表评论,所以必须回答一下 你试过了吗
doc.checkin(AutoClassify.DO_NOT_AUTO_CLASSIFY, CheckinType.MAJOR_VERSION);
之前 doc.save()
更新答案
你也可以试试
而不是event.get_SourceObject();
`changeEvent.get_SourceObjectId();
Document doc= Factory.Document.fetchInstance(os, documentId, propertyFilter);`
正如@Manjunatha Muniyappa 所说,我通过从对象存储而不是从 CreationEvent 对象获取文档来解决我的问题。 It seems to be recommended by the editor("as a best practice, fetch the persisted source object of the event")。同样通过这种方式不会引发 CreationEvent(我不知道为什么)。
所以解决方案是在创建事件上创建一个异步订阅,与下面的这个处理程序class相关联:
// Only relevant lines are kept.
public class CustomEventAction implements EventActionHandler {
// [...]
public void onEvent(ObjectChangeEvent event, Id eventId) {
if (event instanceof CreationEvent) {
ObjectStore os = event.getObjectStore();
Id id = event.get_SourceObjectId();
FilterElement fe =
new FilterElement(null, null, null, "permissions creator", null);
PropertyFilter pf = new PropertyFilter();
pf.addIncludeProperty(fe);
Document doc = Factory.Document.fetchInstance(os, id, pf);
AccessPermissionList permissions;
String creatorGranteeName = getCreatorGranteeName(doc);
permissions = doc.get_Permissions();
Iterator<AccessPermission> iter = permissions.iterator();
boolean found = false;
while (iter.hasNext()) {
AccessPermission ace = (AccessPermission) iter.next();
if (ace.get_GranteeName().equals(creatorGranteeName)) {
permissions.remove(ace);
found = true;
break;
}
}
if (!found) {
return;
}
doc.save(RefreshMode.REFRESH);
}
}
}