Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

Creation of Artifact programmatically in a Project Area

I need to create an Artifact and set the Attributes programmatically (both) in a Project Area.

Any library to do so.

Please let me know

Thanks
Vaibhav

0 votes



One answer

Permanent link

I created the below code to accomplish the task. PFB the code:


String rtcURL = "https://*****";

        String user = "**";
        String pass = "***";

        JazzRootServicesHelper helper = new JazzRootServicesHelper(rtcURL, OSLCConstants.OSLC_RM_V2);

        JazzFormAuthClient client = helper.initFormClient(user, pass, "https://
***");

        if (client.formLogin() == 200)
            System.out.println("Login SUCCESS!");

        String catalogUrl = helper.getCatalogUrl();

        String serviceProviderUrl = client.lookupServiceProviderUrl(catalogUrl, "TestProjectFromOSLCCode");

        String requirementFactory = client.lookupCreationFactory(serviceProviderUrl, OSLCConstants.OSLC_RM_V2,
                OSLCConstants.RM_REQUIREMENT_TYPE);

         URI uri = new URI("https://
****
");

        // ******

        ResourceShape featureInstanceShape = RmUtil.lookupRequirementsInstanceShapes(serviceProviderUrl,
                OSLCConstants.OSLC_RM_V2, OSLCConstants.RM_REQUIREMENT_TYPE, client, "Requirement");
   
        //
******

        Requirement requirement = new Requirement();
        requirement.setInstanceShape(featureInstanceShape.getAbout());
        requirement.setTitle("Test Artifact Using Code001");
        requirement.setDescription("Test Artifact Using Code");
        requirement.setServiceProvider(uri);

        String primaryText = "Test Primary Text";
        org.w3c.dom.Element obj = RmUtil.convertStringToHTML(primaryText);

        requirement.getExtendedProperties().put(RmConstants.PROPERTY_PRIMARY_TEXT, obj);

        ClientResponse response = client.createResource(requirementFactory, requirement,
                OslcMediaType.APPLICATION_RDF_XML, OslcMediaType.APPLICATION_RDF_XML);
          if (response.getStatusCode() == HttpStatus.SC_OK) {
            System.out.println("Success");
        }




Thanks
Vaibhav

0 votes

Your answer

Register or log in 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 1,221

Question asked: Mar 24 '17, 6:28 a.m.

Question was seen: 3,085 times

Last updated: Mar 31 '17, 1:18 a.m.

Confirmation Cancel Confirm