public void TestPostWithAddAndDeleteByFilter() { // // create new data object by getting an existing one and change its identifier // IList <IDataObject> dataObjects = _dataLayer.Get(_objectType, new DataFilter(), 1, 8); string orgIdentifier = GetIdentifier(dataObjects[0]); string newIdentifier = "559"; SetIdentifier(dataObjects[0], newIdentifier); // post new data object Response response = _dataLayer.Post(dataObjects); Assert.AreEqual(response.Level, StatusLevel.Success); // // delete the new data object with a filter // DataFilter filter = new DataFilter(); filter.Expressions.Add( new Expression() { PropertyName = "display_set_unique_id", RelationalOperator = org.iringtools.library.RelationalOperator.EqualTo, Values = new Values() { newIdentifier } } ); response = _dataLayer.Delete(_objectType, filter); Assert.AreEqual(response.Level, StatusLevel.Success); }
static void Main(string[] args) { AdapterSettings settings = new AdapterSettings(); settings["WhereClauseAlias"] = "_t"; sampleDL = new SampleSQLDataLayer(settings); #region test get // from iRING service point of view IList <IDataObject> dataObjects = sampleDL.Get("LINES", null); Console.WriteLine("Object Count: " + dataObjects.Count); foreach (IDataObject dataObject in dataObjects) { DebugDataObject(dataObject, "LINES"); } #endregion #region test post foreach (IDataObject dataObject in dataObjects) { ((GenericDataObject)dataObject).ObjectType = "LINES"; // make tag different by appending timestamp on it string tag = dataObject.GetPropertyValue("TAG").ToString(); string newTag = tag + DateTime.Now.ToString(); if (newTag.Length > 100) { newTag = newTag.Substring(0, 100); } dataObject.SetPropertyValue("TAG", newTag); } // from iRING service point of view Response response = sampleDL.Post(dataObjects); Console.WriteLine("Post result: " + response.Level.ToString()); #endregion Console.WriteLine("Test completed!"); Console.ReadKey(); }
static void Main(string[] args) { AdapterSettings settings = new AdapterSettings(); settings["WhereClauseAlias"] = "_t"; sampleDL = new SampleSQLDataLayer(settings); #region test get // from iRING service point of view IList<IDataObject> dataObjects = sampleDL.Get("LINES", null); Console.WriteLine("Object Count: " + dataObjects.Count); foreach (IDataObject dataObject in dataObjects) { DebugDataObject(dataObject, "LINES"); } #endregion #region test post foreach (IDataObject dataObject in dataObjects) { ((GenericDataObject)dataObject).ObjectType = "LINES"; // make tag different by appending timestamp on it string tag = dataObject.GetPropertyValue("TAG").ToString(); string newTag = tag + DateTime.Now.ToString(); if (newTag.Length > 100) newTag = newTag.Substring(0, 100); dataObject.SetPropertyValue("TAG", newTag); } // from iRING service point of view Response response = sampleDL.Post(dataObjects); Console.WriteLine("Post result: " + response.Level.ToString()); #endregion Console.WriteLine("Test completed!"); Console.ReadKey(); }
public void TestDataObjects() { int MAX_ITEMS = 25; string result = string.Empty; #region Test dictionary Console.WriteLine("\nTesting get dictionary ..."); DataDictionary dictionary = _dataLayer.GetDictionary(); Assert.Greater(dictionary.dataObjects.Count, 0); result = (dictionary.dataObjects.Count > 0) ? "passed." : "failed."; _logger.Info("Test get dictionary " + result); #endregion #region Test refresh dictionary Console.WriteLine("Testing refresh dictionary ..."); Response response = _dataLayer.RefreshAll(); Assert.AreEqual(response.Level, StatusLevel.Success); result = (dictionary.dataObjects.Count > 0) ? "passed." : "failed."; _logger.Info("Test refresh dictionary " + result); #endregion foreach (Scenario scenario in _scenarios) { Console.WriteLine(string.Format("\nExecuting scenario [{0}] ...", scenario.Name)); string objectType = scenario.ObjectType; string padding = scenario.IdentifierPadding; org.iringtools.test.Properties properties = scenario.Properties; DataFilter filter = (scenario.DataFilter != null) ? Utility.DeserializeDataContract <DataFilter>(scenario.DataFilter) : new DataFilter(); #region Test get count Console.WriteLine("Testing get count ..."); long count = _dataLayer.GetCount(objectType, filter); Assert.Greater(count, 0); result = (count > 0) ? "passed." : "failed."; _logger.Info("Test get count " + result); #endregion if (count > MAX_ITEMS) { count = MAX_ITEMS; } #region Test get page Console.WriteLine("Testing get page ..."); IList <IDataObject> dataObjects = _dataLayer.Get(objectType, filter, (int)count, 0); Assert.Greater(dataObjects.Count, 0); result = (dataObjects.Count > 0) ? "passed." : "failed."; _logger.Info("Test get page " + result); #endregion #region Test get identifiers Console.WriteLine("Testing get identifiers ..."); IList <string> identifiers = _dataLayer.GetIdentifiers(objectType, filter); Assert.Greater(identifiers.Count, 0); result = (identifiers.Count > 0) ? "passed." : "failed."; _logger.Info("Test get identifires " + result); #endregion #region Test get by identifiers Console.WriteLine("Testing get by identifiers ..."); if (identifiers.Count > MAX_ITEMS) { dataObjects = _dataLayer.Get(objectType, (((List <string>)identifiers).GetRange(0, MAX_ITEMS - 1))); } else { dataObjects = _dataLayer.Get(objectType, identifiers); } Assert.Greater(dataObjects.Count, 0); result = (dataObjects.Count > 0) ? "passed." : "failed."; _logger.Info("Test get by identifires " + result); #endregion // // Create a data object to post and delete // IDataObject dataObject = dataObjects[0]; DataObject objDef = dictionary.dataObjects.Find(x => x.objectName.ToLower() == objectType.ToLower()); string keyPropName = objDef.keyProperties[0].keyPropertyName; string keyPropValue = Convert.ToString(dataObject.GetPropertyValue(keyPropName)) + padding; // Set key property dataObject.SetPropertyValue(keyPropName, keyPropValue); // Set configured properties foreach (Property prop in properties) { dataObject.SetPropertyValue(prop.Name, prop.Value); } #region Test post Console.WriteLine("Testing post ..."); response = _dataLayer.Post(new List <IDataObject>() { dataObject }); Assert.AreEqual(response.Level, StatusLevel.Success); result = (response.Level == StatusLevel.Success) ? "passed." : "failed."; _logger.Info("Test post " + result); #endregion #region Test delete by identifiers Console.WriteLine("Testing delete by identifiers ..."); response = _dataLayer.Delete(objectType, new List <string>() { keyPropValue }); Assert.AreEqual(response.Level, StatusLevel.Success); result = (response.Level == StatusLevel.Success) ? "passed." : "failed."; _logger.Info("Test delete by identifiers " + result); #endregion #region Test create Console.WriteLine("Testing create ..."); IDataObject newDataObject = _dataLayer.Create(objectType, null)[0]; Assert.AreNotEqual(newDataObject, null); result = (newDataObject != null) ? "passed." : "failed."; _logger.Info("Test create " + result); #endregion #region Test delete by filter Console.WriteLine("Testing delete by filter ..."); // Prepare data object to post foreach (DataProperty prop in objDef.dataProperties) { newDataObject.SetPropertyValue(prop.propertyName, dataObject.GetPropertyValue(prop.propertyName)); } // Post it response = _dataLayer.Post(new List <IDataObject>() { newDataObject }); Assert.AreEqual(response.Level, StatusLevel.Success); // Prepare filter to delete filter = new DataFilter() { Expressions = new List <Expression>() { new Expression() { PropertyName = keyPropName, RelationalOperator = RelationalOperator.EqualTo, Values = new Values() { keyPropValue } } } }; // Execute delete _dataLayer.Delete(objectType, filter); Assert.AreEqual(response.Level, StatusLevel.Success); result = (response.Level == StatusLevel.Success) ? "passed." : "failed."; _logger.Info("Test delete by filter " + result); #endregion } }
public Response Pull(string scope, string app, string graph, Request request) { Response response = new Response(); response.Level = StatusLevel.Success; Status status = new Status(); status.Messages = new Messages(); try { status.Identifier = String.Format("{0}.{1}", scope, app); InitializeScope(scope, app); if (_settings["ReadOnlyDataLayer"] != null && _settings["ReadOnlyDataLayer"].ToString().ToLower() == "true") { string message = "Can not perform post on read-only data layer of [" + scope + "." + app + "]."; _logger.Error(message); status.Level = StatusLevel.Error; status.Messages.Add(message); } else { InitializeDataLayer(); DateTime startTime = DateTime.Now; #region move this portion to dotNetRdfEngine? if (!request.ContainsKey("targetEndpointUri")) { throw new Exception("Target Endpoint Uri is required"); } string targetEndpointUri = request["targetEndpointUri"]; if (!request.ContainsKey("targetGraphBaseUri")) { throw new Exception("Target graph uri is required"); } string targetGraphBaseUri = request["targetGraphBaseUri"]; _settings["TargetGraphBaseUri"] = targetGraphBaseUri; if (targetGraphBaseUri.ToLower() == "[default graph]") { targetGraphBaseUri = String.Empty; } SparqlRemoteEndpoint endpoint = new SparqlRemoteEndpoint(new Uri(targetEndpointUri), targetGraphBaseUri); if (request.ContainsKey("targetCredentials")) { string targetCredentialsXML = request["targetCredentials"]; WebCredentials targetCredentials = Utility.Deserialize <WebCredentials>(targetCredentialsXML, true); if (targetCredentials.isEncrypted) { targetCredentials.Decrypt(); } endpoint.SetCredentials(targetCredentials.GetNetworkCredential().UserName, targetCredentials.GetNetworkCredential().Password, targetCredentials.GetNetworkCredential().Domain); } string proxyHost = _settings["ProxyHost"]; string proxyPort = _settings["ProxyPort"]; string proxyCredsToken = _settings["ProxyCredentialToken"]; if (!String.IsNullOrEmpty(proxyHost) && !String.IsNullOrEmpty(proxyPort) && !String.IsNullOrEmpty(proxyCredsToken)) { WebProxyCredentials proxyCreds = _settings.GetWebProxyCredentials(); endpoint.Proxy = proxyCreds.GetWebProxy() as WebProxy; endpoint.ProxyCredentials = proxyCreds.GetNetworkCredential(); } VDS.RDF.IGraph resultGraph = endpoint.QueryWithResultGraph("CONSTRUCT {?s ?p ?o} WHERE {?s ?p ?o}"); #endregion if (resultGraph != null && resultGraph.Triples.Count > 0) { // call RdfProjectionEngine to fill data objects from a given graph _projectionEngine = _kernel.Get <IProjectionLayer>("rdf"); System.Text.StringBuilder sb = new System.Text.StringBuilder(); TextWriter textWriter = new StringWriter(sb); VDS.RDF.Writing.RdfXmlWriter rdfWriter = new VDS.RDF.Writing.RdfXmlWriter(); rdfWriter.Save(resultGraph, textWriter); XDocument xDocument = XDocument.Parse(sb.ToString()); if (xDocument != null && xDocument.Root != null) { _logger.Debug(xDocument.Root.ToString()); _dataObjects = _projectionEngine.ToDataObjects(graph, ref xDocument); if (_dataObjects != null && _dataObjects.Count > 0) { status.Messages.Add("Query target endpoint completed successfully."); status.Messages.Add(String.Format("Number of data objects created [{0}].", _dataObjects.Count)); // post data objects to data layer response.Append(_dataLayer.Post(_dataObjects)); DateTime endTime = DateTime.Now; TimeSpan duration = endTime.Subtract(startTime); status.Messages.Add(String.Format("Execution time [{0}:{1}.{2}] minutes.", duration.Minutes, duration.Seconds, duration.Milliseconds)); } else { status.Messages.Add(string.Format("No data objects being created.")); } } else { throw new Exception("Facade document is empty."); } } else { throw new Exception("Facade graph is empty."); } } } catch (Exception ex) { _logger.Error("Error in Pull(): ", ex); status.Level = StatusLevel.Error; status.Messages.Add(string.Format("Error pulling graph: {0}", ex)); } response.Append(status); return(response); }