コード例 #1
0
ファイル: AbstractSysObject.java プロジェクト: yanglogan/zgh
  @Override
  public IAfSysObject copyTo(String specific, String newName) throws AfException {
    if (isNew()) {
      throw new AfException("this object is new, you can not do copy action");
    }

    NodeService nodeService = ServiceHelper.getNodeService(afSession);
    NodeRef parent = getSpecifiedNode(specific);

    if (parent == null || !nodeService.exists(parent)) {
      throw new AfException("the folder " + specific + " you specified not exist");
    }

    IAfType folderType = AFCHelper.getNodeType(afSession, parent);
    if (!(folderType.isSubTypeOf("cm:folder") || folderType.getName().equals("cm:folder"))) {
      // parent is a doc
      throw new AfException("you can not copy object into a document");
    }

    CopyService copyService = ServiceHelper.getCopyService(afSession);

    String objName = (newName == null) ? getObjectName() : newName;
    QName nodeName = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, objName);
    NodeRef ref = copyService.copyAndRename(nodeRef, parent, getAssType(), nodeName, true);

    IAfSysObject object = (IAfSysObject) afSession.getObject(new AfID(ref.getId()));

    object.setObjectName(objName);
    object.save();

    return object;
  }
コード例 #2
0
  private NodeRef createNodeWithPermission(NodeRef parent, String username, String permission) {
    // Authenticate as system user because the current user should not be node owner
    AuthenticationComponent authenticationComponent =
        (AuthenticationComponent) this.applicationContext.getBean("authenticationComponent");
    authenticationComponent.setSystemUserAsCurrentUser();

    // Create the node as a copy of prepared
    NodeRef node =
        copyService.copy(nodeRef, parent, ContentModel.ASSOC_CHILDREN, ContentModel.TYPE_CONTENT);

    // Apply permissions to node
    permissionService.deletePermissions(node);
    permissionService.setInheritParentPermissions(node, false);
    permissionService.setPermission(node, userName, permission, true);

    // Authenticate test user
    TestWithUserUtils.authenticateUser(
        this.userName, PWD, this.rootNodeRef, this.authenticationService);

    return node;
  }