public void Execute() { // Use the SpssImporter to get a ResourcePackage with all metadata // contained in the SPSS file. var spssImporter = new SpssImporter(); var resourcePackage = spssImporter.Import(fileName, "uk.cls"); // Get a list of all items contained in the ResourcePackage. var gatherer = new ItemGathererVisitor(); resourcePackage.Accept(gatherer); var allItems = gatherer.FoundItems; // Add the items to the repository. WorkingSet.AddRange(allItems); }
private void CreateQuestionGroups() { //Get concepts that are used, add the implicit ones and except for "0" create question groups from them in the relevant question scheme and put into the working set this.usedConcepts = questionsConcepts.Values.Distinct().ToList(); //add implicit level-1 groups that are parents of level-2 groups var implicits = new List <string>(); foreach (var uc in this.usedConcepts) { if (uc.Length == 1 + 2 + 2) { if (!usedConcepts.Contains(uc.Substring(0, 3))) { implicits.Add(uc.Substring(0, 3)); } } } this.usedConcepts.AddRange(implicits.Distinct()); //get the concept scheme from the repository //I assume there is only one //if there is none, get concepts from the working set ConceptScheme qcgConceptScheme = new ConceptScheme(); var client = Utility.GetClient(); var facet = new SearchFacet(); facet.ItemTypes.Add(DdiItemType.ConceptScheme); SearchResponse response = client.Search(facet); bool fromRepo = false; if (response.ReturnedResults > 0) { fromRepo = true; qcgConceptScheme = client.GetItem(response.Results[0].CompositeId, ChildReferenceProcessing.Populate) as ConceptScheme; } var controlConstructScheme = WorkingSet.OfType <ControlConstructScheme>().Where(x => string.Compare(x.ItemName.Best, this.qcsName, ignoreCase: true) == 0).First(); foreach (var uc in this.usedConcepts) { if (uc != "0") { ControlConstructGroup qcg = new ControlConstructGroup(); qcg.TypeOfGroup = "ConceptGroup"; Concept qcgConcept = new Concept(); if (fromRepo) { qcgConcept = qcgConceptScheme.Concepts.Where(x => string.Compare(x.ItemName.Best, uc, ignoreCase: true) == 0).First(); } else //from working set { qcgConcept = WorkingSet.OfType <Concept>().Where(x => string.Compare(x.ItemName.Best, uc, ignoreCase: true) == 0).First(); } qcg.Concept = qcgConcept; qcg.ItemName.Add("en-GB", "Question Construct Group - " + qcgConcept.Label.Best); //Trace.WriteLine(" " + qcg.ItemName.Best); controlConstructScheme.ControlConstructGroups.Add(qcg); } } WorkingSet.AddRange(controlConstructScheme.ControlConstructGroups); Trace.WriteLine(" question construct groups: " + controlConstructScheme.ControlConstructGroups.Count().ToString() + " for " + this.qcsName); }
public void Execute() { // Load the DDI 3.2 toplevel file. if (!System.IO.File.Exists(fileName)) { Trace.WriteLine(" missing file: " + fileName); return; } var validator = new DdiValidator(fileName, DdiFileFormat.Ddi32); bool isValid = validator.Validate(); var doc = validator.ValidatedXDocument; var deserializer = new Ddi32Deserializer(); var harmonized = deserializer.HarmonizeIdentifiers(doc, DdiFileFormat.Ddi32); var instance = deserializer.GetDdiInstance(doc.Root); // Get a list of all items contained in the DdiInstance. var gatherer = new ItemGathererVisitor(); instance.Accept(gatherer); var allItems = gatherer.FoundItems; //mesh in the instrument references //nb: ItemName seems to be the empty string rather than null if it does not exist in the ddi file var dataCollections = allItems.OfType <DataCollection>().Where(x => string.Compare(x.ItemName.Best, "") != 0); foreach (var dc in dataCollections) { var instrumentName = dc.ItemName.Best + "-in-000001"; var instruments = WorkingSet.OfType <Instrument>().Where(x => string.Compare(x.UserIds[0].Identifier, instrumentName, ignoreCase: true) == 0); var ic = instruments.Count(); if (ic == 1) { dc.AddChild(instruments.First()); } else if (ic > 1) { Trace.WriteLine(" more than one instrument found for " + instrumentName); } else { Trace.WriteLine(" no instrument found for " + instrumentName); //to do: try repo //var client = Utility.GetClient(); //var facet = new SearchFacet(); //facet.ItemTypes.Add(DdiItemType.Instrument); //SearchResponse response = client.Search(facet); //if (response.ReturnedResults > 1) //{ // var repoInstruments = client.GetItems(response.Results); //} } } //mesh in variable set references //I assume that there may be more than one corresponding dataset (i.e. its log prod, phys prod...) with same base name but with a hyphenated suffix //get all the study units (from toplevel, assumed) and go through all its data collections //find the logical products with a base name matching the data collection name and attach them to the study unit //find physical data product and do the same, -I assume sdk physical product is ddi physical data product?- //find physicalInstance with base alternate title matching data collection name and attach them to the study unit var studyUnits = allItems.OfType <StudyUnit>(); foreach (var su in studyUnits) { foreach (var dc in su.DataCollections.Where(x => string.Compare(x.ItemName.Best, "") != 0)) { var dcName = dc.ItemName.Best; var matchingLogicalProducts = WorkingSet.OfType <LogicalProduct>().Where(x => string.Compare(x.ItemName.Best.Split('-')[0], dcName, ignoreCase: true) == 0); var lpc = matchingLogicalProducts.Count(); //if (lpc == 1) // su.AddChild(matchingLogicalProducts.First()); //else if (lpc > 1) // Trace.WriteLine(" more than one logical product found for " + dcName); if (lpc > 0) { foreach (var lp in matchingLogicalProducts) { su.AddChild(lp); } } else { Trace.WriteLine(" no logical product found for " + dcName); } var matchingPhysicalProducts = WorkingSet.OfType <PhysicalProduct>().Where(x => string.Compare(x.ItemName.Best.Split('-')[0], dcName, ignoreCase: true) == 0); var pdpc = matchingPhysicalProducts.Count(); //if (pdpc == 1) // su.AddChild(matchingPhysicalProducts.First()); //else if (pdpc > 1) // Trace.WriteLine(" more than one physical data product found for " + dcName); if (pdpc > 0) { foreach (var pp in matchingPhysicalProducts) { su.AddChild(pp); } } else { Trace.WriteLine(" no physical data product found for " + dcName); } var matchingPhysicalInstances = WorkingSet.OfType <PhysicalInstance>().Where(x => string.Compare(x.DublinCoreMetadata.AlternateTitle.Best.Split('-')[0], dcName, ignoreCase: true) == 0); var pic = matchingPhysicalInstances.Count(); //if (pic == 1) // su.AddChild(matchingPhysicalInstances.First()); //else if (pic > 1) // Trace.WriteLine(" more than one physical instance found for " + dcName); if (pic > 0) { foreach (var pi in matchingPhysicalInstances) { su.AddChild(pi); } } else { Trace.WriteLine(" no physical instance found for " + dcName); } var matchingResourcePackages = WorkingSet.OfType <ResourcePackage>().Where(x => string.Compare(x.DublinCoreMetadata.AlternateTitle.Best.Split('-')[0], dcName, ignoreCase: true) == 0); var rpc = matchingResourcePackages.Count(); //if (rpc == 1) // su.AddChild(matchingResourcePackages.First()); //else if (rpc > 1) // Trace.WriteLine(" more than one resource package found for " + dcName); if (rpc > 0) { foreach (var rp in matchingResourcePackages) { su.AddChild(rp); } } else { Trace.WriteLine(" no resource package found for " + dcName); } } } // Add the items to the working set. WorkingSet.AddRange(allItems); }
public void Execute() { // Load the DDI 3.2 file. if (!System.IO.File.Exists(fileName)) { //throw new System.Exception("...Missing file: " + fileName); Trace.WriteLine(" missing file: " + fileName); return; } var validator = new DdiValidator(fileName, DdiFileFormat.Ddi32); bool isValid = validator.Validate(); var doc = validator.ValidatedXDocument; var deserializer = new Ddi32Deserializer(); var harmonized = deserializer.HarmonizeIdentifiers(doc, DdiFileFormat.Ddi32); var instance = deserializer.GetDdiInstance(doc.Root); // Get a list of all items contained in the DdiInstance. var gatherer = new ItemGathererVisitor(); instance.Accept(gatherer); var allItems = gatherer.FoundItems; //test if there is a caddies-style question scheme (non-grid) //in which case add parameters var questionSchemes = allItems.OfType <QuestionScheme>().Where(x => string.Compare(x.ItemName.Best.Substring(x.ItemName.Best.Length - 5, 5), "_qs01") == 0); if (questionSchemes.Count() != 0) { var questionItems = questionSchemes.First().Questions; foreach (var qi in questionItems) { var p = new Parameter(); p.ParameterType = InstrumentParameterType.Out; p.Name.Add("en-GB", "p_" + qi.ItemName.Best); qi.OutParameters.Add(p); } //I assume that there are the corresponding caddies question constructs //add an InParameter based on the first (the only) OutParameter of its QuestionItem, //an OutputParameter based on the construct name //and a binding between the two var questionConstructs = allItems.OfType <QuestionActivity>(); foreach (var qc in questionConstructs) { if (qc.Question != null) { var p = new Parameter(); p.ParameterType = InstrumentParameterType.In; p.Name.Add("en-GB", qc.Question.OutParameters.First().Name.Best); qc.InParameters.Add(p); var p2 = new Parameter(); p2.ParameterType = InstrumentParameterType.Out; p2.Name.Add("en-GB", "p_" + qc.ItemName.Best); qc.OutParameters.Add(p2); var b = new Binding(); //b.SourceParameter = p; //b.TargetParameter = p2; //qc.Bindings.Add(b); } else if (qc.QuestionGrid != null) { continue; } else { Trace.WriteLine(" question construct with no source"); } } } // Add the items to the working set. WorkingSet.AddRange(allItems); }