CmisObjectNotFoundException 在 getRootFolder() 上。

huangapple 未分类评论49阅读模式
英文:

CmisObjectNotFoundException on getRootFolder()

问题

s = d.getSession().session;
p.append("成功建立会话 \n");
p.append("id:" + s.getRepositoryInfo().getId() + "\n");
try {
    Folder folder = s.getRootFolder();
} catch (Exception e) {
    p.append("无法获取文件夹,原因:" + e.toString() + "\n");
}

response.getWriter().println("<html><body>");
try {
    // 使用具有包语义的唯一名称,例如 com.foo.MyRepository
    String uniqueName = "com.vat.VatDocumentsRepo";
    // 使用只有您的应用程序知道的秘密密钥(至少10个字符)
    String secretKey = "****";
    Session openCmisSession = null;
    InitialContext ctx = new InitialContext();

    String lookupName = "java:comp/env/" + "EcmService";
    EcmService ecmSvc = (EcmService) ctx.lookup(lookupName);
    try {
        // 连接到我的存储库
        openCmisSession = ecmSvc.connect(uniqueName, secretKey);
    } catch (CmisObjectNotFoundException e) {
        // 存储库不存在,因此尝试创建它
        RepositoryOptions options = new RepositoryOptions();
        options.setUniqueName(uniqueName);
        options.setRepositoryKey(secretKey);
        options.setVisibility(Visibility.PROTECTED);
        ecmSvc.createRepository(options);
        // 现在应该已创建,因此连接到它
        openCmisSession = ecmSvc.connect(uniqueName, secretKey);
        openCmisSession.getDefaultContext().setIncludeAcls(true);
        openCmisSession.getDefaultContext().setIncludeAllowableActions(true);
        openCmisSession.getDefaultContext().setIncludePolicies(false);
    }
    response.getWriter().println(
            "<h3>您现在已连接到具有 ID 的存储库" +
            openCmisSession.getRepositoryInfo().getId() +
            "</h3>");
    Folder folder = openCmisSession.getRootFolder();
    Map<String, String> newFolderProps = new HashMap<String, String>();
    newFolderProps.put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder");
    newFolderProps.put(PropertyIds.NAME, "Attachments");
    try {
        folder.createFolder(newFolderProps);
    } catch (CmisNameConstraintViolationException e) {
        // 文件夹已存在,无需操作
    }
    String userIdOfUser1 = "user1 ";
    String userIdOfUser2 = "user2";
    response.getWriter().println("<h3>创建者:" + folder.getCreatedBy() + "</h3>");
    List<Ace> addAcl = new ArrayList<Ace>();

    // 为用户U1构建并添加ACE
    List<String> permissionsUser1 = new ArrayList<String>();
    permissionsUser1.add("cmis:all");
    Ace aceUser1 = openCmisSession.getObjectFactory().createAce(userIdOfUser1, permissionsUser1);
    addAcl.add(aceUser1);

    // 为用户U2构建并添加ACE
    List<String> permissionsUser2 = new ArrayList<String>();
    permissionsUser2.add("cmis:read");
    Ace aceUser2 = openCmisSession.getObjectFactory().createAce(userIdOfUser2, permissionsUser2);
    addAcl.add(aceUser2);
    response.getWriter().println("<b>用户权限" + addAcl.toString() + "</b>");
    List<Ace> removeAcl = new ArrayList<Ace>();

    // 为用户{sap:builtin}everyone构建并添加ACE
    List<String> permissionsEveryone = new ArrayList<String>();
    permissionsEveryone.add("cmis:all");
    Ace aceEveryone = openCmisSession.getObjectFactory().createAce(
            "{sap:builtin}everyone", permissionsEveryone);
    removeAcl.add(aceEveryone);
    response.getWriter().println("<b>移除用户权限" + removeAcl.toString() + "</b>");

    ItemIterable<CmisObject> children = folder.getChildren();
    response.getWriter().println("<h1>更改以下对象的权限:</h1><ul>");
    for (CmisObject o : children) {
        response.getWriter().println("<li>");
        if (o instanceof Folder) {
            response.getWriter().println("创建者:" + o.getCreatedBy());
            o.applyAcl(addAcl, removeAcl, AclPropagation.OBJECTONLY);
            response.getWriter().println("已更改权限</li>");
        } else {
            Document doc = (Document) o;
            response.getWriter().println("创建者:" + o.getCreatedBy() + " 文件大小:" +
                    doc.getContentStreamLength() + " 字节");
            doc.applyAcl(addAcl, removeAcl, AclPropagation.OBJECTONLY);
            response.getWriter().println("已更改权限</li>");
        }
    }
    response.getWriter().println("</ul>");
} catch (Exception e) {
    response.getWriter().println("<h1>错误:" + e.toString() + "</h1>");
} finally {
    response.getWriter().println("</body></html>");
}
英文:

I'm getting CMISNotFoundException while accessing the root folder even though i already have many documents uploaded to the repository.I'm able to fetch the repository id but getRootFolder throws error

could not fetch folder due to org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException: Object not found

s = d.getSession().session;
p.append(&quot;Successfully established session \n&quot;);
p.append(&quot;id:&quot;+s.getRepositoryInfo().getId()+&quot;\n&quot;);
try {
	Folder folder = s.getRootFolder();
	}catch(Exception e) {
           p.append(&quot;could not fetch folder due to &quot;+e.toString()+&quot;\n&quot;);
	}
	  

I'm able to get the root folder now after creating a new repository.But now for applying ACLS i'm facing problem.

  1. LWhen i try to apply ACl to the root folder i get CmisObjectNotFound exception.
  2. When i apply ACL to subfolders, it workds but the permission is not applied correctly.I want to give user1 all the permission and user 2 read permission.But for user1 , now i'm not able to even view the folder.And for user2 i'm able to do everything except download.

I have referred to this link for doing so sap-link

 response.getWriter().println(&quot;&lt;html&gt;&lt;body&gt;&quot;);
    try {
      // Use a unique name with package semantics e.g. com.foo.MyRepository
      String uniqueName = &quot;com.vat.VatDocumentsRepo&quot;;
      // Use a secret key only known to your application (min. 10 chars)
      String secretKey = &quot;****&quot;;
      Session openCmisSession = null;
        InitialContext ctx = new InitialContext();
        
        String lookupName = &quot;java:comp/env/&quot; + &quot;EcmService&quot;;
        EcmService ecmSvc = (EcmService) ctx.lookup(lookupName);
      try {
        // connect to my repository
        openCmisSession = ecmSvc.connect(uniqueName, secretKey);
        
      }
      catch (CmisObjectNotFoundException e) {
        // repository does not exist, so try to create it
        RepositoryOptions options = new RepositoryOptions();
        options.setUniqueName(uniqueName);
        options.setRepositoryKey(secretKey);
        options.setVisibility(Visibility.PROTECTED);
        ecmSvc.createRepository(options);
        // should be created now, so connect to it
        openCmisSession = ecmSvc.connect(uniqueName, secretKey);
        openCmisSession.getDefaultContext().setIncludeAcls(true);
        openCmisSession.getDefaultContext().setIncludeAllowableActions(true);
        openCmisSession.getDefaultContext().setIncludePolicies(false);
      }
      response.getWriter().println(
        &quot;&lt;h3&gt;You are now connected to the Repository with Id &quot;
        + openCmisSession.getRepositoryInfo().getId()
        + &quot;&lt;/h3&gt;&quot;);
      Folder folder = openCmisSession.getRootFolder();
      Map&lt;String, String&gt; newFolderProps = new HashMap&lt;String, String&gt;();
      newFolderProps.put(PropertyIds.OBJECT_TYPE_ID, &quot;cmis:folder&quot;);
      newFolderProps.put(PropertyIds.NAME, &quot;Attachments&quot;);
      try {
        folder.createFolder(newFolderProps);
      } catch (CmisNameConstraintViolationException e) {
        // Folder exists already, nothing to do
      }
      String userIdOfUser1 = &quot;user1 &quot;;
      String userIdOfUser2 = &quot;user2&quot;;
      response.getWriter().println(&quot;&lt;h3&gt;Created By :&quot;+folder.getCreatedBy()+&quot;&lt;/h3&gt;&quot;);
      List&lt;Ace&gt; addAcl = new ArrayList&lt;Ace&gt;();

  	// build and add ACE for user U1
  	List&lt;String&gt; permissionsUser1 = new ArrayList&lt;String&gt;();
  	permissionsUser1.add(&quot;cmis:all&quot;);
  	Ace aceUser1 = openCmisSession.getObjectFactory().createAce(userIdOfUser1, permissionsUser1);
  	addAcl.add(aceUser1);
  	
  	// build and add ACE for user U2
  	List&lt;String&gt; permissionsUser2 = new ArrayList&lt;String&gt;();
  		permissionsUser2.add(&quot;cmis:read&quot;);
  	Ace aceUser2 = openCmisSession.getObjectFactory().createAce(userIdOfUser2, 
  		permissionsUser1);
  	addAcl.add(aceUser2);
  	response.getWriter().println(&quot;&lt;b&gt;Permissions for users&quot;+addAcl.toString()+&quot;&lt;/b&gt;&quot;);
  	// list of ACEs which should be removed
  	List&lt;Ace&gt; removeAcl = new ArrayList&lt;Ace&gt;();

  	// build and add ACE for user {sap:builtin}everyone
  	List&lt;String&gt; permissionsEveryone = new ArrayList&lt;String&gt;();
  		permissionsEveryone.add(&quot;cmis:all&quot;);
  	Ace aceEveryone = openCmisSession.getObjectFactory().createAce(
  	    	&quot;{sap:builtin}everyone&quot;, permissionsEveryone);
  	removeAcl.add(aceEveryone);
  	response.getWriter().println(&quot;&lt;b&gt;Removing Permissions for users&quot;+removeAcl.toString()+&quot;&lt;/b&gt;&quot;);

  	ItemIterable&lt;CmisObject&gt; children = folder.getChildren();
	response.getWriter().println(&quot;&lt;h1&gt; changing permissions of the following objects: &lt;/h1&gt;&lt;ul&gt;&quot;);
	for (CmisObject o : children) {
		response.getWriter().println(&quot;&lt;li&gt;&quot;);
		if (o instanceof Folder) {
	          response.getWriter().println(&quot; createdBy: &quot; + o.getCreatedBy());
	          o.applyAcl(addAcl, removeAcl, AclPropagation.OBJECTONLY);
	          response.getWriter().println(&quot;Changed permission&lt;/li&gt;&quot;);
	          
	        } else {
	          Document doc = (Document) o;
	          response.getWriter().println(&quot; createdBy: &quot; + o.getCreatedBy() + &quot; filesize: &quot;
	                                     + doc.getContentStreamLength() + &quot; bytes&quot;);
	          doc.applyAcl(addAcl, removeAcl, AclPropagation.OBJECTONLY);
	          response.getWriter().println(&quot;Changed permission&lt;/li&gt;&quot;);
	        }
	}
	response.getWriter().println(&quot;&lt;/ul&gt;&quot;);
          } catch (Exception e) {
      response.getWriter().println(&quot;&lt;h1&gt;Error: &quot;+e.toString()+&quot;&lt;/h1&gt;&quot;);
    } finally {
      response.getWriter().println(&quot;&lt;/body&gt;&lt;/html&gt;&quot;);
    }

huangapple
  • 本文由 发表于 2020年4月3日 20:28:27
  • 转载请务必保留本文链接:https://java.coder-hub.com/61011934.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定