PolicyDefinition result return empty collection using Java SDK of TFS 2015 "tp.getCheckinPolicies()" or "vcc.getCheckinPoliciesForServerPaths()"

137 views Asked by At

Does anyone tried to retrieve PolicyDefinition using Java SDK of TFS 2015?

I have used following code to retrieve the PolicyDefinition under intelliJ Plugin. Code execute fine but I am getting empty collection of PolicyDefinition. I am working on CustomPath Policy and I know on particular team project customPath Policy is applied.

Before allowing user checkin I want to validate that weather this policy is applied or not.

Sample Code:

Project myProject = policyContext.getProject(); // PolicyContext is received from intelliJ and I got Project
                                                // object opened in intelliJ

Workstation workstation = Workstation.getInstance(); // Workspace Info, it depeneds how many workspaces created
                                                        // to map TFS solution
Collection<WorkspaceInfo> workspaceInfos = workstation
        .findWorkspacesCached(TfsFileUtil.getFilePath(myProject.getBaseDir()), false); // This will return the
                                                                                        // workspace info based
                                                                                        // on project path.

WorkspaceInfo workspaceInfo = workspaceInfos.iterator().next();
Collection<String> serverFolderPaths = workspaceInfo
        .findServerPathsByLocalPath(VcsUtil.getFilePath(myProject.getBasePath()), false, myProject); // This
                                                                                                        // will
                                                                                                        // return$/TeamProjectCollection/TeamProject/ProjectFolder

ServerInfo serverInfo = workspaceInfo.getServer();
TfsSdkManager tfsSdkManager = TfsSdkManager.getInstance(); // intelliJ provide TfsSdkManager to get cached
                                                            // information about TFS, like credential
Credentials credentials = tfsSdkManager.getCredentials(serverInfo);
URI uri = new URI(serverInfo.getPresentableUri());

TFSTeamProjectCollection tpc = new TFSTeamProjectCollection(uri, credentials);
tpc.ensureAuthenticated();
VersionControlClient vcc;

vcc = forcePluginClassLoader(() -> tpc.getVersionControlClient()); // intelliJ has SOX issue if call is not
                                                                    // wrapped using forcePluginClassLoader()
                                                                    // method;
String teamProjectServerPath = "$/TeamProjectCollection"; // Tried to pass "$/TeamProjectCollection/TeamProject"
                                                            // as well but same result, getting emppty
//line: 15                                                          // collection of PlicyDefinition
PolicyDefinition[] results = vcc.getCheckinPoliciesForServerPaths(new String[] { teamProjectServerPath });

String serverProjectPath = serverFolderPaths.iterator().next();

// Another way to get policy
Item item = vcc.getItem("$/TeamProjectCollection");
TeamProject tp = new TeamProject(item, vcc);

String projectName = tp.getName();

//line: 20
PolicyDefinition[] ps = tp.getCheckinPolicies();
for (PolicyDefinition pd : ps) {
    int pi = pd.getPriority();

}

Line 15 & 20 both returns empty Policy definition.

Anyone faced this issue?

0

There are 0 answers