public static List <RepositoryItemMetadata> GetAllRepositoryQuestions(string agency, Guid id, RepositoryClientBase client) { // Retrieves data for the selected study from the repository to be used in determining equivalences List <RepositoryItemMetadata> infoList = new List <RepositoryItemMetadata>(); MultilingualString.CurrentCulture = "en-GB"; //IVersionable item = client.GetLatestItem(id, agency, // ChildReferenceProcessing.Populate); IVersionable item = client.GetLatestItem(id, agency); var studyUnit = item as StudyUnit; SetSearchFacet setFacet = new SetSearchFacet(); setFacet.ItemTypes.Add(DdiItemType.QuestionItem); if (studyUnit == null) { return(infoList); } var matches = client.SearchTypedSet(studyUnit.CompositeId, setFacet); infoList = client.GetRepositoryItemDescriptions(matches.ToIdentifierCollection()).ToList(); return(infoList); }
public static QuestionModel GetAllQuestions(QuestionModel model, string agency, Guid id, string itemType) { MultilingualString.CurrentCulture = "en-GB"; var client = ClientHelper.GetClient(); IVersionable item = client.GetLatestItem(id, agency, ChildReferenceProcessing.Populate); var studyUnit = item as StudyUnit; //var studyModel = new List<RepositoryItemMetadata>(); //studyModel.StudyUnit = studyUnit; foreach (var qualityStatement in studyUnit.QualityStatements) { client.PopulateItem(qualityStatement); } // Use a set search to get a list of all questions that are referenced // by the study. A set search will return items that may be several steps // away. SetSearchFacet setFacet = new SetSearchFacet(); setFacet.ItemTypes.Add(DdiItemType.QuestionItem); var matches = client.SearchTypedSet(studyUnit.CompositeId, setFacet); var infoList = client.GetRepositoryItemDescriptions(matches.ToIdentifierCollection()); foreach (var info in infoList) { model.AllQuestions.Add(info); var references = Helper.GetReferences(info.AgencyId, info.Identifier); foreach (var reference in references) { if (itemType == "Variable") { if (reference.ItemType == new Guid("683889c6-f74b-4d5e-92ed-908c0a42bb2d")) { reference.ItemType = info.Identifier; model.AllVariables.Add(reference); } } if (reference.ItemType == new Guid("5cc915a1-23c9-4487-9613-779c62f8c205")) { reference.ItemType = info.Identifier; model.AllConcepts.Add(reference); } } } return(model); }
public int GetQuestionCount(string agency, Guid id) { MultilingualString.CurrentCulture = "en-US"; var client = ClientHelper.GetClient(); IVersionable item = client.GetLatestItem(id, agency, ChildReferenceProcessing.Populate); var studyUnit = item as StudyUnit; SetSearchFacet setFacet = new SetSearchFacet(); setFacet.ItemTypes.Add(DdiItemType.QuestionItem); var matches = client.SearchTypedSet(studyUnit.CompositeId, setFacet); var infoList = client.GetRepositoryItemDescriptions(matches.ToIdentifierCollection()); return(infoList.Count()); }
public static IdentifierTriple GetContainingPhysicalInstance(IdentifierTriple id, RepositoryClientBase client) { var facet = new SetSearchFacet(); facet.ItemTypes.Add(DdiItemType.PhysicalInstance); facet.ReverseTraversal = true; facet.LeafItemTypes.Add(DdiItemType.VariableScheme); facet.LeafItemTypes.Add(DdiItemType.VariableGroup); var response = client.SearchTypedSet(id, facet); var piID = response.OrderByDescending(x => x.Version).FirstOrDefault(); if (piID == null) { return(null); } return(piID.CompositeId); }
/// <summary> /// Counts the number of Categories with the same label that are /// found in a particular ResourcePackage in the Repository. /// For each unique category label, output the number of categories with that label. /// This is useful for determining whether harmonizing a repository's Category items /// would be a worthwhile effort. /// </summary> /// <remarks> /// This will provide output like this: /// Yes: 1 /// No: 1 /// Don't know: 12 /// Refused: 12 /// </remarks> public void CountUniqueCategoryLabels() { MultilingualString.CurrentCulture = "en-GB"; var client = RepositoryIntro.GetClient(); // To search within a certain set of items, we create a SetSearchFacet object. // We can set some properties on this object to tell the repository what // items we want to find. SetSearchFacet facet = new SetSearchFacet(); // Find all Category items. facet.ItemTypes.Add(DdiItemType.Category); // Search under the item with the provided identification. // This method returns a collection of identifiers of all matching items. var categoryIDs = client.SearchTypedSet( new IdentifierTriple(new Guid("e92ac0d9-9f2f-4891-9c42-75bfeafc6d23"), 3, "example.org"), facet); // The identifiers by themselves don't give us much information. // Ask the repository for descriptions of all the categories. // This is a very fast call, compared to retrieving the fully populated Category objects, // and it has the information we need: each category's name, label, and description. var categoryDescriptions = client.GetRepositoryItemDescriptions(categoryIDs.ToIdentifierCollection()); // Group the categories by label. The GroupBy method returns a list of lists, looking something like this: // "Yes" -> [cat1Desc, cat2Desc, cat3Desc] // "No" -> [cat4Desc, cat5Desc, cat6Desc] // ... var groupedCategories = categoryDescriptions.GroupBy(cat => cat.Label.Current); // For each unique category label, output the number of categories with that label. foreach (var group in groupedCategories.OrderBy(g => g.Count())) { Console.WriteLine(group.Key + ": " + group.Count().ToString()); } }
public void SetSearch() { var dataRelationshipIdentifier = new IdentifierTriple(new Guid(), 1, "int.example"); // Search for all Categories in the DataRelationship's set. var facet = new SetSearchFacet(); facet.ItemTypes.Add(DdiItemType.Category); var resultIdentifiers = client.SearchTypedSet( dataRelationshipIdentifier, facet); // The set search only returns the identifiers of items. // Request the description of each result here. var results = client.GetRepositoryItemDescriptions( resultIdentifiers.ToIdentifierCollection()); // Write a line for each result. foreach (var result in results) { Console.WriteLine(result.Label["en-US"]); } }
private static StudyUnitModel GetAllQuestions(string agency, Guid id) { MultilingualString.CurrentCulture = "en-US"; var client = ClientHelper.GetClient(); IVersionable item = client.GetLatestItem(id, agency, ChildReferenceProcessing.Populate); var studyUnit = item as StudyUnit; var studyModel = new StudyUnitModel(); studyModel.StudyUnit = studyUnit; foreach (var qualityStatement in studyUnit.QualityStatements) { client.PopulateItem(qualityStatement); } // Use a set search to get a list of all questions that are referenced // by the study. A set search will return items that may be several steps // away. SetSearchFacet setFacet = new SetSearchFacet(); setFacet.ItemTypes.Add(DdiItemType.QuestionItem); var matches = client.SearchTypedSet(studyUnit.CompositeId, setFacet); var infoList = client.GetRepositoryItemDescriptions(matches.ToIdentifierCollection()); foreach (var info in infoList) { studyModel.Questions.Add(info); } return(studyModel); }
// // GET: /Item/ public ActionResult Index(string agency, Guid id) { MultilingualString.CurrentCulture = "en-US"; var client = ClientHelper.GetClient(); // Retrieve the requested item from the Repository. // Populate the item's children, so we can display information about them. IVersionable item = client.GetLatestItem(id, agency, ChildReferenceProcessing.Populate); // To populate more than one level of children, you can use the GraphPopulator. //GraphPopulator populator = new GraphPopulator(client); //item.Accept(populator); // The type of model and the view we want depends on the item type. // This sample only provides specific support for a few item types, // so we will just hard-code the type checking below. ItemModel model = null; string viewName = string.Empty; if (item is CategoryScheme) { var categoryList = item as CategoryScheme; // Create the model and set the item as a property, so it's contents can be displayed var categorySchemeModel = new CategorySchemeModel(); categorySchemeModel.CategoryScheme = categoryList; model = categorySchemeModel; viewName = "CategoryList"; } else if (item is StudyUnit) { var studyUnit = item as StudyUnit; // Create the model and set the item as a property, so it's contents can be displayed var studyModel = new StudyUnitModel(); studyModel.StudyUnit = studyUnit; foreach (var qualityStatement in studyUnit.QualityStatements) { client.PopulateItem(qualityStatement); } // Use a set search to get a list of all questions that are referenced // by the study. A set search will return items that may be several steps // away. SetSearchFacet setFacet = new SetSearchFacet(); setFacet.ItemTypes.Add(DdiItemType.QuestionItem); var matches = client.SearchTypedSet(studyUnit.CompositeId, setFacet); var infoList = client.GetRepositoryItemDescriptions(matches.ToIdentifierCollection()); foreach (var info in infoList) { studyModel.Questions.Add(info); } model = studyModel; viewName = "StudyUnit"; } else if (item is CodeScheme) { var codeScheme = item as CodeScheme; // Create the model and set the item as a property, so it's contents can be displayed var codeSchemeModel = new CodeSchemeModel(); codeSchemeModel.CodeScheme = codeScheme; model = codeSchemeModel; viewName = "CodeList"; } else if (item is QualityStatement) { var qualityStatement = item as QualityStatement; var qualityStatementModel = new QualityStatementModel(qualityStatement); model = qualityStatementModel; viewName = "QualityStatement"; } else { model = new ItemModel(); viewName = "GenericItem"; } // Fopr all item types, get the version history of the item, // and add the information to the model. var history = client.GetVersionHistory(id, agency); foreach (var version in history) { model.History.Add(version); } // Use a graph search to find a list of all items that // directly reference this item. GraphSearchFacet facet = new GraphSearchFacet(); facet.TargetItem = item.CompositeId; facet.UseDistinctResultItem = true; var referencingItemsDescriptions = client.GetRepositoryItemDescriptionsByObject(facet); // Add the list of referencing items to the model. foreach (var info in referencingItemsDescriptions) { model.ReferencingItems.Add(info); } // Return the appropriate view, sending in the model. return View(viewName, model); }
public object GetRepository(string agency, Guid id) { MultilingualString.CurrentCulture = "en-US"; var client = ClientHelper.GetClient(); // Retrieve the requested item from the Repository. // Populate the item's children, so we can display information about them. var v = client.GetLatestVersionNumber(id, agency); IVersionable item1 = client.GetItem(id, agency, v); IVersionable item = client.GetLatestItem(id, agency, ChildReferenceProcessing.Populate); // To populate more than one level of children, you can use the GraphPopulator. //GraphPopulator populator = new GraphPopulator(client); //item.Accept(populator); // The type of model and the view we want depends on the item type. // This sample only provides specific support for a few item types, // so we will just hard-code the type checking below. ItemModel model = null; string viewName = string.Empty; if (item is CategoryScheme) { var categoryList = item as CategoryScheme; // Create the model and set the item as a property, so it's contents can be displayed var categorySchemeModel = new CategorySchemeModel(); categorySchemeModel.CategoryScheme = categoryList; model = categorySchemeModel; viewName = "CategoryList"; } else if (item is StudyUnit) { var studyUnit = item as StudyUnit; // Create the model and set the item as a property, so it's contents can be displayed var studyModel = new StudyUnitModel(); studyModel.StudyUnit = studyUnit; var QualityStatements = studyUnit.QualityStatements.OrderBy(x => x.Identifier).ToList(); foreach (var qualityStatement in QualityStatements) { client.PopulateItem(qualityStatement); } // Use a set search to get a list of all questions that are referenced // by the study. A set search will return items that may be several steps // away. SetSearchFacet setFacet = new SetSearchFacet(); setFacet.ItemTypes.Add(DdiItemType.QuestionItem); var matches = client.SearchTypedSet(studyUnit.CompositeId, setFacet); var infoList = client.GetRepositoryItemDescriptions(matches.ToIdentifierCollection()); var infoList1 = from x in infoList orderby x.DisplayLabel select x; foreach (var info in infoList1) { studyModel.Questions.Add(info); } model = studyModel; viewName = "StudyUnit"; } else if (item is CodeList) { var codeList = item as CodeList; // Create the model and set the item as a property, so it's contents can be displayed var codeListModel = new CodeListModel(); codeListModel.CodeList = codeList; model = codeListModel; viewName = "CodeList"; } else if (item is QualityStatement) { var qualityStatement = item as QualityStatement; var qualityStatementModel = new QualityStatementModel(qualityStatement); model = qualityStatementModel; viewName = "QualityStatement"; } else { model = new ItemModel(); viewName = "GenericItem"; } // Fopr all item types, get the version history of the item, // and add the information to the model. var history = client.GetVersionHistory(id, agency); foreach (var version in history) { model.History.Add(version); } // Use a graph search to find a list of all items that // directly reference this item. GraphSearchFacet facet = new GraphSearchFacet(); facet.TargetItem = item.CompositeId; facet.UseDistinctResultItem = true; var referencingItemsDescriptions = client.GetRepositoryItemDescriptionsByObject(facet); // Add the list of referencing items to the model. foreach (var info in referencingItemsDescriptions) { model.ReferencingItems.Add(info); } return(model); }
public void Commit() { var client = Utility.GetClient(); var facet = new SetSearchFacet(); facet.ItemTypes.Add(DdiItemType.Group); facet.ItemTypes.Add(DdiItemType.DdiInstance); facet.ReverseTraversal = true; var toCommit = new List <IVersionable>(); toCommit.AddRange(toBeAdded); toCommit.AddRange(workingSet.OfType <VariableScheme>()); toCommit.AddRange(workingSet.OfType <VariableGroup>()); toCommit.AddRange(workingSet.OfType <ControlConstructScheme>()); toCommit.AddRange(workingSet.OfType <ControlConstructGroup>()); foreach (var scope in scopes) { toCommit.AddRange(scope.Value.toBeAdded); } var versioner = new Versioner(); var acceptedTypes = new List <Guid>() { DdiItemType.ResourcePackage, DdiItemType.DataCollection, DdiItemType.InstrumentScheme, DdiItemType.Instrument, DdiItemType.VariableScheme, DdiItemType.ControlConstructScheme }; var joints = toCommit.Where(x => acceptedTypes.Contains(x.ItemType)).ToList(); var tops = new Dictionary <IdentifierTriple, IVersionable>(); foreach (var joint in joints) { var set = client.SearchTypedSet(joint.CompositeId, facet); foreach (var parent in set) { var top = client.GetItem( parent.CompositeId, ChildReferenceProcessing.PopulateLatest ) as IVersionable; if (top != null) { tops[top.CompositeId] = top; } } } foreach (var top in tops) { toCommit.Add(top.Value); var one_down = top.Value.GetChildren().ToList(); for (var i = 0; i < one_down.Count; i++) { toCommit.Add(one_down[i]); IVersionable su_joint; if ((su_joint = toCommit.FirstOrDefault(x => one_down[i].CompositeId.Identifier == x.CompositeId.Identifier)) != default(IVersionable)) { top.Value.ReplaceChild(one_down[i].CompositeId, su_joint); } else { foreach (var child in one_down[i].GetChildren().ToList()) { var bottom_joint = toCommit.FirstOrDefault(x => x.CompositeId == child.CompositeId); if (bottom_joint != default(IVersionable)) { one_down[i].ReplaceChild(child.CompositeId, bottom_joint); } } } } versioner.IncrementDityItemAndParents(top.Value); } client.RegisterItems(toCommit, new CommitOptions()); }