Merge branch 'master' of ssh://jani@git.smart-api.io/srv/git/smartapi.git
authorjani <jani@asema.com>
Fri, 4 Jan 2019 14:48:08 +0000 (16:48 +0200)
committerjani <jani@asema.com>
Fri, 4 Jan 2019 14:48:08 +0000 (16:48 +0200)
Common/C#/SmartAPI/SmartAPI.csproj
Common/C#/SmartAPI/agents/TradingAgent.cs
Common/C#/SmartAPI/agents/TransactionAgent.cs
Common/C#/SmartAPI/common/UnitConverter.cs
Common/C#/SmartAPI/model/Activity.cs
Common/C#/SmartAPI/model/Evaluation.cs
Common/C#/SmartAPI/model/Provenance.cs
Common/C#/SmartAPI/model/Restriction.cs
Common/C#/SmartAPI/tests/SigningTest.cs

index a7376119a26208cdfd1b200a2a91dab3b5e6cabe..62ede555aee1405efb1b7b3ed11b70a7b5d9be57 100644 (file)
@@ -94,7 +94,6 @@
     <Compile Include="agents\SharingAgent.cs" />
     <Compile Include="common\ACTIVITIES.cs" />
     <Compile Include="common\Bictionary.cs" />
-    <Compile Include="common\CurrencyConverter.cs" />
     <Compile Include="common\URLs.cs" />
     <Compile Include="common\ConceptDetails.cs" />
     <Compile Include="common\HttpClient.cs" />
     <Compile Include="tests\RequestSerializeParseTest.cs" />
     <Compile Include="tests\ResponseRequestTest.cs" />
     <Compile Include="tests\OptimizerRegistrationTest.cs" />
-    <Compile Include="tests\ChargePlanRegistrationTest.cs" />
     <Compile Include="tests\ChargePlanTest.cs" />
     <Compile Include="tests\ListOfMapsTest.cs" />
     <Compile Include="tests\ParseFileTest.cs" />
index 019e8a4765df82c78a74d3e14839438843f7e97a..eb2b3ca74bbf322d7c35574e2e9ce023b243abd8 100644 (file)
@@ -497,58 +497,6 @@ namespace SmartAPI.Agents
 
         }
 
-        public ValueObject getAccountTransactionsSum(String accountId, DateTime from, DateTime to, String myIdentifier, RSAParameters privKey)
-        {
-            Request request = RequestFactory.create(myIdentifier);
-            Activity activity = request.newActivity(ACTIVITIES.ACCOUNT_TRANSACTION_SUM);
-            activity.setMethod(RESOURCE.READ);
-            Input input = activity.newInput();
-            if (accountId != null)
-            {
-                input.add(PROPERTY.ACCOUNT, new Account(accountId));
-            }            
-            TemporalContext tcx = new TemporalContext();
-            input.add(PROPERTY.TEMPORALCONTEXT, tcx);
-            if (from != null)
-            {
-                tcx.setStart(from);
-            }
-            if (to != null)
-            {
-                tcx.setEnd(to);
-            }
-            Response resp = sendRequest(request, serverUri, privKey);
-            if (resp != null)
-            {
-                if (!resp.hasErrors())
-                {
-                    foreach (Activity a in resp.getActivities())
-                    {
-                        if (a.hasErrors())
-                        {
-                            Tools.printErrors(a);
-                            return null;
-                        }
-                        if (a.hasOutput())
-                        {
-                            return a.getFirstOutput().getValueObjects()[0];
-                        }
-                    }
-                    return null;
-                }
-                else
-                {
-                    Tools.printErrors(resp);
-                    return null;
-                }
-            }
-            else
-            {
-                return null;
-            }
-
-        }
-
         public bool addAccountUserAsClient(String accountUri, String username, String myIdentifier, RSAParameters privKey)
         {
             Person p = new Person();
index 312610f35bfe85cee0c70048fce6b312f0042b36..4d13566a79fed24101bc9ac4452b63686c0ab050 100644 (file)
@@ -136,7 +136,7 @@ namespace SmartAPI.Agents
         }
         
 
-        public String fetchKeyFromNotary(String senderId, String objectId, String objectHash, String objectSignature, String notary, RSAParameters? privKey = null)
+        public String fetchKeyFromNotary(String senderId, String objectId, String objectHash, String objectSignature, String notary, RSAParameters privKey)
         {
             String key = null;
             Transaction transaction = Factory.Factory.createTransaction(senderId);
@@ -270,7 +270,7 @@ namespace SmartAPI.Agents
         }
         */
 
-        public List<Transaction> fetchFromTransactionServer(String senderId, String notary, List<Transaction> transactions, String activityId, RSAParameters? privKey = null)
+        public List<Transaction> fetchFromTransactionServer(String senderId, String notary, List<Transaction> transactions, String activityId, RSAParameters privKey)
         {
             List<Transaction> lst = new List<Transaction>();
 
@@ -291,10 +291,7 @@ namespace SmartAPI.Agents
             }
 
             // Now just sign it and send it
-            if (privKey != null)
-            {
-                req.sign(privKey);
-            }
+            req.sign(privKey);
 
             Response resp = sendRequest(req, serverUri);
             if (resp != null)
index f7c64cff1f6d109b884a32a93dee9deec706f496..6e8c69871cb6d8caa7f14a49a09497bc8ddc2a35 100644 (file)
@@ -78,8 +78,8 @@ namespace SmartAPI.Common
                 // if this is currency conversion
                 if ( fromCode != null && toCode != null ) {
                     try {
-                        double fromRate = CurrencyConverter.getExchangeRateToEUR(fromCode);
-                        double toRate = CurrencyConverter.getExchangeRateToEUR(toCode);
+                        double fromRate = 1.0; // FIXME CurrencyConverter.getExchangeRateToEUR(fromCode);
+                        double toRate = 1.0; // FIXME CurrencyConverter.getExchangeRateToEUR(toCode);
                         newValue = newValue*toRate/fromRate;
                         return new Tuple<String, Double?>(toUnit, newValue);
                     } catch ( Exception e ) {
index 6d108c61aa94005f68be3af4daaa240f74bbb5c7..a237cf8b0865f66464359909efd2e785dba4b46a 100644 (file)
@@ -5,9 +5,8 @@ using System.Collections.Generic;
 
 namespace SmartAPI.Model
 {
-    public class Activity : Obj
+    public class Activity : Evaluation
     {
-        private Variant method = null;
         private List<Input> inputs = new List<Input>();
         private List<Input> refInputs = new List<Input>();
         private List<Output> outputs = new List<Output>();
@@ -16,14 +15,11 @@ namespace SmartAPI.Model
         private List<Availability> dataAvailabilities = new List<Availability>();
         private List<InterfaceAddress> interfaces = new List<InterfaceAddress>();
         private List<Entity> entities = new List<Entity>();
-        private TemporalContext temporalContext = null;
-        private List<TimeSeries> timeSeries = new List<TimeSeries>();
         private Variant traverseUntil = null;
         private Variant traverseTo = null;
 
         private void init()
         {
-            this.initProperty<Variant>(PROPERTY.METHOD, this.hasMethod, this.getMethodVar);
             this.initPropertyList<List<Input>, Input>(PROPERTY.HASINPUT, this.hasInput, this.getInputs);
             this.initPropertyList<List<Input>, Input>(PROPERTY.HASREFINPUT, this.hasRefInput, this.getRefInputs);
             this.initPropertyList<List<Output>, Output>(PROPERTY.HASOUTPUT, this.hasOutput, this.getOutputs);
@@ -32,8 +28,6 @@ namespace SmartAPI.Model
             this.initPropertyList<List<Availability>, Availability>(PROPERTY.HASDATAAVAILABILITY, this.hasDataAvailability, this.getDataAvailabilities);
             this.initPropertyList<List<InterfaceAddress>, InterfaceAddress>(PROPERTY.INTERFACE, this.hasInterface, this.getInterfaces);
             this.initPropertyList<List<Entity>, Entity>(PROPERTY.ENTITY, this.hasEntity, this.getEntities);
-            this.initProperty<TemporalContext>(PROPERTY.TEMPORALCONTEXT, this.hasTemporalContext, this.getTemporalContext);
-            this.initPropertyList<List<TimeSeries>, TimeSeries>(PROPERTY.TIMESERIES, this.hasTimeSeries, this.getTimeSeries);
             this.initProperty<Variant>(PROPERTY.TRAVERSEUNTIL, this.hasTraverseUntil, this.getTraverseUntilVar);
             this.initProperty<Variant>(PROPERTY.TRAVERSETO, this.hasTraverseTo, this.getTraverseToVar);
         }
@@ -58,7 +52,6 @@ namespace SmartAPI.Model
 
         public override void parse(Statement statement)
         {
-            if (this.parseProperty<Variant>(statement, PROPERTY.METHOD, this.setMethod)) return;
             if (this.parseProperty<Input>(statement, PROPERTY.HASINPUT, this.addInput)) return;
             if (this.parseProperty<Input>(statement, PROPERTY.HASREFINPUT, this.addRefInput)) return;
             if (this.parseProperty<Output>(statement, PROPERTY.HASOUTPUT, this.addOutput)) return;
@@ -67,7 +60,6 @@ namespace SmartAPI.Model
             if (this.parseProperty<Availability>(statement, PROPERTY.HASDATAAVAILABILITY, this.addDataAvailability)) return;
             if (this.parseProperty<InterfaceAddress>(statement, PROPERTY.INTERFACE, this.addInterface)) return;
             if (this.parseProperty<Entity>(statement, PROPERTY.ENTITY, this.addEntity)) return;
-            if (this.parseProperty<TemporalContext>(statement, PROPERTY.TEMPORALCONTEXT, this.setTemporalContext)) return;
             if (this.parseProperty<TimeSeries>(statement, PROPERTY.TIMESERIES, this.addTimeSeries)) return;
             if (this.parseProperty<Variant>(statement, PROPERTY.TRAVERSEUNTIL, this.setTraverseUntil)) return;
             if (this.parseProperty<Variant>(statement, PROPERTY.TRAVERSETO, this.setTraverseTo)) return;
@@ -75,37 +67,6 @@ namespace SmartAPI.Model
             base.parse(statement);
         }
 
-        public bool hasMethod()
-        {
-            return this.method != null;
-        }
-
-        public void setMethod(Variant v)
-        {
-            this.method = v;
-        }
-
-        public void setMethod(Uri v)
-        {
-            this.setMethod(new Variant(v));
-        }
-
-        public void setMethod(String v)
-        {
-            this.setMethod(new Variant(new Uri(v)));
-        }
-
-        public Uri getMethod()
-        {
-            if (this.method != null) return this.method.asUri();
-            return null;
-        }
-
-        public Variant getMethodVar()
-        {
-            return this.method;
-        }
-
         public bool hasInput()
         {
             return this.inputs.Count > 0;
@@ -311,57 +272,7 @@ namespace SmartAPI.Model
             this.addEntity(e);
             return e;
         }
-
-        public bool hasTemporalContext()
-        {
-            return this.temporalContext != null;
-        }
-
-        public void setTemporalContext(TemporalContext v)
-        {
-            this.temporalContext = v;
-        }
-
-        public void setTemporalContext(DateTime start, DateTime end)
-        {
-            TemporalContext v = new TemporalContext();
-            v.setStart(start);
-            v.setEnd(end);
-            this.temporalContext = v;
-        }
-
-        public void setTemporalContext(DateTime start)
-        {
-            TemporalContext v = new TemporalContext();
-            v.setStart(start);
-            this.temporalContext = v;
-        }
-
-        public TemporalContext getTemporalContext()
-        {
-            return this.temporalContext;
-        }
-
-        public bool hasTimeSeries()
-        {
-            return this.timeSeries.Count > 0;
-        }
-
-        public void setTimeSeries(List<TimeSeries> v)
-        {
-            this.timeSeries = v;
-        }
-
-        public List<TimeSeries> getTimeSeries()
-        {
-            return this.timeSeries;
-        }
-
-        public void addTimeSeries(TimeSeries v)
-        {
-            this.timeSeries.Add(v);
-        }
-
+        
         public bool hasTraverseUntil()
         {
             return this.traverseUntil != null;
index 3485884b43f5dedc706026e00cb79d63f8e6e12a..c0cc6164248308ec77b3efada79e3a09cae41990 100644 (file)
@@ -7,19 +7,17 @@ namespace SmartAPI.Model
 {
     public class Evaluation : ValueObject
     {
+        private Variant method = null;
         private List<Obj> categories = new List<Obj>();
         private List<TimeSeries> timeSeries = new List<TimeSeries>();
         private SystemOfInterest systemOfInterest = null;
-        private List<Activity> activities = new List<Activity>();
-        private List<ValueObject> valueObjects = new List<ValueObject>();
 
         private void init()
         {
+            this.initProperty<Variant>(PROPERTY.METHOD, this.hasMethod, this.getMethodVar);
             this.initPropertyList<List<Obj>, Obj>(PROPERTY.CATEGORY, this.hasCategories, this.getCategories);
             this.initPropertyList<List<TimeSeries>, TimeSeries>(PROPERTY.TIMESERIES, this.hasTimeSeries, this.getTimeSeries);
             this.initProperty<SystemOfInterest>(PROPERTY.SYSTEMOFINTEREST, this.hasSystemOfInterest, this.getSystemOfInterest);
-            this.initPropertyList<List<Activity>, Activity>(PROPERTY.ACTIVITY, this.hasActivities, this.getActivities);
-            this.initPropertyList<List<ValueObject>, ValueObject>(PROPERTY.VALUEOBJECT, this.hasValueObjects, this.getValueObjects);
         }
 
         public Evaluation()
@@ -42,15 +40,45 @@ namespace SmartAPI.Model
 
         public override void parse(Statement statement)
         {
-            if (this.parseProperty<Activity>(statement, PROPERTY.ACTIVITY, this.addActivity)) return;
+            if (this.parseProperty<Variant>(statement, PROPERTY.METHOD, this.setMethod)) return;
             if (this.parseProperty<Obj>(statement, PROPERTY.CATEGORY, this.addCategory)) return;
             if (this.parseProperty<TimeSeries>(statement, PROPERTY.TIMESERIES, this.addTimeSeries)) return;
             if (this.parseProperty<SystemOfInterest>(statement, PROPERTY.SYSTEMOFINTEREST, this.setSystemOfInterest)) return;
-            if (this.parseProperty<ValueObject>(statement, PROPERTY.VALUEOBJECT, this.addValueObject)) return;
 
             base.parse(statement);
         }
 
+        public bool hasMethod()
+        {
+            return this.method != null;
+        }
+
+        public void setMethod(Variant v)
+        {
+            this.method = v;
+        }
+
+        public void setMethod(Uri v)
+        {
+            this.setMethod(new Variant(v));
+        }
+
+        public void setMethod(String v)
+        {
+            this.setMethod(new Variant(new Uri(v)));
+        }
+
+        public Uri getMethod()
+        {
+            if (this.method != null) return this.method.asUri();
+            return null;
+        }
+
+        public Variant getMethodVar()
+        {
+            return this.method;
+        }
+
         public bool hasCategories()
         {
             return this.categories.Count > 0;
@@ -128,45 +156,5 @@ namespace SmartAPI.Model
         {
             return this.systemOfInterest;
         }
-        
-        public bool hasActivities()
-        {
-            return this.activities.Count > 0;
-        }
-
-        public void setActivities(List<Activity> v)
-        {
-            this.activities = v;
-        }
-
-        public List<Activity> getActivities()
-        {
-            return this.activities;
-        }
-
-        public void addActivity(Activity v)
-        {
-            this.activities.Add(v);
-        }
-
-        public bool hasValueObjects()
-        {
-            return this.valueObjects.Count > 0;
-        }
-
-        public void setValueObjects(List<ValueObject> v)
-        {
-            this.valueObjects = v;
-        }
-
-        public List<ValueObject> getValueObjects()
-        {
-            return this.valueObjects;
-        }
-
-        public void addValueObject(ValueObject v)
-        {
-            this.valueObjects.Add(v);
-        }
     }
 }
index 6be970a04513cb568de3d209259b3f91992f2a8f..d1bbcd47ca3e4880d8fc521f8aee9f1899358587 100644 (file)
@@ -6,7 +6,7 @@ using System.Collections.Generic;
 
 namespace SmartAPI.Model
 {
-    public class Provenance : Obj
+    public class Provenance : Evaluation
     {
         private List<Variant> generationMethods = new List<Variant>();
         private List<Variant> dataSources = new List<Variant>();
@@ -138,6 +138,5 @@ namespace SmartAPI.Model
             Uri p = new Uri(property);
             this.addProperty(p);
         }
-
     }
 }
index bd43f290e4fdd869322f909adba4f7c788df5455..187009bb4f9c76f4a33252c9c993bc8cb8ed8214 100644 (file)
@@ -6,7 +6,7 @@ using System.Collections.Generic;
 
 namespace SmartAPI.Model
 {
-    public class Restriction : Obj
+    public class Restriction : Evaluation
     {
         private Variant cardinality = null;
         private Variant minCardinality = null;
index 4827cf4c3d0482478250937b81e3621843c9b3cc..1ea9785bd376aa4240a1922c13d0b6eee0aad0dc 100644 (file)
@@ -42,13 +42,6 @@ namespace SmartAPI.tests
             Console.WriteLine("Parsed: ");
             Console.WriteLine(Tools.toString(parsed, SERIALIZATION.TURTLE));
             Console.WriteLine("Parsed identifier: " + parsed.getIdentifierUri());
-            Input ai = parsed.getFirstInput();
-            List<ValueObject> vos = ai.getValueObjects();
-            //List <Variant> vos = ai.get(PROPERTY.VALUEOBJECT);
-            Console.WriteLine("Number of value objects: " + vos.Count);
-            //ValueObject vo = (ValueObject)vos[0].asObj();
-            ValueObject vo = vos[0];
-            Console.WriteLine("Parsed quantity: " + vo.getQuantity());
             Console.WriteLine("Hash match: " + parsed.verifyHash());
             Console.WriteLine("Signature match: " + parsed.verifySignature(pubKey));