Filenet Component 节点修改附件文档权限

这个包(import com.filenet.wcm.toolkit.server.operations.util.opsUtil;)我好像没找到,在网上看到有人说 3.5 里面有,我现在用的 p8 4.5 里面没找到,但收藏下来,以备后用.


package com.filenet.operations;

import java.util.Iterator;

import com.filenet.wcm.api.Document;
import com.filenet.wcm.api.GettableObject;
import com.filenet.wcm.api.ObjectFactory;
import com.filenet.wcm.api.Permission;
import com.filenet.wcm.api.Permissions;
import com.filenet.wcm.api.Property;
import com.filenet.wcm.api.Session;
import com.filenet.wcm.toolkit.server.operations.util.opsUtil;
import com.filenet.wcm.toolkit.util.WcmException;

import filenet.vw.api.VWAttachment;
import filenet.vw.api.VWException;

public class ChangePermission {
    public void setDocPermission(VWAttachment sourceDocument,String currentUserName) throws WcmException
    {
        boolean exist = false;
        String userName = null;
        int maskNumber = 131201;
        opsUtil opsUtil=new opsUtil();
        Session session = opsUtil.getSession();
        GettableObject attachment = opsUtil.getAttachment(sourceDocument, session);
        Document doc = (Document) attachment;
        Permissions permissions = doc.getPermissions();
        Iterator iterator = permissions.iterator();
        try{
            while (iterator.hasNext()) {
                Permission permission = (Permission) iterator.next();
                userName = permission.getGranteeName(); // #AUTHENTICATED-USERS,Administrator@fndemo.com,tester1@fndemo.com,tester2@fndemo.com,Administrator@fndemo.com,
                if (userName.equalsIgnoreCase(currentUserName.trim())) {
                    permission.setAccess(maskNumber);
                    permissions.add(permission);
                    doc.setPermissions(permissions);
                    doc.refresh();
                    exist = true;
                }
            }
            if(!exist){
                Permission permission = ObjectFactory.getPermission(maskNumber,1,currentUserName,2000);
                permission.setInheritableDepth(0);
                permissions.add(permission);
                doc.setPermissions(permissions, Property.PERMISSIONS);
                doc.refresh();
            }
        }catch(Exception e)
        {
            e.printStackTrace();
        }
    }
    public void removeDocPermission(VWAttachment sourceDocument,String currentUserName) throws WcmException {
        
        opsUtil opsUtil=new opsUtil();
        Session session = opsUtil.getSession();
        String userName = null;
        GettableObject go = opsUtil.getAttachment(sourceDocument, session);
        Document doc = (Document) go;
        Permissions permissions = doc.getPermissions();
        Iterator iterator = permissions.iterator();
        try{
            while (iterator.hasNext()) {
                Permission permission = (Permission) iterator.next();
                userName = permission.getGranteeName(); // #AUTHENTICATED-USERS,Administrator@fndemo.com,tester1@fndemo.com,tester2@fndemo.com,Administrator@fndemo.com,
                if (userName.equalsIgnoreCase(currentUserName.trim())) {
                    iterator.remove();
                    Permission p = ObjectFactory.getPermission(131073,1,currentUserName,2000);
                    p.setInheritableDepth(0);
                    permissions.add(p);
                    permissions.add(p);
                    doc.setPermissions(permissions,Property.PERMISSIONS);
                    doc.refresh();
                }  
            }
        }catch(Exception e)
        {
            e.printStackTrace();
        }
    }
}


除非申明,文章均为一号门原创,转载请注明本文地址,谢谢!
[本日志由 轻舞肥羊 于 2011-03-06 09:07 PM 编辑]
文章来自: 本站原创
引用通告: 查看所有引用 | 我要引用此文章
Tags: filenet
相关日志:
评论: 0 | 引用: 0 | 查看次数: -
发表评论
昵 称:
密 码: 游客发言不需要密码.
内 容:
验证码: 验证码
选 项:
虽然发表评论不用注册,但是为了保护您的发言权,建议您注册帐号.