Wikis - Page

How can I set multiple values for an attribute of type set using web services?

0 Likes

Problem:

How can I set multiple values for an attribute of type set using web services?

Resolution:

Using Web Services you can set multiple values for an attribute of type set.

Please see example below that logs in as admin | admin and adds 3 values (Windows 2000, Windows 2003 and Windows XP) to the attribute "Platform".

Please note - attributes and their options must be defined by using the GUI before they can be used via web services.

..............................................

package com.borland.testmanager.democlient.samples;

import java.net.MalformedURLException;
import java.net.URL;
import java.rmi.RemoteException;

import javax.xml.rpc.ServiceException;

import com.borland.testmanager.stubs.sccsystem.SystemService;
import com.borland.testmanager.stubs.sccsystem.SystemServiceServiceLocator;
import com.borland.testmanager.stubs.tmplanning.PlanningService;
import com.borland.testmanager.stubs.tmplanning.PlanningServiceServiceLocator;
import com.borland.testmanager.stubs.tmplanning.tm.PropertyValue;
import com.borland.testmanager.stubs.tmplanning.tm.TestPlanningNode;

/**
* Assigns options of attribute "Platform" (type SET) to a node.
*
* @author gehmayer
*
*/
public class SetPlatformAttributeSetOptions {

String host = "localhost";
int port = 19120;
String user = "admin";
String pwd = "admin";
int nodeId = 12; // see demo project: test definition "Attach File to Requirement" (ID=12)

/**
* @param args
*/
public static void main(String[] args) {

SetPlatformAttributeSetOptions optionsSetter = new SetPlatformAttributeSetOptions();

optionsSetter.processArguments(args);

try {
long sessionId = optionsSetter.login();

optionsSetter.setPlatformAttributeOptions(sessionId);

TestPlanningNode node = optionsSetter.retrieveNode(sessionId);

boolean noAttributesFound = ReadAttributeOptions.printAttributes(node);

if (noAttributesFound) {
System.out.printf("no attributes found for node "%s" (ID=%d)%n", node.getName(), node.getId());
}

} catch (Exception e) {
e.printStackTrace();
}
}

private void setPlatformAttributeOptions(long sessionId) throws MalformedURLException, ServiceException, RemoteException {
PlanningService planningService = new PlanningServiceServiceLocator().gettmplanning(new URL("http", host, port, "/services/tmplanning"));
planningService.updateProperties(sessionId, makePlatformOptions());
}

private PropertyValue[] makePlatformOptions() {
return new PropertyValue[] {
new PropertyValue() {
{
setPropertyTypeID("_attribute_option_");
setPropertyID ("_attribute_option_Platform");
setName ("Platform");
setValue ("Platform");
setNodeID (Integer.toString(nodeId));
setType (12); // attribute type SET (see javadoc of PropertyMetaInfo)
setChildren(new PropertyValue[] {
new PropertyValue() {
{
setPropertyTypeID("_attribute_option_");
setPropertyID ("_attribute_option_Platform");
setName ("Platform");
setValue ("Windows 2000");
setNodeID (Integer.toString(nodeId));
setType (12);
}
},
new PropertyValue() {
{
setPropertyTypeID("_attribute_option_");
setPropertyID ("_attribute_option_Platform");
setName ("Platform");
setValue ("Windows 2003");
setNodeID (Integer.toString(nodeId));
setType (12); // attribute type SET (see javadoc of PropertyMetaInfo)
}
},
new PropertyValue() {
{
setPropertyTypeID("_attribute_option_");
setPropertyID ("_attribute_option_Platform");
setName ("Platform");
setValue ("Windows XP");
setNodeID (Integer.toString(nodeId));
setType (12); // attribute type SET (see javadoc of PropertyMetaInfo)
}
},
});
}
}
};
}

private TestPlanningNode retrieveNode(long sessionId) throws ServiceException, MalformedURLException, RemoteException {
PlanningService planningService = new PlanningServiceServiceLocator().gettmplanning(new URL("http", host, port, "/services/tmplanning"));
TestPlanningNode node = planningService.getNode(sessionId, Integer.toString(nodeId));
return node;
}

private long login() throws ServiceException, MalformedURLException, RemoteException {
SystemService sccService = new SystemServiceServiceLocator().getsccsystem(new URL("http", host, port, "/services/sccsystem"));
long sessionId = sccService.logonUser(user, pwd);
return sessionId;
}

private void processArguments(String[] args) {
for (int i = 0; i
switch (i) {
case 0:
if ("help".equals(args)) {
System.out.println("valid arguments: host port user password nodeID");
System.exit(0);
} else {
host = args;
}
break;
case 1:
port = Integer.parseInt(args);
break;
case 2:
user = args;
break;
case 3:
pwd = args;
case 4:
nodeId = Integer.parseInt(args);
break;
}
}
}

}

SetPlatformAttributeSetOptions.java
Old KB# 30287
Comment List
Related
Recommended