/// <summary> /// Defines a new extraction project this is stored in the Data Export database /// </summary> public Project(IDataExportRepository repository, string name) { Repository = repository; try { Repository.InsertAndHydrate(this, new Dictionary <string, object> { { "Name", name } }); } catch (Exception ex) { //sometimes the user tries to create multiple Projects without fully populating the last one (with a project number) if (ex.Message.Contains("idx_ProjectNumberMustBeUnique")) { Project offender; try { //find the one with the unset project number offender = Repository.GetAllObjects <Project>().Single(p => p.ProjectNumber == null); } catch (Exception) { throw; } throw new Exception("Could not create a new Project because there is already another Project in the system (" + offender + ") which is missing a Project Number. All projects must have a ProjectNumber, there can be 1 Project at a time which does not have a number and that is one that is being built by the user right now. Either delete Project " + offender + " or give it a project number", ex); } throw; } }
/// <summary> /// Returns all <see cref="ExtractableColumn"/> Injected with thier corresponding <see cref="ExtractionInformation"/> /// </summary> /// <param name="repository"></param> /// <returns></returns> public ExtractableColumn[] GetAllExtractableColumns(IDataExportRepository repository) { lock (WriteLock) { var toReturn = repository.GetAllObjects <ExtractableColumn>(); foreach (var c in toReturn) { if (c.CatalogueExtractionInformation_ID == null) { c.InjectKnown((ExtractionInformation)null); } else { if (AllExtractionInformationsDictionary.TryGetValue(c.CatalogueExtractionInformation_ID.Value, out ExtractionInformation ei)) { c.InjectKnown(ei); } } } return(toReturn); } }
/// <summary> /// Returns all <see cref="ExtractableColumn"/> Injected with thier corresponding <see cref="ExtractionInformation"/> /// </summary> /// <param name="repository"></param> /// <returns></returns> public ExtractableColumn[] GetAllExtractableColumns(IDataExportRepository repository) { var toReturn = repository.GetAllObjects <ExtractableColumn>(); foreach (var c in toReturn) { if (c.CatalogueExtractionInformation_ID == null) { c.InjectKnown((ExtractionInformation)null); } else { if (AllExtractionInformationsDictionary.ContainsKey(c.CatalogueExtractionInformation_ID.Value)) { var extractionInformation = AllExtractionInformationsDictionary[c.CatalogueExtractionInformation_ID.Value]; c.InjectKnown(extractionInformation); } } } return(toReturn); }
public int ImportAsExtractableCohort(bool deprecateOldCohortOnSuccess, bool migrateUsages) { if (NewCohortDefinition.ID == null) { throw new NotSupportedException("CohortCreationRequest cannot be imported because it's ID is null, it is likely that it has not been pushed to the server yet"); } var cohort = new ExtractableCohort(_repository, (ExternalCohortTable)NewCohortDefinition.LocationOfCohort, (int)NewCohortDefinition.ID); cohort.AppendToAuditLog(DescriptionForAuditLog); CohortCreatedIfAny = cohort; if (deprecateOldCohortOnSuccess && NewCohortDefinition.CohortReplacedIfAny != null) { NewCohortDefinition.CohortReplacedIfAny.IsDeprecated = true; NewCohortDefinition.CohortReplacedIfAny.SaveToDatabase(); } if (migrateUsages && NewCohortDefinition.CohortReplacedIfAny != null) { var oldId = NewCohortDefinition.CohortReplacedIfAny.ID; var newId = cohort.ID; // ExtractionConfigurations that use the old (replaced) cohort var liveUsers = _repository.GetAllObjects <ExtractionConfiguration>() .Where(ec => ec.Cohort_ID == oldId && ec.IsReleased == false); foreach (var ec in liveUsers) { ec.Cohort_ID = newId; ec.SaveToDatabase(); } } return(cohort.ID); }
/// <summary> /// Creates ExtractableCohortDescription objects for each of your cohorts, this involves issuing an async request to the cohort endpoints to calcualte things like /// Count, CountDistinct etc. The ExtractableCohortDescription objects returned from Create will not be populated with values until the async finishes and will have only /// placeholder values like "Loading..." etc /// </summary> /// <param name="repository">The DataExportRepository containing all your cohort refrences (ExtractableCohorts)</param> public CohortDescriptionFactory(IDataExportRepository repository) { _sources = repository.GetAllObjects <ExternalCohortTable>(); _cohorts = repository.GetAllObjects <ExtractableCohort>(); }