How to pre-fill OSLC resource creation fields in Rational Change

Save time by pre-filling parts of the resource creation dialog

The Open Services for Lifecycle Collaboration (OSLC) core specification states that service providers can support receiving a POST request that contains a change request resource definition for the creation dialog URI. It retrieves a URI that represents the embedded page to be used. Neeraja Vishwanathapura provides sample code that shows how to pre-fill the creation dialog.

Neeraja Vishwanathapura (nevishwa@in.ibm.com), Senior Software Engineer, IBM

author photoNeeraja Vishwanathapura, a senior software engineer, has nearly nine years of experience in software development and has been working as a senior developer for IBM Rational Change software for the past five years. She has experience in Java, Java 2 Enterprise Edition (J2EE), Perl, web technologies such as Dojo toolkit, Ajax, web services, OSLC, and change and configuration management.



01 May 2012

Also available in Chinese Russian

Open Services for Lifecycle Collaboration (OSLC) represents a set of standards or rules for how software development tools provide their services and share their data with other tools.

If a software development tool provides a service through an OSLC interface, it is called an OSLC provider. A tool that provides an interface to use the services is called a consumer. The OSLC specifications define the rules for how an OSLC provider and a consumer should behave. One of these specifications is about pre-filling creation dialogs windows.

As an example, IBM® Rational® Change 5.3 behaves as an OSLC provider by providing many services. One such service is creating change requests through an OSLC interface. IBM® Rational® Quality Manager 3.0 might use or consume this service by relating the change request to a test case.

To integrate any software development tools in the OSLC mode, a tool that is a provider must register with the consumer so that the two tools can complete an exchange, and the same applies in reverse. In this example, Rational Quality Manager registers Rational Change as an OSLC service provider and Rational Change approves the registration. After the OSLC integration is established between the tools, the OSLC consumer can use the services from the provider. Therefore, now Rational Quality Manager can create and consume change requests in Rational Change and associate them with any of its test cases. To create or choose an existing change request, Rational Change has to provide a dialog through which the consumers can create or select the required resource. (This is another specification in OSLC called Delegated UI, where the provider must provide an interface for users to create and select resources.

Every time that the consumer creates a change request through its provider, the consumer needs to fill in all of the fields in the provider’s resource creation interface. Some developers might want some provider fields be pre-filled in the creation dialog so that do not need to enter the value every time or so they can add more to an existing value. The OSLC core specification defines this behavior of pre-filling the creation dialogs for providers. Rational Change implements this specification by allowing you to pre-fill the change request creation dialogs.

An example of how to pre-fill a creation dialog

To pre-fill a creation dialog, the OSLC consumer needs to send the pre-filling data in a POST request to the URI of the provider’s creation dialog. The provider must respond with a status of 201 (Created), with the Location response header and a value that is the URI to request the newly created form.

Service providers might not store the created form. Therefore, a GET method on these transient response URIs might result later, with response status codes of 404 (Not found) or 3xx (Redirect).

The code snippet that follows sends a POST request to the Rational Change creation dialog to pre-fill the dialog’s Summary attribute. After the response is received from the provider, the code prints the location for the actual pre-filled creation dialog.

Sample code to pre-fill a creation dialog in Rational Change
//import the required classes to create POST request
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.StringRequestEntity;

/**
* This class will POST a request to OSLC provider’s creation dialog to pre-fill 
* the dialog and from the embedded response, it prints the location for the actual 
* pre-filled creation dialog.
*/
public class PostToPreFillDialog
{

/**
* Pre-filling the Summary attribute in the creation dialog
*/
public static void postData(String url)
{

PostMethod post = new PostMethod(url);
try {
    post.setRequestHeader("Content-Type", "application/x-oslc-cm-change-request+xml");

    //create the data needs to be sent to the creation dialog. It should be in the 
    //format set above in the "Content-Type". Include the attribute names and values 
    //to be prefilled. I have added the ‘Summary’ attribute and its value.

    String data = "<oslc_cm:ChangeRequest xmlns:dcterms='http://purl.org/dc/terms/' 
    xmlns:foaf='http://xmlns.com/foaf/0.1/' 
        xmlns:oslc='http://open-services.net/ns/core#'
    xmlns:oslc_cm='http://open-services.net/xmlns/cm/1.0/' 
    xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'>
    <Summary>This is my synopsis!</Summary>
    </oslc_cm:ChangeRequest>";

    StringRequestEntity requestEntity = new StringRequestEntity(data);
    post.setRequestEntity(requestEntity);
			
    //set the user login credentials in the request 
    //header. Rational Change expects it to be set in a specific cookie.
    //This information can be got from the browser’s cookie.
    post.setRequestHeader("Cookie", "JSESSIONID=16rzss8fdtk3b; 
        ChangeLoginCookie_8080_context=
            user1%7c%5c%5myserver%5database%5testdb%7ccentral%7c
    User%7ctrue");
    
    //send the post request
    HttpClient httpclient = new HttpClient();
    int result = httpclient.executeMethod(post);
    
    //The response header has the location for the pre-filled dialog,
    System.out.print(post.getResponseHeader("Location"));
    }
    catch (HttpException e) { e.printStackTrace();  }
    catch (IOException e) {  e.printStackTrace();    }
    finally { post.releaseConnection();    }
}

public static void main(String args[])
{
try
    {
    //call the postData method with the URL to the creation dialog. 
    //The creation dialog URL can ge got from the provider’s OSLC service catalog.
    postData
        ("http://Myserver:8080/context/oslc/db/<database_guid>/role/User/dialog/
    START_HERE2entered");			
    } 
    catch (Exception e) { e.printStackTrace();	}
}
}

Download

DescriptionNameSize
Sample codepre-fill-creation-dialog-rational-change.zip2KB

Resources

Learn

Get products and technologies

Discuss

Comments

developerWorks: Sign in

Required fields are indicated with an asterisk (*).


Need an IBM ID?
Forgot your IBM ID?


Forgot your password?
Change your password

By clicking Submit, you agree to the developerWorks terms of use.

 


The first time you sign into developerWorks, a profile is created for you. Select information in your profile (name, country/region, and company) is displayed to the public and will accompany any content you post. You may update your IBM account at any time.

All information submitted is secure.

Choose your display name



The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerWorks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

Required fields are indicated with an asterisk (*).

(Must be between 3 – 31 characters.)

By clicking Submit, you agree to the developerWorks terms of use.

 


All information submitted is secure.

Dig deeper into Rational software on developerWorks


static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Rational
ArticleID=811994
ArticleTitle=How to pre-fill OSLC resource creation fields in Rational Change
publish-date=05012012