private POCO.Ontology AddOntology(POCO.Ontology ontologyEntity)
        {
            bool isAddedOk = false;

            // Execute the insert operation.
            //log.Verbose("Executing table operation");
            try
            {
                // Check if an SystemId has been set
                if (ontologyEntity.UniqueId == null)
                {
                    ontologyEntity.UniqueId = Guid.NewGuid().ToString();
                }

                // Call the Add datafactory method
                DataFactory.DataConfig datacfg = Utils.GetDataConfig();
                DataFactory.Ontology.Add(datacfg, ontologyEntity);
            }

            catch (Exception aex)
            {
                _logger.LogError("ERR exception: " + aex.Message);
            }

            isAddedOk = true;

            return(ontologyEntity);
        }
Esempio n. 2
0
        public static string Add(DataConfig providerConfig, POCO.Ontology ontology)
        {
            switch (providerConfig.ProviderType)
            {
            case "azure.tableservice":
                AzureOntology az = new AzureOntology(ontology);

                CloudTable     table     = Utils.GetCloudTable(providerConfig, AzureTableNames.Ontology);
                TableOperation operation = TableOperation.InsertOrMerge(az);
                Task           tUpdate   = table.ExecuteAsync(operation);
                tUpdate.Wait();

                //TODO return the inserted record id/timestamp
                return(string.Empty);


            case "internal.mongodb":
                IMongoCollection <MongoOntology> collection = Utils.GetMongoCollection <MongoOntology>(providerConfig, MongoTableNames.Ontology);
                MongoOntology mongoObject = Utils.ConvertType <MongoOntology>(ontology);
                collection.InsertOne(mongoObject);
                return(string.Empty);

            default:
                throw new ApplicationException("Data provider not recognised: " + providerConfig.ProviderType);
            }

            return(string.Empty);
        }
        public IActionResult OntologyAdd([FromHeader] string ontology)
        {
            _logger.LogInformation("CPAPI: OntologyAdd");

            // Deserialize the system
            POCO.Ontology newOntology = new POCO.Ontology();
            if (ontology != null && ontology.Length > 0)
            {
                _logger.LogDebug("Deserializing Ontology of length: " + ontology.Length);
                newOntology = JsonConvert.DeserializeObject <POCO.Ontology>(ontology);
            }
            else
            {
                return(StatusCode((int)System.Net.HttpStatusCode.BadRequest));
            }

            // Validate the system
            if (newOntology.PartitionKey == null || newOntology.PartitionKey == string.Empty)
            {
                return(StatusCode((int)System.Net.HttpStatusCode.BadRequest));
            }

            if (newOntology.Label == null || newOntology.Label == string.Empty)
            {
                return(StatusCode((int)System.Net.HttpStatusCode.BadRequest));
            }

            // Check if the System Id has been set
            if (newOntology.UniqueId == null)
            {
                // Set to a new Guid
                newOntology.UniqueId = Guid.NewGuid().ToString();
            }

            // Clean the table and row keys
            if (!newOntology.PartitionKey.EndsWith("/"))
            {
                newOntology.PartitionKey += "/";
            }
            newOntology.PartitionKey = Utils.CleanTableKey(newOntology.PartitionKey);
            newOntology.RowKey       = Utils.CleanTableKey(DateTime.UtcNow.ToString(Utils.ISODateFormat));

            POCO.Ontology addedOntology = AddOntology(newOntology);

            if (addedOntology != null)
            {
                // Return the added system entity
                ObjectResult result = new ObjectResult(addedOntology);
                return(result);
            }
            else
            {
                return(StatusCode((int)System.Net.HttpStatusCode.InternalServerError));
            }
        }
        public IActionResult OntologyAddV2([FromBody] POCO.Ontology ontology)
        {
            _logger.LogInformation("CPAPI: OntologyAdd");

            // Deserialize the system
            if (ontology == null)
            {
                return(BadRequest("Ontology data is invalid or empty"));
            }

            // Validate the system
            if (string.IsNullOrEmpty(ontology.PartitionKey))
            {
                return(BadRequest("PartitionKey is invalid"));
            }

            if (string.IsNullOrEmpty(ontology.Label))
            {
                return(BadRequest("Ontology is invalid"));
            }

            // Check if the System Id has been set
            if (ontology.UniqueId == null)
            {
                // Set to a new Guid
                ontology.UniqueId = Guid.NewGuid().ToString();
            }

            // Clean the table and row keys
            if (!ontology.PartitionKey.EndsWith("/"))
            {
                ontology.PartitionKey += "/";
            }
            ontology.PartitionKey = Utils.CleanTableKey(ontology.PartitionKey);
            ontology.RowKey       = Utils.CleanTableKey(DateTime.UtcNow.ToString(Utils.ISODateFormat));

            POCO.Ontology addedOntology = AddOntology(ontology);

            if (addedOntology != null)
            {
                // Return the added system entity
                ObjectResult result = new ObjectResult(addedOntology);
                return(result);
            }
            else
            {
                return(new UnprocessableEntityObjectResult("Internal server error, cannot process this request."));
            }
        }
Esempio n. 5
0
 public static List <POCO.OntologyTerm> GetOntologyTerms(DataConfig providerConfig, POCO.Ontology ontology)
 {
     return(GetOntologyTerms(providerConfig, ontology.PartitionKey));
 }
Esempio n. 6
0
        public static List <POCO.OntologyMatchSummary> GetOntologyMatchSummary(DataConfig providerConfig, POCO.Ontology ontology)
        {
            List <Filter> filters  = new List <Filter>();
            Filter        pkFilter = new Filter("PartitionKey", ontology.PartitionKey, "eq");

            filters.Add(pkFilter);

            return(GetOntologyMatchSummary(providerConfig, filters));
        }