It's all about the answers!

Ask a question

How to create a defect(customised work item) in Project using OSLC Java Programming?


Pankaj Kumar (17216) | asked Aug 14 '17, 2:55 a.m.

 Hi,

 

Kindly guide me on creating customized work item(defect) by using OSLC Java programming. <o:p> </o:p>

 

As of now,i'm able to create default defect in sample project. <o:p> </o:p>

 

When i'm trying to create a defect(customised work item) in my project,i'm able to see that workitem-task is created instead of defect-work item. <o:p> </o:p>

 

 

Please find the below code used. <o:p> </o:p>

 

                String webContextUrl = " "; <o:p> </o:p>

                                String user = " "; <o:p> </o:p>

                                String passwd = " "; <o:p> </o:p>

                                String projectArea = " "; <o:p> </o:p>

 

                                try { <o:p> </o:p>

 

                                                //STEP 1: Initialize a Jazz rootservices helper and indicate we're looking for the ChangeManagement catalog <o:p> </o:p>

                                                //RTC contains a service provider for CM and SCM, so we need to indicate our interest in CM <o:p> </o:p>

                                                JazzRootServicesHelper helper = new JazzRootServicesHelper(webContextUrl,OSLCConstants.OSLC_CM_V2); <o:p> </o:p>

 

                                                //STEP 2: Create a new Form Auth client with the supplied user/password <o:p> </o:p>

                                                JazzFormAuthClient client = helper.initFormClient(user, passwd); <o:p> </o:p>

 

                                                //STEP 3: Login in to Jazz Server <o:p> </o:p>

                                                if (client.formLogin() == HttpStatus.SC_OK) { <o:p> </o:p>

                                                                System.out.println("Login Successful"); <o:p> </o:p>

 

                                                                //STEP 4: Get the URL of the OSLC ChangeManagement catalog <o:p> </o:p>

                                                                String catalogUrl = helper.getCatalogUrl(); <o:p> </o:p>

 

                                                                //STEP 5: Find the OSLC Service Provider for the project area we want to work with <o:p> </o:p>

                                                                String serviceProviderUrl = client.lookupServiceProviderUrl(catalogUrl, projectArea); <o:p> </o:p>

 

                                                                //STEP 6: Get the Query Capabilities URL so that we can run some OSLC queries <o:p> </o:p>

                                                                String queryCapability = client.lookupQueryCapability(serviceProviderUrl, <o:p> </o:p>

                                                                                                                                                                                                                                                                                  OSLCConstants.OSLC_CM_V2, <o:p> </o:p>

                                                                                                                                                                                                                                                                                  OSLCConstants.CM_CHANGE_REQUEST_TYPE); <o:p> </o:p>

 

                                                                <o:p> </o:p>

                                                                <o:p> </o:p>

                                                                //SCENARIO D:  RTC defect creation <o:p> </o:p>

                                                                ChangeRequest defect = new ChangeRequest(); <o:p> </o:p>

                                                                <o:p> </o:p>

                                                                <o:p> </o:p>

                                                                defect.setTitle("Error logging in by Sujith Babu Bandla"); <o:p> </o:p>

                                                                defect.setDescription("An error occurred when I tried to log in with a user ID - sujithbabubandla, that contained the '@' symbol."); <o:p> </o:p>

                                                                defect.addTestedByTestCase(new Link(new URI("http://qmprovider/testcase-sujithbabu/3"), "Global Verifcation Test - sujith babu")); <o:p> </o:p>

                                                                defect.addDctermsType("defect"); <o:p> </o:p>

 

                                                                //Get the Creation Factory URL for change requests so that we can create one <o:p> </o:p>

                                                                CreationFactory defectCreation = client.lookupCreationFactoryResource( <o:p> </o:p>

                                                                                                serviceProviderUrl, OSLCConstants.OSLC_CM_V2, <o:p> </o:p>

                                                                                                defect.getRdfTypes()[0].toString(), OSLCConstants.OSLC_CM_V2 + "defect"); <o:p> </o:p>

                                                                String factoryUrl = defectCreation.getCreation().toString(); <o:p> </o:p>

 

                                                                //Determine what to use for the Filed Against attribute by requesting the resource shape for the creation factory. <o:p> </o:p>

                                                                String shapeUrl = defectCreation.getResourceShapes()[0].toString(); <o:p> </o:p>

                                                                ClientResponse shapeResponse = client.getResource(shapeUrl,OslcMediaType.APPLICATION_XML); <o:p> </o:p>

                                                                ResourceShape shape = shapeResponse.getEntity(ResourceShape.class); <o:p> </o:p>

 

                                                                //Look at the allowed values for Filed Against. This is generally a required field for defects. <o:p> </o:p>

                                                                Property filedAgainstProperty = shape.getProperty(new URI(RTC_NAMESPACE + RTC_FILED_AGAINST)); <o:p> </o:p>

                                                                if (filedAgainstProperty != null) { <o:p> </o:p>

                                                                                URI allowedValuesRef = filedAgainstProperty.getAllowedValuesRef(); <o:p> </o:p>

                                                                                ClientResponse allowedValuesResponse = client.getResource(allowedValuesRef.toString(),OslcMediaType.APPLICATION_XML); <o:p> </o:p>

                                                                                AllowedValues allowedValues = allowedValuesResponse.getEntity(AllowedValues.class); <o:p> </o:p>

                                                                                Object[] values = allowedValues.getValues().toArray(); <o:p> </o:p>

                                                                                //If this fails, you might need to check that the value is <o:p> </o:p>

                                                                                //not "Unassigned", which is an allowed value in some RTC <o:p> </o:p>

                                                                                //project areas. Try the second value instead of the first, most project area processes <o:p> </o:p>

                                                                                //create more than one category <o:p> </o:p>

                                                                                defect.getExtendedProperties().put(new QName(RTC_NAMESPACE, RTC_FILED_AGAINST), (URI) values[1]); <o:p> </o:p>

                                                                } <o:p> </o:p>

 

                                                                //Create the change request <o:p> </o:p>

                                                                ClientResponse creationResponse = client.createResource( <o:p> </o:p>

                                                                                                factoryUrl, defect, <o:p> </o:p>

                                                                                                OslcMediaType.APPLICATION_RDF_XML, <o:p> </o:p>

                                                                                                OslcMediaType.APPLICATION_RDF_XML); <o:p> </o:p>

                                                                String defectLocation = creationResponse.getHeaders().getFirst(HttpHeaders.LOCATION); <o:p> </o:p>

                                                                if (creationResponse.getStatusCode() != HttpStatus.SC_CREATED) { <o:p> </o:p>

                                                                                System.err.println("ERROR: Could not create the defect (status " + creationResponse.getStatusCode() + ")\n"); <o:p> </o:p>

                                                                                System.err.println(creationResponse.getEntity(String.class)); <o:p> </o:p>

                                                                                System.exit(1); <o:p> </o:p>

                                                                } <o:p> </o:p>

                                                                creationResponse.consumeContent(); <o:p> </o:p>

                                                                System.out.println("Defect created at location " + defectLocation); <o:p> </o:p>

                                <o:p> </o:p>

                                                                <o:p> </o:p>

Any suggestion will be helpful.

Thanks in advance.                                                 <o:p> </o:p>

Regards, <o:p> </o:p>

Pankaj Kumar

2 answers



permanent link
Ralph Schoon (63.5k33646) | answered Aug 21 '17, 5:48 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Not sure where that API comes from. I think the code to set or select the work item type, is this and uses "defect" as default. To create a different type you would have to set the type ID to the desired value.

CreationFactory defectCreation = client.lookupCreationFactoryResource( serviceProviderUrl,  OSLCConstants.OSLC_CM_V2,  defect.getRdfTypes()[0].toString(), OSLCConstants.OSLC_CM_V2 + "defect");


permanent link
Sujith Babu Bandla (266) | answered Sep 05 '17, 6:28 a.m.

 Hi Pankaj,


You can tye the below code once

//RTC defect creation
ChangeRequest defect1 = new ChangeRequest();
//severity
defect1.addDctermsType("defect_new");
defect1.setTitle("Error logging in by Sujith Babu Bandla");
defect1.setDescription("An error occurred when I tried to log in with a user ID - , that contained the '@' symbol.");
defect1.addTestedByTestCase(new Link(new URI("http://qmprovider/testcase/3"), "Global Verifcation Test -"));
//defect1.setExtendedProperties(new QName("http://jazz.net/xmlns/prod/jazz/rtc/ext/1.0/", "sw_new", "rtc_ext"), "1234");
defect1.getExtendedProperties().put(new QName("http://jazz.net/xmlns/prod/jazz/rtc/ext/1.0/", "sw_new", "rtc_ext"), "1234");
defect1.getExtendedProperties().put(new QName("http://jazz.net/xmlns/prod/jazz/rtc/ext/1.0/", "affected_new", "rtc_ext"), "4444");
defect1.getExtendedProperties().put(new QName("http://jazz.net/xmlns/prod/jazz/rtc/ext/1.0/", "test_scenario_new", "rtc_ext"), "This is a Testcase created by scenario ");
defect1.getExtendedProperties().put(new QName("http://jazz.net/xmlns/prod/jazz/rtc/ext/1.0/", "ica_new", "rtc_ext"), "This is a Testcase created by scenario");
//defect1.getExtendedProperties().put(new QName("http://jazz.net/xmlns/prod/jazz/rtc/ext/1.0/", "internalPriority", "rtc_ext"), "High");
//2017-12-17T22:22:33.419Z
defect1.getExtendedProperties().put(new QName("http://jazz.net/xmlns/prod/jazz/rtc/ext/1.0/", "issue_obsrv", "rtc_ext"), "2017-09-06T11:28:33Z");
//Get the Creation Factory URL for change requests so that we can create one
CreationFactory defectCreation = client.lookupCreationFactoryResource(
serviceProviderUrl, OSLCConstants.OSLC_CM_V2,defect1.getRdfTypes()[0].toString(), OSLCConstants.OSLC_CM_V2 + "defect");
String factoryUrl = defectCreation.getCreation().toString();

//Determine what to use for the Filed Against attribute by requesting the resource shape for the creation factory.
String shapeUrl = defectCreation.getResourceShapes()[0].toString();
ClientResponse shapeResponse = client.getResource(shapeUrl,OslcMediaType.APPLICATION_XML);
ResourceShape shape = shapeResponse.getEntity(ResourceShape.class);

//Look at the allowed values for Filed Against. This is generally a required field for defects.
Property filedAgainstProperty = shape.getProperty(new URI(RTC_NAMESPACE + RTC_FILED_AGAINST));
if (filedAgainstProperty != null) {
URI allowedValuesRef = filedAgainstProperty.getAllowedValuesRef();
ClientResponse allowedValuesResponse = client.getResource(allowedValuesRef.toString(),OslcMediaType.APPLICATION_XML);
AllowedValues allowedValues = allowedValuesResponse.getEntity(AllowedValues.class);
Object[] values = allowedValues.getValues().toArray();
//If this fails, you might need to check that the value is not "Unassigned", which is an allowed value in some RTC project areas.
//Try the second value instead of the first, most project area processes create more than one category
defect1.getExtendedProperties().put(new QName(RTC_NAMESPACE, RTC_FILED_AGAINST), (URI) values[1]);
}
//Look at the allowed values for Priority. This is generally a required field for defects.
Property Vehicle_build_phase_newProperty = shape.getProperty(new URI("http://jazz.net/xmlns/prod/jazz/rtc/ext/1.0/"+"vehicle_build_phase_new"));
if(null !=Vehicle_build_phase_newProperty) {
URI allowedValuesRef2=Vehicle_build_phase_newProperty.getAllowedValuesRef();
ClientResponse allowedValuesResponse2= client.getResource(allowedValuesRef2.toString(),OslcMediaType.APPLICATION_XML);
AllowedValues allowedValues2 = allowedValuesResponse2.getEntity(AllowedValues.class);
Object[] values2 = allowedValues2.getValues().toArray();
defect1.getExtendedProperties().put(new QName("http://jazz.net/xmlns/prod/jazz/rtc/ext/1.0/","vehicle_build_phase_new", "rtc_ext"), (URI) values2[1]);
}

Thanks,
Sujith Babu

Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.