It's all about the answers!

Ask a question

Creation of Artifact programmatically in a Project Area


Vaibhav S (106247) | asked Mar 24 '17, 6:28 a.m.
edited Mar 24 '17, 6:29 a.m.

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

One answer



permanent link
Vaibhav S (106247) | answered Mar 28 '17, 7:47 a.m.
edited Mar 31 '17, 1:18 a.m.

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

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.