如何使用Eclipse Lyo Java API在RTC中创建Risk类型变更请求?
Great to hear you've already got Task and Defect creation working—creating a Risk follows the same core pattern, but we just need to adjust a few key details specific to the Risk work item type. Here's how to do it:
Step 1: Identify the OSLC Type Identifiers for Risk
First, you'll need the correct RDF type URI and OSLC resource type for your RTC Risk work item. Unlike Task/Defect which use standard Lyo constants, custom or specialized types like Risk often have unique URIs. You can find these in two straightforward ways:
- Check RTC's OSLC Service Documentation: Navigate to your project area's OSLC service provider document (usually at a URL like
https://your-rtc-server/ccm/oslc/workitems/serviceProviders/[project-area-id]) and look for CreationFactories linked to the Risk type. - Use Lyo to List Available Factories: Run a quick snippet to print all creation factories for your service provider—this will show you the exact URIs you need:
ServiceProvider serviceProvider = client.getServiceProvider(serviceProviderUrl); for (CreationFactory factory : serviceProvider.getCreationFactories()) { System.out.println("Resource Type: " + factory.getResourceType()); System.out.println("RDF Type: " + factory.getRdfType()); // Look for entries that match your Risk work item type }
Step 2: Fetch the Risk CreationFactory
Once you have the correct RDF type and resource type, update your lookupCreationFactoryResource call to target Risk instead of Task/Defect:
// Replace these with the actual URIs you found in Step 1 String riskRdfType = "http://jazz.net/ns/your-custom-namespace#Risk"; String riskResourceType = "http://open-services.net/ns/cm#risk"; // Or your custom resource type URI CreationFactory riskCreation = client.lookupCreationFactoryResource( serviceProviderUrl, OSLCConstants.OSLC_CM_V2, riskRdfType, riskResourceType );
Step 3: Configure the Risk Work Item
Create a ChangeRequest instance (RTC's Risk type is typically an extension of ChangeRequest) and set all required properties like title, description, and project area:
ChangeRequest risk = new ChangeRequest(); risk.setTitle("Third-Party Dependency Risk"); risk.setDescription("Critical external dependency lacks a fallback plan"); // Set your project area URI (find this in RTC's project area settings) risk.setProject(new URI("https://your-rtc-server/ccm/process/project-areas/your-project-area-id")); // If your Risk has custom fields, set them using extended properties: risk.setExtendedProperty(new URI("http://your-custom-uri/risk-severity"), "High");
Step 4: Create the Risk Work Item
Finally, use the Risk CreationFactory to submit the work item to RTC:
ChangeRequest createdRisk = client.createResource( riskCreation.getCreationURI(), risk, ChangeRequest.class ); // Verify success by checking the returned URI System.out.println("Successfully created Risk: " + createdRisk.getAbout());
Key Notes to Remember
- Make sure your RTC project area has the Risk work item type enabled, and your API user has permission to create Risk items.
- If you hit 404 or permission errors, double-check the URIs for the Risk type and project area—typos here are a common pitfall.
内容的提问来源于stack exchange,提问作者joseph

