Ejemplo n.º 1
0
 public static async Task CreateDataCollectionProtocol(
     IDataApiClient dataApiClient,
     string protocolName,
     List <DataCollectionProtocolParameter> parameters,
     List <DataPlaceholder> expectedData)
 {
     var protocol = new DataCollectionProtocol(
         protocolName,
         parameters ?? new List <DataCollectionProtocolParameter>(),
         expectedData ?? new List <DataPlaceholder>());
     await dataApiClient.InsertAsync(protocol, protocolName);
 }
Ejemplo n.º 2
0
        public static List <UnitTestSearchObject> GenerateAndSubmitSearchData(int searchObjectCount, IDataApiClient dataApiClient)
        {
            var searchObjects  = new List <UnitTestSearchObject>();
            var insertionTasks = new List <Task>();

            for (int objectIdx = 0; objectIdx < searchObjectCount; objectIdx++)
            {
                var searchObject = GenerateUnitTestSearchObject();
                insertionTasks.Add(dataApiClient.InsertAsync(searchObject, searchObject.Id));
                searchObjects.Add(searchObject);
            }
            Task.WaitAll(insertionTasks.ToArray());
            return(searchObjects);
        }
Ejemplo n.º 3
0
        public static async Task CreateDataProject(
            IDataApiClient dataApiClient,
            string dataProjectId,
            string projectSourceSystem,
            string protocolName,
            Dictionary <string, string> protocolParameterResponses)
        {
            var protocol = await dataApiClient.GetAsync <DataCollectionProtocol>(protocolName);

            var mandatoryResponses = protocol.Parameters
                                     .Where(x => x.IsMandatory);
            var missingResponses = mandatoryResponses
                                   .Where(x => !protocolParameterResponses.ContainsKey(x.Name))
                                   .ToList();

            if (missingResponses.Any())
            {
                var aggregatedMissingParameters = string.Join(", ", missingResponses.Select(x => x.Name));
                throw new ArgumentException($"You are missing parameter responses for the following mandatory parameters: {aggregatedMissingParameters}");
            }


            var globalizedProjectId = dataProjectId;

            try
            {
                var detectedSourceSystem = IdGenerator.GetSourceSystem(dataProjectId);
                if (detectedSourceSystem != projectSourceSystem)
                {
                    throw new ArgumentException($"The provided data project ID has a prefix that is associated with "
                                                + $"source system '{detectedSourceSystem}', but '{projectSourceSystem}' was specified. "
                                                + $"This either means that the '{projectSourceSystem}' system uses an ID-pattern that "
                                                + $"clashes with the ID-convention (PREFIX.<LocalID>)"
                                                + $"or you specified the wrong ID/source system.");
                }
            }
            catch (KeyNotFoundException)
            {
                if (projectSourceSystem != "SelfAssigned")
                {
                    globalizedProjectId = IdGenerator.GlobalizeLocalId(projectSourceSystem, dataProjectId);
                }
            }
            var dataProject = new DataProject(
                globalizedProjectId,
                projectSourceSystem,
                protocol,
                protocolParameterResponses);
            await dataApiClient.InsertAsync(dataProject, dataProjectId);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Inserts object into database if it doesn't already exist
        /// </summary>
        /// <returns>True if the object was inserted, otherwise false</returns>
        public static async Task <bool> Upload(
            IId obj,
            IDataApiClient dataApiClient,
            bool overwriteIfExists = false)
        {
            if (overwriteIfExists)
            {
                await dataApiClient.ReplaceAsync(obj, obj.Id);

                return(true);
            }
            var exists = await dataApiClient.ExistsAsync(obj.GetType().Name, obj.Id);

            if (!exists)
            {
                await dataApiClient.InsertAsync(obj, obj.Id);
            }
            return(!exists);
        }
Ejemplo n.º 5
0
 public static async Task AddToDataProject(
     IDataApiClient dataApiClient,
     string dataProjectId,
     string dataType,
     string id,
     List <DataReference> derivedData = null,
     string filename = null)
 {
     if (!await dataApiClient.ExistsAsync <DataProject>(dataProjectId))
     {
         throw new KeyNotFoundException($"No data project with ID '{dataProjectId}' exists");
     }
     var dataProjectUploadInfo = new DataProjectUploadInfo(
         dataApiClient.LoggedInUsername,
         DateTime.UtcNow,
         dataProjectId,
         new DataReference(dataType, id),
         derivedData,
         filename);
     await dataApiClient.InsertAsync(dataProjectUploadInfo, dataProjectUploadInfo.Id);
 }
Ejemplo n.º 6
0
        public async Task ProcessObject(DataModificationType modificationType, string dataType, string inputId, string inputObjectJson, IProcessor typeProcessor)
        {
            //await LogExecutionStarting(typeProcessor);
            var    stopWatch = Stopwatch.StartNew();
            bool   isSuccess;
            var    isWorkDone = true;
            string summary;
            string outputTypeName = null;

            try
            {
                var processorResult = await typeProcessor.Process(modificationType, dataType, inputId, inputObjectJson);

                if (processorResult.Status == ProcessingStatus.NotInterested)
                {
                    return;
                }
                else if (processorResult.Status == ProcessingStatus.Postponed)
                {
                    var postponedProcessorResult = (PostponedProcessorResult)processorResult;
                    await dataApiClient.InsertAsync(postponedProcessorResult.PostponedObject);

                    return;
                }
                else if (processorResult.Status == ProcessingStatus.Error)
                {
                    isSuccess = false;
                    var errorProcessorResult = (ErrorProcessorResult)processorResult;
                    summary = errorProcessorResult.ErrorMessage;
                }
                else if (processorResult.Status == ProcessingStatus.Success)
                {
                    isSuccess = true;
                    var successProcessorResult = (SuccessProcessorResult)processorResult;
                    foreach (var obj in successProcessorResult.Objects)
                    {
                        await StoreResult(obj);
                    }

                    summary = successProcessorResult.Summary;
                }
                else
                {
                    throw new InvalidEnumArgumentException($"Invalid enum value '{processorResult.Status}' for {nameof(ProcessingStatus)}");
                }
            }
            catch (Exception e)
            {
                isSuccess  = false;
                isWorkDone = false;
                summary    = e.InnermostException().Message;
                if (string.IsNullOrWhiteSpace(summary))
                {
                    summary = e.Message;
                }
            }

            stopWatch.Stop();
            await LogExecutionFinished(
                typeProcessor,
                outputTypeName,
                inputId,
                summary,
                isSuccess,
                isWorkDone,
                stopWatch);
        }
 public async Task Log(DataProcessingServiceLog logEntry)
 {
     await dataApiClient.InsertAsync(logEntry, logEntry.Id);
 }