Example Use Case: Adding a Requirement

Following up on previous steps detailed in this section, this topic completes a use case for adding a requirement to Silk Central.

Before proceeding you must have satisfied the following pre-requisites:

  • You have completed the steps detailed for the requirements web service.
  • A working POJO or JUnit class with binding and login methods has been created.
  • You have familiarized yourself with the other Silk Central API help topics.
  1. Generate a web-service token in the User Settings page.
    1. Click on the user name in the Silk Central menu. The User Settings page opens.
    2. In the Web-Service Token section of the page, click Generate Token.
  2. Construct a requirements object that contains the desired data.
  3. Call the updateRequirement method by using the web-service token, project ID and the requirements object you have generated.
  4. Save the requirement ID that is returned by the updateRequirement method.
  5. Create a PropertyValue array of the requirement properties.
  6. Call the updateProperties method using the previously created array.
The wsimport will create the above mentioned Web Service objects:
  • Requirement
  • PropertyValue

You can now use the OOP methods of the above objects to consume the Web Service. No SOAP envelope construction is required. Below are excerpts of the code that is required to complete this use case.

/** project ID of Silk Central project */
private static final int PROJECT_ID = 0; 
 
/** propertyID for requirement risk */
public static final String PROPERTY_RISK = "Risk";
 
/** propertyID for requirement reviewed */
public static final String PROPERTY_REVIEWED = "Reviewed";
 
/** propertyID for requirement priority */
public static final String PROPERTY_PRIORITY = "Priority";
 
/** propertyID for requirement obsolete property */
public static final String PROPERTY_OBSOLETE = "Obsolete";
 
 
// Get the Requirements service
RequirementsService service = getRequirementsService();
 
// The web-service token that you have generated in the UI. Required to authenticate when using
// a web service.
String webServiceToken = "e39a0b5b-45db-42db-84b2-b85028d954d5";
 
// Construct Top Level Requirement
Requirement topLevelRequirement = new Requirement();
topLevelRequirement.setName("tmReqMgt TopLevelReq");
topLevelRequirement.setDescription("tmReqMgt TopLevel Desc");
 
PropertyValue propRisk = new PropertyValue();
propRisk.setPropertyId(PROPERTY_RISK);
propRisk.setValue("2");
PropertyValue propPriority = new PropertyValue();
propPriority.setPropertyId(PROPERTY_PRIORITY);
propPriority.setValue("3");
PropertyValue[] properties = new PropertyValue[] {propRisk, propPriority};
 
/*
* First add requirement skeleton, get its ID
* service is a binding stub, see above getRequirementsService()
*/
int requirementID = service.updateRequirement(webServiceToken, PROJECT_ID, topLevelRequirement, -1);
 
// Now loop through and set properties
for (PropertyValue propValue : properties) {
propValue.setRequirementId(requirementID);
service.updateProperty(webServiceToken, requirementID, propValue);
}
 
// Add Child Requirement
Requirement childRequirement = new Requirement();
childRequirement.setName("tmReqMgt ChildReq");
childRequirement.setDescription("tmReqMgt ChildLevel Desc");
childRequirement.setParentId(requirementID);
propRisk = new PropertyValue();
propRisk.setPropertyId(PROPERTY_RISK);
propRisk.setValue("1");
propPriority = new PropertyValue();
propPriority.setPropertyId(PROPERTY_PRIORITY);
propPriority.setValue("1");
properties = new PropertyValue[] {propRisk, propPriority};
 
int childReqID = service.updateRequirement(webServiceToken, PROJECT_ID, childRequirement, -1);
 
// Now loop through and set properties
for (PropertyValue propValue : properties) {
propValue.setRequirementId(requirementID);
service.updateProperty(webServiceToken, childReqID, propValue);
}
 
// Print Results
System.out.println("Login Successful with web-service token: " + webServiceToken);
System.out.println("Top Level Requirement ID: " + requirementID);
System.out.println("Child Requirement ID: " + childReqID);
Note: This sample code is also available in the Web Service Demo Client's class com.microfocus.silkcentral.democlient.samples.AddingRequirement.