1

ユーザーをプロジェクト ユーザー abcd@web.com に追加する必要があります。workSpace1 へのユーザー権限を持っています。Project1 は Java コードを通じて workSpace1 に存在します。ユーザーに Project1 への編集者権限を与える必要があります。

私は以下のコードを持っています - エラーはありません - しかし更新していません

//fetch project as JSonObject
JsonObject prjObj = new Example1().fetchPrjDetails("../project/12399939580.js", restApi);   

//get Editors as JSonArray           
JsonArray editorsList = prjObj.get("Editors").getAsJsonArray();

//Create new JSonObject with new user information            
JsonObject newUser = new JsonObject();
newUser.addProperty("_rallyAPIMajor", "1");
newUser.addProperty("_rallyAPIMinor", "37");
newUser.addProperty("_ref", "../user/12418060172.js");
newUser.addProperty("_refObjectName", "venu");
newUser.addProperty("_type", "User");

//add this new JSonObject to Editors Array          
editorsList.add(newUser);

//remove the existing editors  
prjObj.remove("Editors");
//i dont know whether i need the above line 

//add editors to 
prjObj.add("Editors", editorsList);


UpdateRequest uRequest = new UpdateRequest("..project/12399939580.js", prjObj);
UpdateResponse uResponse = restApi.update(uRequest);
    if (uResponse.wasSuccessful()) {
    System.out.println("update success");
    }       
4

1 に答える 1

2

プロジェクトの Editors コレクションは読み取り専用です。Rally の Web サービス API では、Rally ユーザーのユーザー権限は、ユーザー オブジェクトの UserPermissions コレクションで管理されます。ユーザーの新しい ProjectPermission を作成することにより、ユーザーを編集者としてプロジェクトに追加します。次の例は、既存の Rally ユーザーに対して編集者レベルの ProjectPermission を作成する方法と、ユーザーの TeamMemberships コレクションを更新して、そのユーザーがそのプロジェクト内のチーム メンバーでもあるようにする方法を示しています。

public class RestExample_AddExistingUserToProject {

    public static void main(String[] args) throws URISyntaxException, IOException {
        // Create and configure a new instance of RallyRestApi
        // Connection parameters
        String rallyURL = "https://rally1.rallydev.com";
        String wsapiVersion = "1.43";
        String applicationName = "RestExample_AddExistingUserToProject";

        // Integration Credentials
        // Must be a Rally Subscription Administrator, or a Workspace Administrator
        // in a Rally Workspace whose Workspace Admins have been granted user administration
        // privileges

        String myUserName = "subadmin@company.com";
        String myUserPassword = "topsecret";

        RallyRestApi restApi = new RallyRestApi(
                new URI(rallyURL),
                myUserName,
                myUserPassword);
        restApi.setWsapiVersion(wsapiVersion);
        restApi.setApplicationName(applicationName);       

        // Workspace and Project Settings
        String myWorkspace = "Middle Earth";
        String myProject = "Mirkwood";

        // Rally UserID and meta-data for whom we wish to add a new Project Permission
        String rallyUserId = "tauriel@midearth.com";

        // Workspace Permission Strings
        final String WORKSPACE_ADMIN = "Admin";
        final String WORKSPACE_USER = "User";
        final String PROJECT_EDITOR = "Editor";
        final String PROJECT_VIEWER = "Viewer";

        //Read User
        QueryRequest userRequest = new QueryRequest("User");
        userRequest.setFetch(new Fetch(
                "UserName", 
                "FirstName",
                "LastName",
                "DisplayName",
                "UserPermissions",
                "Name", 
                "Role", 
                "Workspace", 
                "ObjectID", 
                "Project", 
                "ObjectID", 
                "TeamMemberships")
        );
        userRequest.setQueryFilter(new QueryFilter("UserName", "=", rallyUserId));
        QueryResponse userQueryResponse = restApi.query(userRequest);
        JsonObject userObject = userQueryResponse.getResults().get(0).getAsJsonObject();      
        String userRef = userObject.get("_ref").toString();
        System.out.println("Found User with Ref: " + userRef);

        // Now add an additional Project Permission to the found User   

        // Get reference to Workspace in which Project for Permission Grant Resides
        QueryRequest workspaceRequest = new QueryRequest("Workspace");
        workspaceRequest.setFetch(new Fetch("Name", "Owner", "Projects"));
        workspaceRequest.setQueryFilter(new QueryFilter("Name", "=", myWorkspace));
        QueryResponse workspaceQueryResponse = restApi.query(workspaceRequest);
        String workspaceRef = workspaceQueryResponse.getResults().get(0).getAsJsonObject().get("_ref").toString();

        // Get reference to Project for this Permission Grant
        QueryRequest projectRequest = new QueryRequest("Project");
        projectRequest.setFetch(new Fetch("Name", "Owner", "Projects"));
        projectRequest.setQueryFilter(new QueryFilter("Name", "=", myProject));
        QueryResponse projectQueryResponse = restApi.query(projectRequest);
        JsonObject projectObj = projectQueryResponse.getResults().get(0).getAsJsonObject();
        String projectRef = projectObj.get("_ref").toString();

        // Create the new ProjectPermission for the User
        JsonObject newProjectPermission = new JsonObject();
        newProjectPermission.addProperty("Workspace", workspaceRef);      
        newProjectPermission.addProperty("Project", projectRef);
        newProjectPermission.addProperty("User", userRef);
        newProjectPermission.addProperty("Role", PROJECT_EDITOR);

        CreateRequest createProjectPermissionRequest = new CreateRequest("projectpermission", newProjectPermission);
        System.out.println(createProjectPermissionRequest.getBody());
        CreateResponse createProjectPermissionResponse = restApi.create(createProjectPermissionRequest);

        if (createProjectPermissionResponse.wasSuccessful()) {          
            System.out.println(String.format("Create Project Permission Successful? %s", createProjectPermissionResponse.wasSuccessful()));
            System.out.println(String.format("Added %s Access to Project %s", PROJECT_EDITOR, myProject));
            System.out.println(String.format("For user %s", rallyUserId));                     
        } else {
            String[] createErrors;
            createErrors = createProjectPermissionResponse.getErrors();
            System.out.println("Error occurred creating User Project Permissions: ");
            for (int i=0; i<createErrors.length;i++) {
                System.out.println(createErrors[i]);
            }
        }

        // Also Make this User a Team Member for Project of interest.
        // Get this User's Existing Team Memberships
        JsonArray existTeamMemberships = (JsonArray) userQueryResponse.getResults().get(0).getAsJsonObject().get("TeamMemberships");

        // Add this Project to User's Team Membership collection
        existTeamMemberships.add(projectObj);

        // Setup update fields/values for Team Membership
        JsonObject updateUserTeamMembershipObj = new JsonObject();
        updateUserTeamMembershipObj.add("TeamMemberships", existTeamMemberships);

        // Issue UpdateRequest for Team Membership
        System.out.println("\nUpdating User's Team Membership...");
        UpdateRequest updateTeamMembershipsRequest = new UpdateRequest(userRef, updateUserTeamMembershipObj);
        UpdateResponse updateTeamMembershipResponse = restApi.update(updateTeamMembershipsRequest);

        if (updateTeamMembershipResponse.wasSuccessful()) {
            System.out.println("Updated User to be Team Member in Project: " + myProject);
        } else {
            String[] updateTeamMembershipErrors;
            updateTeamMembershipErrors = updateTeamMembershipResponse.getErrors();
                System.out.println("Error occurred updating Team Membership: ");
            for (int i=0; i<updateTeamMembershipErrors.length;i++) {
                System.out.println(updateTeamMembershipErrors[i]);
            }                   
        }                
        restApi.close();
    }
}
于 2013-07-14T19:10:23.410 に答える