Community Tip - Learn all about PTC Community Badges. Engage with PTC and see how many you can earn! X
Hello
I am working at java tool which connects at the mks source integrity server that add new members in an mks project.
I read the following documentation
{
}
and I found java sample code only for connection with the server:
{
IntegrationPointFactory ipf = IntegrationPointFactory.getInstance();CmdRunner cmdRunner;
cmdRunner = ipf.createLocalIntegrationPoint().getCommonSession()
.createCmdRunner();
cmdRunner.setDefaultHostname(
cmdRunner.setDefaultPort(7001);
cmdRunner.setDefaultUsername(
cmdRunner.setDefaultPassword(
e.printStackTrace();
}
However I have not found in the above documentation a sample for adding members in mks source integrity server using the mks java api.
Would you give me a sample code that do that or pointing me another documentation for the mks source integrity java api ?
Best Regards,
This is a very rough example of adding a member to a project using the Java API...
Command cmd = new Command(Command.SI, "add");
cmd.addOption(new Option("description", descriptionText));
cmd.addOption(new Option("project", projectPath));
cmd.addSelection(filename);
Response resp = null;
try {
resp = cmdRunner.execute(cmd);
} catch (APIException e) {
// deal with exception
}
David Gibbs wrote:
This is a very rough example of adding a member to a project using the Java API...
Command cmd = new Command(Command.SI, "add"); cmd.addOption(new Option("description", descriptionText)); cmd.addOption(new Option("project", projectPath)); cmd.addSelection(filename); Response resp = null; try { resp = cmdRunner.execute(cmd); } catch (APIException e) { // deal with exception }
IntegrationPointFactory integrationPointFactory = IntegrationPointFactory.getInstance();
CmdRunner cmdRunner;
try {
cmdRunner = (CmdRunner) integrationPointFactory.createIntegrationPoint("myserver",7001)
.getCommonSession().createCmdRunner();
cmdRunner.setDefaultHostname("myserver");
cmdRunner.setDefaultPort(7001);
cmdRunner.setDefaultUsername("IntegrationUser");
cmdRunner.setDefaultPassword("secret");
Command cmd = new Command(Command.SI, "add");
cmd.addOption(new Option("description", "test"));
cmd.addOption(new Option(
"project",
"_ProjectPath_\\project.pj"));
cmd.addSelection("_ProjectPath_\\KPI_TMP_MKS_API_TEST__.xls");
Response resp = null;
try {
resp = cmdRunner.execute(cmd);
System.out.println("resp. "+resp.getExitCode());
} catch (APIException e) {
e.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
}
I have run the above code and I have not encountered any mks api exception.
Please note that I modified the mks server access details (serverhost, server port, username and password) with the correct ones then I checked the mks server and the file was not added in mks and neither exception was throw by the java mks api.
Thanks in advance for any usefull advice.
Hi Cristian,
in addition to David's post you might keep in mind that the Command Line Interface and the Java API share almost all commands (but not ALL).
So, in terms of options/flags/parameters (as shown by David) the Java API's usage is a straight copy of the CLI. The schema is always the same:
1. create the command object
2. add Option(s)
3. add Selection(s)
4. use your IntegrationPoint's CmdRunner to execute the command
5. analyze the response Object
Personally I always check whether a command works as expected using the CLI (especially with the --xmlapi option for result output) before I try to use it in Java.
For many commands the inner structure of the command response is not as simple as it might look on the CLI.
But as long as you receive a valid and meaningful XML result on CLI you can be quite sure it will work as expected in Java.
HTH Matthias
Hello Matthias,
Would you give me a concrete example about using the --xml api option?
Best Regards,
"si projects --xmlapi"
gives you XML representation of the API's Response Object, like this
<?xml version="1.0"?>
<Response command="projects" app="si" version="4.12.4301 4-1 4301">
<App-Connection port="7001" userID="######" server="##########"></App-Connection>
<WorkItems selectionType="Projects">
<WorkItem id="#/projectA" displayId="/projectA/project.pj" modelType="si.Project">
<Field name="projectName">
<Value dataType="string">
<TokenValue>/projectA/project.pj</TokenValue>
</Value>
</Field>
<Field name="canonicalPath">
<Value dataType="string">
<TokenValue>/projectA/project.pj</TokenValue>
</Value>
</Field>
......
<Field name="isSubproject"><Value dataType="boolean">
<TokenValue>false</TokenValue>
</Value>
</Field>
<Field name="isShared">
<Value dataType="boolean">
<TokenValue>false</TokenValue>
</Value>
</Field>
<Field name="parentProject">
<Value></Value>
</Field>
<Field name="isVariant">
<Value dataType="boolean">
<TokenValue>false</TokenValue>
</Value>
</Field>
<Field name="developmentPath">
<Value></Value>
</Field>
<Field name="isBuild">
<Value dataType="boolean">
<TokenValue>false</TokenValue>
</Value>
</Field>
<Field name="buildRevision">
<Value></Value>
</Field>
</WorkItem>
<WorkItem id="#/projectB" displayId="/projectB/project.pj" modelType="si.Project">
......
</WorkItem></WorkItems>
</Response>
This can be very useful in understanding the Response in the JAVA API :
- when to expect a single WorkItem or a WorkItemIterator
- what fields of what type are available
- what "wrapper"-objects exist and where is you actual "target value" hidden
....