Пример #1
0
        protected ChangeRequest MakeChangeRequest(String mediaType)
        {
            CREATED_CHANGE_REQUEST_URI = null;

            ChangeRequest changeRequest = new ChangeRequest();

            changeRequest.AddContributor(new Uri("http://myserver/mycmapp/users/bob"));
            changeRequest.AddCreator(new Uri("http://myserver/mycmapp/users/bob"));
            changeRequest.AddDctermsType(ChangeManagement.Type.Defect.ToString());
            changeRequest.SetDescription("Invalid installation instructions indicating invalid patches to be applied.");
            changeRequest.SetDiscussedBy(new Uri("http://example.com/bugs/2314/discussion"));
            changeRequest.SetInstanceShape(new Uri("http://example.com/shapes/defect"));
            changeRequest.AddRelatedChangeRequest(new Link(new Uri("http://myserver/mycmapp/bugs/1235"), "Bug 1235"));
            changeRequest.SetSeverity(Severity.Major.ToString());
            changeRequest.SetShortTitle("Bug 2314");
            changeRequest.SetStatus("InProgress");
            changeRequest.AddSubject("doc");
            changeRequest.AddSubject("install");
            changeRequest.SetTitle("Invalid installation instructions");
            changeRequest.AddTracksRequirement(new Link(new Uri("http://myserver/reqtool/req/34ef31af")));
            changeRequest.AddTracksRequirement(new Link(new Uri("http://remoteserver/reqrepo/project1/req456"), "Requirement 456"));

            String creation = GetCreation(mediaType, Constants.TYPE_CHANGE_REQUEST);

            OslcRestClient oslcRestClient = new OslcRestClient(FORMATTERS,
                                                               creation,
                                                               mediaType);

            ChangeRequest addedChangeRequest = oslcRestClient.AddOslcResource(changeRequest);

            CREATED_CHANGE_REQUEST_URI = addedChangeRequest.GetAbout();

            return(addedChangeRequest);
        }
Пример #2
0
        /// <summary>
        /// Login to the RTC server and perform some OSLC actions
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            log4net.Config.XmlConfigurator.Configure();

            CommandLineDictionary cmd = CommandLineDictionary.FromArguments(args);

            if (!ValidateOptions(cmd))
            {
                logger.Error("Syntax:  /url=https://<server>:port/<context>/ /user=<user> /password=<password> /project=\"<project_area>\"");
                logger.Error("Example: /url=https://exmple.com:9443/ccm /user=ADMIN /password=ADMIN /project=\"JKE Banking (Change Management)\"");
                return;
            }

            String webContextUrl = cmd["url"];
            String user          = cmd["user"];
            String passwd        = cmd["password"];
            String projectArea   = cmd["project"];

            try {
                //STEP 1: Initialize a Jazz rootservices helper and indicate we're looking for the ChangeManagement catalog
                //RTC contains a service provider for CM and SCM, so we need to indicate our interest in CM
                JazzRootServicesHelper helper = new JazzRootServicesHelper(webContextUrl, OSLCConstants.OSLC_CM_V2);

                //STEP 2: Create a new Form Auth client with the supplied user/password
                JazzFormAuthClient client = helper.InitFormClient(user, passwd);

                //STEP 3: Login in to Jazz Server
                if (client.FormLogin() == HttpStatusCode.OK)
                {
                    //STEP 4: Get the URL of the OSLC ChangeManagement catalog
                    String catalogUrl = helper.GetCatalogUrl();

                    //STEP 5: Find the OSLC Service Provider for the project area we want to work with
                    String serviceProviderUrl = client.LookupServiceProviderUrl(catalogUrl, projectArea);

                    //STEP 6: Get the Query Capabilities URL so that we can run some OSLC queries
                    String queryCapability = client.LookupQueryCapability(serviceProviderUrl,
                                                                          OSLCConstants.OSLC_CM_V2,
                                                                          OSLCConstants.CM_CHANGE_REQUEST_TYPE);

                    //SCENARIO A: Run a query for all open ChangeRequests with OSLC paging of 10 items per
                    //page turned on and list the members of the result
                    OslcQueryParameters queryParams = new OslcQueryParameters();
                    queryParams.SetWhere("oslc_cm:closed=false");
                    queryParams.SetSelect("dcterms:identifier,dcterms:title,oslc_cm:status");
                    OslcQuery query = new OslcQuery(client, queryCapability, 10, queryParams);

                    OslcQueryResult result = query.Submit();

                    bool processAsJavaObjects = true;
                    ProcessPagedQueryResults(result, client, processAsJavaObjects);

                    Console.WriteLine("\n------------------------------\n");

                    //SCENARIO B:  Run a query for a specific ChangeRequest selecting only certain
                    //attributes and then print it as raw XML.  Change the dcterms:identifier below to match a
                    //real workitem in your RTC project area
                    OslcQueryParameters queryParams2 = new OslcQueryParameters();
                    queryParams2.SetWhere("dcterms:identifier=\"10\"");
                    queryParams2.SetSelect("dcterms:identifier,dcterms:title,dcterms:creator,dcterms:created,oslc_cm:status");
                    OslcQuery query2 = new OslcQuery(client, queryCapability, queryParams2);

                    OslcQueryResult     result2     = query2.Submit();
                    HttpResponseMessage rawResponse = result2.GetRawResponse();
                    ProcessRawResponse(rawResponse);
                    rawResponse.ConsumeContent();

                    //SCENARIO C:  RTC Workitem creation and update
                    ChangeRequest changeRequest = new ChangeRequest();
                    changeRequest.SetTitle("Implement accessibility in Pet Store application");
                    changeRequest.SetDescription("Image elements must provide a description in the 'alt' attribute for consumption by screen readers.");
                    changeRequest.AddTestedByTestCase(new Link(new Uri("http://qmprovider/testcase/1"), "Accessibility verification using a screen reader"));
                    changeRequest.AddDctermsType("task");

                    //Get the Creation Factory URL for change requests so that we can create one
                    String changeRequestCreation = client.LookupCreationFactory(
                        serviceProviderUrl, OSLCConstants.OSLC_CM_V2,
                        changeRequest.GetRdfTypes()[0].ToString());

                    //Create the change request
                    HttpResponseMessage creationResponse = client.CreateResource(
                        changeRequestCreation, changeRequest,
                        OslcMediaType.APPLICATION_RDF_XML,
                        OslcMediaType.APPLICATION_RDF_XML);

                    if (creationResponse.StatusCode != HttpStatusCode.Created)
                    {
                        String errorString = creationResponse.Content.ReadAsStringAsync().Result;
                        Console.Error.WriteLine("Failed to create change request: " + errorString);
                        return;
                    }

                    String changeRequestLocation = creationResponse.Headers.Location.ToString();
                    creationResponse.ConsumeContent();
                    Console.WriteLine("Change Request created a location " + changeRequestLocation);


                    //Get the change request from the service provider and update its title property
                    changeRequest = client.GetResource(changeRequestLocation,
                                                       OslcMediaType.APPLICATION_RDF_XML).Content.ReadAsAsync <ChangeRequest>(client.GetFormatters()).Result;
                    changeRequest.SetTitle(changeRequest.GetTitle() + " (updated)");

                    //Create a partial update URL so that only the title will be updated.
                    //Assuming (for readability) that the change request URL does not already contain a '?'
                    String updateUrl = changeRequest.GetAbout() + "?oslc.properties=dcterms:title";

                    //Update the change request at the service provider
                    HttpResponseMessage updateResponse = client.UpdateResource(
                        updateUrl, changeRequest,
                        OslcMediaType.APPLICATION_RDF_XML,
                        OslcMediaType.APPLICATION_RDF_XML);

                    updateResponse.ConsumeContent();
                }
            } catch (RootServicesException re) {
                logger.Error("Unable to access the Jazz rootservices document at: " + webContextUrl + "/rootservices", re);
            } catch (Exception e) {
                logger.Error(e.Message, e);
            }
        }