Пример #1
0
        /// <summary>
        /// Gets a value indicating whether the given result should be included in the results display.
        /// Each valid search result is passed into this method.
        /// </summary>
        /// <param name="node">The node representing the search result.</param>
        /// <returns>Return <c>true</c> to keep the search result; return <c>false</c> to
        /// hide the search result.</returns>
        public bool ShouldItemBeListed(RepositoryItemNode node)
        {
            // Don't show any search results tha start with the letter "B".
            if (node.Header.StartsWith("B"))
            {
                return(false);
            }

            return(true);
        }
        /// <summary>
        /// Gets a value indicating whether the given result should be included in the results display.
        /// Each valid search result is passed into this method.
        /// </summary>
        /// <param name="node">The node representing the search result.</param>
        /// <returns>Return <c>true</c> to keep the search result; return <c>false</c> to 
        /// hide the search result.</returns>
        public bool ShouldItemBeListed(RepositoryItemNode node)
        {
            // Don't show any search results tha start with the letter "B".
            if (node.Header.StartsWith("B"))
            {
                return false;
            }

            return true;
        }
Пример #3
0
        public static string CreateOrUpdatePhysicalInstanceForFile <TImporter>(Guid fileId, string filePath, string agencyId, PhysicalInstance existingPhysicalInstance)
            where TImporter : IDataImporter, new()
        {
            var logger = LogManager.GetLogger("Curation");

            logger.Debug("File import: " + fileId);

            IDataImporter    importer         = new TImporter();
            var              client           = RepositoryHelper.GetClient();
            PhysicalInstance physicalInstance = existingPhysicalInstance;

            // For PhysicalInstances that do not exist yet, create from scratch.
            if (physicalInstance == null)
            {
                // Extract metadata.
                ResourcePackage rp = importer.Import(filePath, agencyId);
                logger.Debug("Imported metadata from data file.");

                if (rp.PhysicalInstances.Count == 0)
                {
                    logger.Debug("No dataset could be extracted from SPSS");
                    return(string.Empty);
                }

                physicalInstance            = rp.PhysicalInstances[0];
                physicalInstance.Identifier = fileId;
            }
            else
            {
                // If there is an existing PhysicalInstance, update it from the data file.
                var updateCommand = new UpdatePhysicalInstanceFromFile();
                updateCommand.DataImporters = new List <IDataImporter>();
                updateCommand.DataImporters.Add(new SpssImporter());
                updateCommand.DataImporters.Add(new StataImporter());
                updateCommand.DataImporters.Add(new SasImporter());
                updateCommand.DataImporters.Add(new RDataImporter());
                updateCommand.DataImporters.Add(new CsvImporter());


                var context = new Algenta.Colectica.ViewModel.Commands.VersionableCommandContext();

                // Update the PhysicalInstance from the data file.
                var repoNode     = new RepositoryNode(client, null);
                var repoItemNode = new RepositoryItemNode(existingPhysicalInstance.GetMetadata(), repoNode, client);
                context.Node = repoItemNode;
                context.Item = physicalInstance;

                try
                {
                    updateCommand.Execute(context);

                    physicalInstance.Version++;
                    foreach (var item in updateCommand.Result.ModifiedItems)
                    {
                        item.Version++;
                    }
                }
                catch (Exception ex)
                {
                    logger.Error("Problem updating PhysicalInstance.", ex);
                    return("Problem updating PhysicalInstance. " + ex.Message);
                }
            }

            // Calculate summary statistics, for both new and updated files.
            try
            {
                logger.Debug("Calculating summary statistics");
                var calculator = new PhysicalInstanceSummaryStatisticComputer();
                SummaryStatisticsOptions options = new SummaryStatisticsOptions()
                {
                    CalculateQuartiles = true
                };
                var stats = calculator.ComputeStatistics(importer, filePath, physicalInstance,
                                                         physicalInstance.FileStructure.CaseQuantity, options, (percent, message) => { });
                logger.Debug("Done calculating summary statistics");

                if (stats != null)
                {
                    physicalInstance.Statistics.Clear();
                    foreach (VariableStatistic stat in stats)
                    {
                        physicalInstance.Statistics.Add(stat);
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error("Problem calculating summary statistics.", ex);
                return("Problem calculating summary statistics. " + ex.Message);
            }


            // Register all items that were created with the repository.
            DirtyItemGatherer visitor = new DirtyItemGatherer(false, true);

            physicalInstance.Accept(visitor);

            logger.Debug("Setting agency IDs");

            // The static default agency id is not thread safe, so set it explicitly here
            foreach (var item in visitor.DirtyItems)
            {
                item.AgencyId = agencyId;
            }

            logger.Debug("Done setting agency IDs");
            logger.Debug("Registering items with the repository");

            var repoOptions = new Algenta.Colectica.Model.Repository.CommitOptions();

            repoOptions.NamedOptions.Add("RegisterOrReplace");
            client.RegisterItems(visitor.DirtyItems, repoOptions);

            logger.Debug("Done registering items with the repository");
            logger.Debug("Done with CreatePhysicalInstanceForFile");

            return(string.Empty);
        }