Ejemplo n.º 1
0
        // Return if the workitem is updated (saved) by the handling code.
        public void handleEvent(
            Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItem workItem,
            String user,
            WorkItemChangedEvent notification)
        {
            Status status = new Status();

            // If the user is the OSLC Provider functional user we will only update status
            // message if so needed. This as changes from the OSLC Provider originates from
            // external source = currently: MHWeb. Need revisit to allow multiple clients.
            String aboutStr = AttributesMapper.GetTfsValueForEcrKey(TFSMapper.ECM_ABOUT, workItem);

            if (!user.Equals(HandlerSettings.TFSProviderUser, StringComparison.OrdinalIgnoreCase))
            {
                if (aboutStr.Length == 0)
                {
                    // We do not have a linked TR, we need to create
                    createTR(workItem, notification, user, ref status);
                }
                else
                {
                    Uri    about        = new Uri(aboutStr);
                    Status statusAssign = null;

                    EnterpriseChangeRequest ecr        = ECRMapper.mapFromWorkitem(workItem, about, ECRMapper.ACTION_ASSIGN);
                    TeamFoundationIdentity  assignedTo = HandlerSettings.GetSignumForAssignedTo(workItem);
                    if (user != null && assignedTo != null && !user.Equals(HandlerSettings.GetUserFromSignum(assignedTo.UniqueName), StringComparison.OrdinalIgnoreCase))
                    {
                        statusAssign = new Status();
                        ecr.SetOwner(user);
                        callUpdateTR(ecr, user, ECRMapper.TR_STATE_ASSIGNED_S, ref statusAssign);
                    }

                    // We have a TR linked which might need to be updated
                    updateTR(workItem, notification, user, about, ref status);

                    if (statusAssign != null && statusAssign.OK)
                    {
                        ecr.SetOwner(HandlerSettings.GetUserFromSignum(assignedTo.UniqueName));
                        callUpdateTR(ecr, user, ECRMapper.TR_STATE_ASSIGNED_S, ref statusAssign);
                    }
                }
            }

            // Handle update of Bug
            ECRMapper.updateBug(status, user, workItem);
        }
Ejemplo n.º 2
0
        // Return an EnterpriseChangeRequest with mapped values needed for the state transiton
        // If there is a fail with mapping some values, this will be captured in event log.
        // TODO: This could likely be described in a xml mapping file for configuration
        public static EnterpriseChangeRequest mapFromWorkitem(
            Microsoft.TeamFoundation.WorkItemTracking.Client.WorkItem workItem,
            Uri about,
            String action)
        {
            EnterpriseChangeRequest newEcr = new EnterpriseChangeRequest();

            newEcr.SetAbout(about);

            // Create a mapped ECR based on suggested action

            switch (action)
            {
            case ACTION_CREATE:
                newEcr.SetTitle(AttributesMapper.GetTfsValueForEcrKey(TFSMapper.ECM_TITLE, workItem));
                newEcr.SetDescription(AttributesMapper.GetTfsValueForEcrKey(TFSMapper.ECM_DESCRIPTION, workItem));
                newEcr.SetCurrentMho(AttributesMapper.GetTfsValueForEcrKey(TFSMapper.ECM_CURRENT_MHO, workItem));
                newEcr.SetCustomer(AttributesMapper.GetTfsValueForEcrKey(TFSMapper.ECM_CUSTOMER, workItem));
                newEcr.SetProduct(AttributesMapper.GetTfsValueForEcrKey(TFSMapper.ECM_PRODUCT, workItem));
                newEcr.SetProductRevision(AttributesMapper.GetTfsValueForEcrKey(TFSMapper.ECM_PRODUCT_REVISION, workItem));
                newEcr.SetNodeProduct(AttributesMapper.GetTfsValueForEcrKey(TFSMapper.ECM_NODE_PRODUCT, workItem));
                newEcr.SetNodeProductRevision(AttributesMapper.GetTfsValueForEcrKey(TFSMapper.ECM_NODE_PRODUCT_REVISION, workItem));

                // Note: The field firstTechnicalContact also is needed for TR creation. This we retrieve from
                // the user in the create notification, and put in the REST call header as required by MHWeb.
                // Formally we have mapping specified in ERICSSON_DEFECT_CREATOR_SIGNUM, but not used.

                // Add the connected Bug as related link
                Uri    relatedBug             = new Uri(HandlerSettings.GetUriForBug(workItem.Id.ToString()));
                String label                  = workItem.Id.ToString() + ": " + workItem.Title;
                OSLC4Net.Core.Model.Link link = new OSLC4Net.Core.Model.Link(relatedBug, label);
                newEcr.AddRelatedChangeRequest(link);

                break;

            case ACTION_REGISTER_ROUTE:
                newEcr.SetAction(ACTION_REGISTER_ROUTE);
                newEcr.SetImpactOnISP(AttributesMapper.GetTfsValueForEcrKey(TFSMapper.ECM_IMPACT_ON_ISP, workItem));
                newEcr.SetPriority(AttributesMapper.GetTfsValueForEcrKey(TFSMapper.ECM_PRIORITY, workItem));
                newEcr.SetDiddet(AttributesMapper.GetTfsValueForEcrKey(TFSMapper.ECM_DIDDET, workItem));
                newEcr.SetActivity(AttributesMapper.GetTfsValueForEcrKey(TFSMapper.ECM_ACTIVITY, workItem));
                newEcr.SetFirstTechContactInfo(AttributesMapper.GetTfsValueForEcrKey(TFSMapper.ECM_FIRST_TECHNICAL_CONTACT_INFO, workItem));
                newEcr.SetCountry(AttributesMapper.GetTfsValueForEcrKey(TFSMapper.ECM_COUNTRY, workItem));
                newEcr.SetSite(AttributesMapper.GetTfsValueForEcrKey(TFSMapper.ECM_SITE, workItem));

                break;

            case ACTION_ASSIGN:
                newEcr.SetAction(ACTION_ASSIGN);
                newEcr.SetOwner(AttributesMapper.GetTfsValueForEcrKey(TFSMapper.ECM_OWNER, workItem));
                break;

            case ACTION_PROPOSE:
                newEcr.SetAction(ACTION_PROPOSE);
                newEcr.SetDiddet(AttributesMapper.GetTfsValueForEcrKey(TFSMapper.ECM_DIDDET, workItem));
                newEcr.SetActivity(AttributesMapper.GetTfsValueForEcrKey(TFSMapper.ECM_ACTIVITY, workItem));
                newEcr.SetFirstTechContactInfo(AttributesMapper.GetTfsValueForEcrKey(TFSMapper.ECM_FIRST_TECHNICAL_CONTACT_INFO, workItem));
                newEcr.SetExpectedImpactOnISP(AttributesMapper.GetTfsValueForEcrKey(TFSMapper.ECM_EXPECTED_IMPACT_ON_ISP, workItem));
                newEcr.SetAnswer(AttributesMapper.GetTfsValueForEcrKey(TFSMapper.ECM_ANSWER, workItem));
                newEcr.SetFaultCode(AttributesMapper.GetTfsValueForEcrKey(TFSMapper.ECM_FAULTCODE, workItem));
                newEcr.SetAnswerCode(AttributesMapper.GetTfsValueForEcrKey(TFSMapper.ECM_ANSWER_CODE, workItem));

                // Corrected Product info is mandatory for some  answerCodes and optional for others. Here
                // we pass in all cases and let the bug.xml handle mandatoryness and mhweb complain if not
                // present.

                newEcr.SetCorrectedProduct(
                    AttributesMapper.GetTfsValueForEcrKey(TFSMapper.ECM_CORRECTED_PRODUCT, workItem));
                newEcr.SetCorrectedProductRevision(
                    AttributesMapper.GetTfsValueForEcrKey(TFSMapper.ECM_CORRECTED_PRODUCT_REVISION, workItem));
                newEcr.SetCorrectedNodeProduct(
                    AttributesMapper.GetTfsValueForEcrKey(TFSMapper.ECM_CORRECTED_NODE_PRODUCT, workItem));
                newEcr.SetCorrectedNodeProductRevision(
                    AttributesMapper.GetTfsValueForEcrKey(TFSMapper.ECM_CORRECTED_NODE_PRODUCT_REVISION, workItem));
                break;

            case ACTION_APPROVE:
                newEcr.SetAction(ACTION_APPROVE);
                break;

            case ACTION_VERIFY:
                newEcr.SetAction(ACTION_VERIFY);
                newEcr.SetCorrectedNodeProduct(
                    AttributesMapper.GetTfsValueForEcrKey(TFSMapper.ECM_CORRECTED_NODE_PRODUCT, workItem));
                newEcr.SetCorrectedNodeProductRevision(
                    AttributesMapper.GetTfsValueForEcrKey(TFSMapper.ECM_CORRECTED_NODE_PRODUCT_REVISION, workItem));
                break;

            case ACTION_ANSWER:
                newEcr.SetAction(ACTION_ANSWER);
                newEcr.SetCorrectedNodeProduct(
                    AttributesMapper.GetTfsValueForEcrKey(TFSMapper.ECM_CORRECTED_NODE_PRODUCT, workItem));
                newEcr.SetCorrectedNodeProductRevision(
                    AttributesMapper.GetTfsValueForEcrKey(TFSMapper.ECM_CORRECTED_NODE_PRODUCT_REVISION, workItem));
                break;

            case ACTION_ACCEPT:
                newEcr.SetAction(ACTION_ACCEPT);
                break;

            case ACTION_REJECT:
                newEcr.SetAction(ACTION_REJECT);
                newEcr.SetNotebook(AttributesMapper.GetTfsValueForEcrKey(TFSMapper.ECM_NOTEBOOK, workItem));
                break;

            case ACTION_DUPLICATE:
                newEcr.SetAction(ACTION_DUPLICATE);
                newEcr.SetPrimaryTR(AttributesMapper.GetTfsValueForEcrKey(TFSMapper.ECM_PRIMARYTR, workItem));
                break;

            case ACTION_UNDUPLICATE:
                newEcr.SetAction(ACTION_UNDUPLICATE);
                break;

            case ACTION_CHANGE_PRODUCT:
                newEcr.SetAction(ACTION_CHANGE_PRODUCT);
                newEcr.SetProduct(AttributesMapper.GetTfsValueForEcrKey(TFSMapper.ECM_PRODUCT, workItem));
                newEcr.SetProductRevision(AttributesMapper.GetTfsValueForEcrKey(TFSMapper.ECM_PRODUCT_REVISION, workItem));
                newEcr.SetNodeProduct(AttributesMapper.GetTfsValueForEcrKey(TFSMapper.ECM_NODE_PRODUCT, workItem));
                newEcr.SetNodeProductRevision(AttributesMapper.GetTfsValueForEcrKey(TFSMapper.ECM_NODE_PRODUCT_REVISION, workItem));
                break;

            case ACTION_REACTIVATE:
                newEcr.SetAction(ACTION_REACTIVATE);
                break;

            case ACTION_FINISH:
                newEcr.SetAction(ACTION_FINISH);
                break;

            case ACTION_DISCONNECT:
                newEcr.SetAction(ACTION_DISCONNECT);
                break;
            }

            return(newEcr);
        }