Ejemplo n.º 1
0
        public HttpResponseMessage <bool> UpdateWorkflow(long id, [FromBody] EC.EntityNugget entityNugget)
        {
            using (Profiler.Measure("WorkflowController.UpdateWorkflow"))
            {
                HttpResponseMessage <bool> result = null;

                DatabaseContext.RunWithRetry(() =>
                {
                    Action updateAction = () =>
                    {
                        MDL.IEntity updatedEntity = EC.EntityNugget.DecodeEntity(entityNugget, true);

                        var wf = updatedEntity.As <MDL.Workflow>();

                        if (updatedEntity == null)
                        {
                            throw new WebArgumentException("Workflow update does not contain data");
                        }

                        if (updatedEntity.Id != id)
                        {
                            throw new WebArgumentException("Request and nugget ids do not match");
                        }


                        updatedEntity.Save();
                    };

                    bool isCloned = WorkflowUpdateHelper.Update(id, updateAction);

                    result = new HttpResponseMessage <bool>(isCloned);
                });

                return(result);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Applies report settings to the structured query and also builds an appropriate query settings object.
        /// </summary>
        /// <param name="structuredQuery"></param>
        /// <param name="queryReportSettings"></param>
        /// <returns></returns>
        private static PreparedQuery PrepareReportRun(StructuredQuery structuredQuery, ReportSettings queryReportSettings)
        {
            QuerySettings querySettings;

            // Build the query engine settings
            bool secureReports;

            if (!_cachedSecureReports.HasValue)
            {
                DatabaseConfiguration dbConfiguration;
                dbConfiguration = ConfigurationSettings.GetDatabaseConfigurationSection( );
                if (dbConfiguration != null)
                {
                    _cachedSecureReports = dbConfiguration.ConnectionSettings.SecureReports;
                }
            }

            secureReports = _cachedSecureReports.Value;

            // Set the time zone for the report
            if (queryReportSettings.Timezone != null)
            {
                structuredQuery.TimeZoneName = queryReportSettings.Timezone.StandardName;
            }

            // Update the query engine settings
            querySettings = new QuerySettings
            {
                SecureQuery             = secureReports,
                SupportPaging           = queryReportSettings.SupportPaging,
                FirstRow                = queryReportSettings.InitialRow,
                PageSize                = queryReportSettings.PageSize,
                QuickSearchTerm         = queryReportSettings.QuickSearch,
                SupportQuickSearch      = !string.IsNullOrWhiteSpace(queryReportSettings.QuickSearch),
                FullAggregateClustering = true,
                RefreshCachedResult     = queryReportSettings.RefreshCachedResult,
                RefreshCachedSql        = queryReportSettings.RefreshCachedSql,
                CpuLimitSeconds         = queryReportSettings.CpuLimitSeconds
            };

            if (queryReportSettings.ReportOnType.HasValue)
            {
                Model.IEntity typeEntity = Model.Entity.Get <Model.EntityType>(queryReportSettings.ReportOnType);
                if (typeEntity == null)
                {
                    throw new WebArgumentException("Not a valid type");
                }

                (( ResourceEntity )structuredQuery.RootEntity).EntityTypeId = queryReportSettings.ReportOnType.Value;
            }

            if (queryReportSettings.ReportParameters != null)
            {
                // Apply any filters for analyser
                if (queryReportSettings.ReportParameters.AnalyserConditions != null &&
                    queryReportSettings.ReportParameters.AnalyserConditions.Count > 0)
                {
                    ApplyAnalyserConditions(structuredQuery, queryReportSettings.ReportParameters.AnalyserConditions);
                }
                // Apply any filters for sorting
                if (queryReportSettings.ReportParameters.SortColumns != null)
                {
                    ApplySortOrder(structuredQuery, queryReportSettings.ReportParameters.SortColumns);
                }
                // Determine if main row report is to be ignored
                querySettings.ResultSchemaOnly = queryReportSettings.ReportParameters.GroupAggregateRules != null && queryReportSettings.ReportParameters.GroupAggregateRules.IgnoreRows;
            }

            if (queryReportSettings.ReportRelationship != null)
            {
                ApplyRelatedResourceCondition(structuredQuery, queryReportSettings.ReportRelationship, querySettings);
            }

            if (queryReportSettings.RelatedEntityFilters != null)
            {
                ApplyRelatedEntityFilters(structuredQuery, queryReportSettings.RelatedEntityFilters);
            }

            if (queryReportSettings.FilteredEntityIdentifiers != null &&
                queryReportSettings.FilteredEntityIdentifiers.Count > 0)
            {
                ApplyFilteredEntityIdentifiers(structuredQuery, queryReportSettings.FilteredEntityIdentifiers);
            }

            PreparedQuery preparedQuery = new PreparedQuery
            {
                QuerySettings   = querySettings,
                StructuredQuery = structuredQuery
            };

            return(preparedQuery);
        }
Ejemplo n.º 3
0
        private SecurityTestData SetupSecurityTest(IEnumerable <Tuple <string, string> > nameAndDescription)
        {
            var testData = new SecurityTestData();

            // Create entity type
            var entityType = EntityModel.Entity.Create <EntityModel.EntityType>();

            entityType.Name = "TestType";
            entityType.Inherits.Add(EntityModel.Entity.Get <EntityModel.EntityType>("core:userResource"));
            entityType.Save();

            testData.EntityType = entityType;

            // Create entity instances
            foreach (var nameDesc in nameAndDescription)
            {
                EntityModel.IEntity entity = EntityModel.Entity.Create(entityType);
                entity.SetField("core:name", nameDesc.Item1);
                entity.SetField("core:description", nameDesc.Item2);

                entity.Save();

                testData.EntityInstances.Add(entity);
            }

            // Create query
            Guid resourceGuid    = Guid.NewGuid();
            var  structuredQuery = new StructuredQuery
            {
                RootEntity = new ResourceEntity
                {
                    EntityTypeId = entityType.Id,
                    ExactType    = false,
                    NodeId       = resourceGuid
                },
                SelectColumns = new List <SelectColumn>()
            };

            structuredQuery.SelectColumns.Add(new SelectColumn
            {
                Expression = new IdExpression {
                    NodeId = resourceGuid
                }
            });
            structuredQuery.SelectColumns.Add(new SelectColumn
            {
                Expression = new ResourceDataColumn
                {
                    NodeId  = resourceGuid,
                    FieldId = EntityModel.Entity.GetId("core:name")
                }
            });
            structuredQuery.SelectColumns.Add(new SelectColumn
            {
                Expression = new ResourceDataColumn
                {
                    NodeId  = resourceGuid,
                    FieldId = EntityModel.Entity.GetId("core:description")
                }
            });

            // Create report
            var report = ReportToEntityModelHelper.ConvertToEntity(structuredQuery);

            report.Save();
            testData.Report = report;

            // Create user
            var userAccount = new EntityModel.UserAccount();

            userAccount.Save();
            testData.UserAccount = userAccount;

            return(testData);
        }