cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Visit the PTCooler (the community lounge) to get to know your fellow community members and check out some of Dale's Friday Humor posts! X

add a new member in mks using the java mks api: mksapi.jar

CristianC.
3-Visitor

add a new member in mks using the java mks api: mksapi.jar

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:

}catch (APIException e) {

 

 

 

{

 

IntegrationPointFactory ipf = IntegrationPointFactory.getInstance();CmdRunner cmdRunner;

try {

cmdRunner = ipf.createLocalIntegrationPoint().getCommonSession()

.createCmdRunner();

 

cmdRunner.setDefaultHostname(

"myserver");

cmdRunner.setDefaultPort(7001);

cmdRunner.setDefaultUsername(

"IntegrationUser");

cmdRunner.setDefaultPassword(

"secret");

 

 

 

 

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,

5 REPLIES 5
David_G
5-Regular Member
(To:CristianC.)

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

}

IBM i on Power Systems: For when you can't afford to be out of business! I'm riding in the American Diabetes Association's Tour de Cure to raise money for diabetes research, education, advocacy, and awareness. You can make a tax deductible donation to my ride by visiting https://ptc.diabetessucks.net. You can see where my donations come from by visiting my interactive donation map ... https://ptc.diabetessucks.net/map (it's a geeky thing).

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.

mrump
14-Alexandrite
(To:CristianC.)

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,

mrump
14-Alexandrite
(To:CristianC.)

"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

....

Top Tags