public async Task <IHttpActionResult> Configure(ActivityDTO curActionDesignDTO, [FromUri] bool force = false)
        {
            ActivityDO curActivityDO = Mapper.Map <ActivityDO>(curActionDesignDTO);
            var        userId        = User.Identity.GetUserId();

            using (var uow = _uowFactory.Create())
            {
                if (_planService.IsPlanActiveOrExecuting(curActionDesignDTO.Id) && !force)
                {
                    return(new LockedHttpActionResult());
                }
                var configuredActivity = await _activityService.Configure(uow, userId, curActivityDO);

                return(Ok(configuredActivity));
            }
        }
Exemplo n.º 2
0
 public Task <ActivityDTO> Configure(IUnitOfWork uow, string userId, ActivityDO curActivityDO)
 {
     return(_activity.Configure(uow, userId, curActivityDO));
 }
Exemplo n.º 3
0
        public async Task <PlanNoChildrenDTO> CreateFromTemplate(PlanDTO plan, string userId)
        {
            var planDo = new PlanDO()
            {
                Category     = plan.Category,
                CreateDate   = DateTimeOffset.Now,
                Fr8AccountId = userId,
                Id           = Guid.NewGuid(),
                PlanState    = PlanState.Inactive,
                Description  = plan.Description,
                Name         = plan.Name,
                Visibility   = PlanVisibility.Standard,
            };

            var idsMap = new Dictionary <Guid, Guid>();

            idsMap[plan.Id] = planDo.Id;

            if (plan.SubPlans != null)
            {
                foreach (var fullSubplanDto in plan.SubPlans)
                {
                    var subplan = new SubplanDO(plan.StartingSubPlanId == fullSubplanDto.SubPlanId);

                    subplan.Id           = Guid.NewGuid();
                    subplan.Name         = fullSubplanDto.Name;
                    subplan.Fr8AccountId = userId;

                    if (fullSubplanDto.SubPlanId != null)
                    {
                        idsMap[fullSubplanDto.SubPlanId.Value] = subplan.Id;
                    }

                    planDo.AddChildWithDefaultOrdering(subplan);

                    if (fullSubplanDto.Activities != null)
                    {
                        foreach (var activityDto in fullSubplanDto.Activities)
                        {
                            var activity = AutoMapper.Mapper.Map <ActivityDO>(activityDto);

                            foreach (var descendant in activity.GetDescendants())
                            {
                                var oldId = descendant.Id;

                                descendant.Id = Guid.NewGuid();
                                idsMap[oldId] = descendant.Id;
                            }

                            subplan.AddChild(activity, activityDto.Ordering);
                        }
                    }
                }

                foreach (var activity in planDo.GetDescendants().OfType <ActivityDO>())
                {
                    ActivityTemplateDO activityTemplate;

                    if (!_activityTemplate.TryGetByKey(activity.ActivityTemplateId, out activityTemplate))
                    {
                        throw new KeyNotFoundException($"Activity '{activity.Id}' use activity template '{activity.ActivityTemplate?.Name}' with id = '{activity.ActivityTemplateId}' that is unknown to this Hub");
                    }

                    activity.CrateStorage = _crateManager.EmptyStorageAsStr(); //  UpdateCrateStorage(activity.CrateStorage, idsMap);
                }
            }

            using (var uow = _unitOfWorkFactory.Create())
            {
                uow.PlanRepository.Add(planDo);
                uow.SaveChanges();
            }

            var levels = new List <List <ActivityDO> >();

            CollectActivitiesByLevels(planDo, levels, 0);

            foreach (var level in levels)
            {
                await Task.WhenAll(level.Select(async x =>
                {
                    using (var uow = _unitOfWorkFactory.Create())
                    {
                        if (uow.PlanRepository.GetById <PlanNodeDO>(x.Id) == null)
                        {
                            return;
                        }

                        await _activityService.Configure(uow, userId, x);
                    }
                }));
            }

            using (var uow = _unitOfWorkFactory.Create())
            {
                return(AutoMapper.Mapper.Map <PlanNoChildrenDTO>(uow.PlanRepository.GetById <PlanDO>(planDo.Id)));
            }
        }
        private async Task ConfigureSaveJiraActivity(IUnitOfWork uow, Fr8AccountDO systemUser, ActivityTemplateDO[] activityTemplates, Guid planId)
        {
            var saveJiraTemplate = activityTemplates.FirstOrDefault(x => x.Name == "Save_Jira_Issue" && x.Version == "1" && x.Terminal.Name == "terminalAtlassian");

            if (saveJiraTemplate == null)
            {
                throw new ApplicationException("Save Jira Issue v1 activity template was not found in Atlassian terminal");
            }
            var saveJiraActivity = await _activity.CreateAndConfigure(uow, systemUser.Id, saveJiraTemplate.Id, saveJiraTemplate.Label, saveJiraTemplate.Label, 3, planId).ConfigureAwait(false) as ActivityDO;

            using (var storage = _crateManager.GetUpdatableStorage(saveJiraActivity))
            {
                var controls = storage.CrateContentsOfType <StandardConfigurationControlsCM>().SingleOrDefault();
                if (controls == null)
                {
                    throw new ApplicationException("Save Jira Issue doesn't contain controls crate");
                }
                var projectSelector = controls.FindByName <DropDownList>("AvailableProjects");
                if (projectSelector == null)
                {
                    throw new ApplicationException("Save Jira Issue doesn't contain project selector");
                }
                projectSelector.SelectByKey("fr8test");
            }
            saveJiraActivity = Mapper.Map <ActivityDO>(await _activity.Configure(uow, systemUser.Id, saveJiraActivity).ConfigureAwait(false));
            using (var storage = _crateManager.GetUpdatableStorage(saveJiraActivity))
            {
                var controls          = storage.CrateContentsOfType <StandardConfigurationControlsCM>().SingleOrDefault();
                var issueTypeSelector = controls.FindByName <DropDownList>("AvailableIssueTypes");
                if (issueTypeSelector == null)
                {
                    throw new ApplicationException("Save Jira Issue doesn't contain issue type selector");
                }
                issueTypeSelector.SelectByKey("Task");
            }
            saveJiraActivity = Mapper.Map <ActivityDO>(await _activity.Configure(uow, systemUser.Id, saveJiraActivity).ConfigureAwait(false));
            using (var storage = _crateManager.GetUpdatableStorage(saveJiraActivity))
            {
                var controls         = storage.CrateContentsOfType <StandardConfigurationControlsCM>().SingleOrDefault();
                var prioritySelector = controls.FindByName <DropDownList>("AvailablePriorities");
                if (prioritySelector == null)
                {
                    throw new ApplicationException("Save Jira Issue doesn't contain priority selector");
                }
                prioritySelector.SelectByKey("Normal");
                var assigneeSelector = controls.FindByName <DropDownList>("Asignee");
                if (assigneeSelector == null)
                {
                    throw new ApplicationException("Save Jira Issue doesn't contain asignee selector");
                }
                assigneeSelector.SelectByValue("admin");
                var summary = controls.FindByName <TextSource>("SummaryTextSource");
                if (summary == null)
                {
                    throw new ApplicationException("Save Jira Issue doesn't contain summary field");
                }
                summary.ValueSource = TextSource.SpecificValueSource;
                summary.TextValue   = "New Manifest Submission";
                var description = controls.FindByName <TextSource>("DescriptionTextSource");
                if (description == null)
                {
                    throw new ApplicationException("Save Jira Issue doesn't contain description field");
                }
                description.ValueSource  = TextSource.UpstreamValueSrouce;
                description.SelectedItem = new FieldDTO(MessageName);
                description.selectedKey  = MessageName;
            }
            await _activity.Configure(uow, systemUser.Id, saveJiraActivity).ConfigureAwait(false);
        }