C++: Add simpla search of duplicate price components in price list
authorjani <jani@asema.com>
Mon, 24 Jun 2019 11:13:30 +0000 (14:13 +0300)
committerjani <jani@asema.com>
Mon, 24 Jun 2019 11:13:30 +0000 (14:13 +0300)
13 files changed:
Common/C++/SmartAPI/build.sh
Common/C++/SmartAPI/smartapi/model/PriceListSpecification.cpp
Common/C++/SmartAPI/smartapi/model/PriceListSpecification.h
Common/C++/SmartAPI/smartapi/rdf/Literal.h
Common/C++/SmartAPI/tests/TestSequences.cpp
Common/Java/SmartAPI/src/smartapi/common/ConceptValidator.java
Common/Java/SmartAPI/src/smartapi/common/Tools.java
Common/Java/SmartAPI/src/smartapi/tests/TestRegistrationServer.java
Common/Java/SmartAPI/src/smartapi/tests/TestRegistrations.java [moved from Common/Java/SmartAPI/src/smartapi/tests/testOrientdb.java with 99% similarity]
Common/Python/SmartAPI/common/ConceptValidator.py
Examples/Java/CoffeeMakerFor10Cups/src/acme/MainClass.java
Examples/Python/CustomPropertiesAndClassesSample/smartapi_server_client_sample.py
Ontology/src/1.0/DataOntology-1.0.ttl

index ad6e3617a719df0be455870ad553807f1ab642b3..e4f66af3616f987d964ab700b313884b635d5dc8 100755 (executable)
@@ -1,11 +1,11 @@
 #!/bin/bash
 
-/opt/Qt5.11/5.11.0/gcc_64/bin/qmake smartapi.pro -o Makefile.lib && \
-/opt/Qt5.11/5.11.0/gcc_64/bin/qmake smartapitests.pro -o Makefile.objecttests && \
-/opt/Qt5.11/5.11.0/gcc_64/bin/qmake smartapitests.pro -o Makefile.agenttests && \
-/opt/Qt5.11/5.11.0/gcc_64/bin/qmake smartapigraphtests.pro -o Makefile.graphtests && \
-/opt/Qt5.11/5.11.0/gcc_64/bin/qmake smartapiplugintests.pro -o Makefile.plugintests && \
-/opt/Qt5.11/5.11.0/gcc_64/bin/qmake smartapiplugin.pro -o Makefile.plugin && \
+/opt/Qt5.11/5.12.2/gcc_64/bin/qmake smartapi.pro -o Makefile.lib && \
+/opt/Qt5.11/5.12.2/gcc_64/bin/qmake smartapitests.pro -o Makefile.objecttests && \
+/opt/Qt5.11/5.12.2/gcc_64/bin/qmake smartapitests.pro -o Makefile.agenttests && \
+/opt/Qt5.11/5.12.2/gcc_64/bin/qmake smartapigraphtests.pro -o Makefile.graphtests && \
+/opt/Qt5.11/5.12.2/gcc_64/bin/qmake smartapiplugintests.pro -o Makefile.plugintests && \
+/opt/Qt5.11/5.12.2/gcc_64/bin/qmake smartapiplugin.pro -o Makefile.plugin && \
 \
 make -f Makefile.lib -j 3 && \
 make -f Makefile.objecttests -j 2 && \
index acd3272b044bcecf3801a9f2699b6b43a81aece8..47a5d7bc96f91dcecee7853822ec6dfe0059c147 100644 (file)
@@ -60,3 +60,14 @@ bool PriceListSpecification::isTimeDependent()
        }
        return isDependent;
 }
+
+bool PriceListSpecification::hasPriceSpecification(QString identifier)
+{
+       for (PropertyListItem<PriceSpecification*>* i = mPriceSpecifications.firstItem(); i != NULL; i = i->next()) {
+               if (i->getItem() &&i->getItem()->getIdentifierUri() == identifier)
+                       return true;
+       }
+       return false;
+}
+
+
index 1d5dc6b339b33a659b54f3e6869c54cce164b4d5..3c9652912592ffab8ebec18a858c6345d449309e 100644 (file)
@@ -16,6 +16,7 @@ public:
        virtual void clearReferences(QSet<GraphItem*>* trash);
 
        bool hasPriceSpecification()                                                                            { return (mPriceSpecifications.length() > 0); }
+       bool hasPriceSpecification(QString identifier);
        void addPriceSpecification(PriceSpecification* priceSpecification)      { mPriceSpecifications.append(priceSpecification); }
        PropertyList<PriceSpecification*> getPriceSpecifications()                      { return mPriceSpecifications; }
 
index 51a56198a872079b2de78b07a82abb9062168347..8ae9999bac1d496372ec0993514e035a40db786c 100644 (file)
@@ -11,7 +11,7 @@ class Literal : public RDFNode
 public:
        Literal(QVariant v, QString d) : RDFNode(NodeType::NodeLiteral) {
                value = v;
-        dataType = QUrl(d);
+               dataType = QUrl(d);
        }
 
        QString getValue() { return value.toString(); }
index 2cf0b6ae1d79df79dd9207456c81db5f4b9649bf..55293cd65b8dd2e595a22cf38f79de7efab8c4ea 100644 (file)
@@ -12,6 +12,7 @@
 #include <QJsonDocument>
 #include <QJsonObject>
 #include <QElapsedTimer>
+#include <QRegularExpression>
 #include <openssl/rand.h>
 #include <unistd.h>
 
index f421c7cfa674df925dc9fdf34e2b49894f672f5c..51ecc3d1ea5035c70e7c5e89fed46237dc76f222 100644 (file)
@@ -20,8 +20,8 @@ import smartapi.agents.OntologyAgent;
 import smartapi.model.Grading;
 import smartapi.model.Obj;
 
-public class ConceptValidator {
-
+public class ConceptValidator
+{
        private static HashMap<String, ConceptDetails> concepts = new HashMap<String, ConceptDetails>();
 
        static
@@ -76,16 +76,19 @@ public class ConceptValidator {
                }
                try {
                        InputStream in = null;
+                       
                        // for jar package and eclipse
                        try {
                                in = new FileInputStream((new File(OntologyAgent.ontologyFolderPath + prefix + ".ttl")));
                        } catch ( FileNotFoundException e ) {
                                // nothing to do, because probably running with Maven
                        }
+                       
                        // for maven
                        if (in == null) {
                                in = FileManager.get().open(prefix  + ".ttl");
                        }
+                       
                        if ( !handleOntology(prefix, in, SERIALIZATION.TURTLE) ) {
                                System.err.println("Failed to load " + prefix + " ontology from " + OntologyAgent.ontologyFolderPath + prefix + ".ttl");                                        
                        }
@@ -121,6 +124,7 @@ public class ConceptValidator {
                Property commentProp = model.createProperty(PROPERTY.getUri(PROPERTY.COMMENT));
                // iterate over subjects in model
                ResIterator i = model.listSubjects();
+               
                while ( i.hasNext() ) {
                        Resource resource = i.next();
                        // if resource has uri
index 896577cecd87eca5e0f26f80421afada85405187..c2807a2179be7f27b39929ba9eb1bfb5f5278bf6 100644 (file)
@@ -192,7 +192,7 @@ public class Tools {
                                System.err.println("Unable to parse MQTT message.");
                                e.printStackTrace();
                                return null;
-                       }                       
+                       }
                }
                return Tools.parseMessage(clazz, body, contentType);
        }
index 83c8099332aa32f156d6c4eed85cae2c4ef7fa6c..4e0a89d9bc2ad2c51e99dd9570c34d3344f3a42b 100644 (file)
@@ -14,12 +14,8 @@ public class TestRegistrationServer {
 
        String myIdentity;
 
-       String myIdentityPrefix = "http://seas.asema.com/registrationservertest/";
-
-       //String registrationUri = "http://seas.asema.com/webapps/rs/v1.0e1.0/register";
+       String myIdentityPrefix = "http://www.smart-api.io/registrationservertest/";
        String registrationUri = "http://development.asema.com:8080/app-core/smartapi/v1.0e1.0/access";
-
-       //String searchUri = "http://seas.asema.com/webapps/rs/v1.0e1.0/search";
        String rsSearchUri = "http://development.asema.com:8080/app-core/smartapi/v1.0e1.0/access";
 
        public TestRegistrationServer()
@@ -53,7 +49,7 @@ public class TestRegistrationServer {
                        s.setName("Registration Server Test Service");
                        Activity a = new Activity();
                        s.addCapability(a);
-                       s.setCoordinates(60.180824, 24.832116);
+                       s.setCoordinates(62.180824, 21.832116);
                        agent.debugMode(true);
                        Response r = agent.registrate(s);
                        if ( r == null || r.hasErrors() ) {
similarity index 99%
rename from Common/Java/SmartAPI/src/smartapi/tests/testOrientdb.java
rename to Common/Java/SmartAPI/src/smartapi/tests/TestRegistrations.java
index bf09cdcea53d25b28ddfdaee7a3da67331527c60..97f0f4aa24c3a97a2dfe29bb296d93a73c85f4f0 100644 (file)
@@ -8,7 +8,7 @@ import smartapi.common.RESOURCE;
 import smartapi.factory.Factory;
 import smartapi.model.*;
 
-public class testOrientdb {
+public class TestRegistrations {
        
          public static void regst5()
       {
index 2a4dd44189490b7ec1a0c65fa45c8728c55f093c..39721e5461f0b87696d9ff48c97d9624f3366bbe 100644 (file)
@@ -13,7 +13,8 @@ import os
 from rdflib import Graph, URIRef
 
 concepts = {}
-def initConcepts():    
+
+def initConcepts():
     ontUpdated = OntologyAgent.updateOntologies()
     
     if ontUpdated or len(concepts)==0:
@@ -26,20 +27,20 @@ def initConcepts():
     #             format = None
     #         else:
     #             format = 'xml'
-            g = Graph()        
+            g = Graph()
             g.parse(ontFile, format = 'turtle')
             subs = g.subjects()
             for s in subs:
                 if isinstance(s, URIRef):
                     label = g.label(s)
                     comment = g.comment(s)
-                    concepts[str(s)] = (label, comment)          
+                    concepts[str(s)] = (label, comment)
         print 'ConceptValidator has been initialized. It has ', len(concepts), ' concepts.'
     
 
 class ConceptValidator(object):
     initConcepts() # only execute once. It generates information needed by explain()
-            
+    
     @classmethod
     def validate(cls, obj):
         '''
@@ -49,7 +50,7 @@ class ConceptValidator(object):
         from sets import Set
         
         initConcepts() # in case update is needed, for example when suddenly ontology has been updated in backend server.
-                
+        
         grading = Grading()
         
         # get rdf model out of this SmartAPI Obj
@@ -67,17 +68,19 @@ class ConceptValidator(object):
         # subject has to have rdf:Type statement, to define its type
         subs = graph.subjects()
         subjectSet = Set()
+        
         for sub in subs:
             subjectSet.add(sub)
+        
         for sub in subjectSet:
             if not (sub, URIRef(PROPERTY.RDF_TYPE), None) in graph:
                 e = Error()
                 e.addType(RESOURCE.UNDEFINEDCONCEPTERROR)
-                e.setDescription("Found subject is not defined by rdf:Type statement (" + str(sub) + ").")              
+                e.setDescription("Found subject is not defined by rdf:Type statement (" + str(sub) + ").")
                 grading.addError(e)
-                conceptErrorCount = conceptErrorCount+1       
+                conceptErrorCount = conceptErrorCount+1
         
-        # validate all triples, check whether they have been defined in ontology        
+        # validate all triples, check whether they have been defined in ontology
         for s, p, o in graph:
             numberOfTestedTriples = numberOfTestedTriples+1
             
@@ -86,9 +89,9 @@ class ConceptValidator(object):
                 # undefined property
                 e = Error()
                 e.addType(RESOURCE.UNDEFINEDCONCEPTERROR)
-                e.setDescription("Found property is not defined in any of the inspected ontologies (" + str(p) + ").")                            
+                e.setDescription("Found property is not defined in any of the inspected ontologies (" + str(p) + ").")
                 grading.addError(e)
-                conceptErrorCount = conceptErrorCount+1            
+                conceptErrorCount = conceptErrorCount+1
             
             # some property's object has to be URIRef, and defined in ontology 
             if str(p) in [PROPERTY.RDF_TYPE, PROPERTY.METHOD, PROPERTY.QUANTITYKIND, PROPERTY.UNIT, PROPERTY.CATEGORY,
@@ -99,7 +102,7 @@ class ConceptValidator(object):
                     # object is wrong data type
                     e = Error()
                     e.addType(RESOURCE.ILLEGALVALUEERROR)
-                    e.setDescription("Value of " + str(p) + " should be a URI resource, found " + str(o) + ".")                    
+                    e.setDescription("Value of " + str(p) + " should be a URI resource, found " + str(o) + ".")
                     grading.addError(e)
                     valueErrorCount = valueErrorCount+1
                 else:
@@ -120,9 +123,9 @@ class ConceptValidator(object):
         if ( conceptErrorCount > 0 ):
             # calculate concept grade from 0 to 10
             conceptGrade = (1 - conceptErrorCount/numberOfTestedTriples) * 10.0
-                                    
+            
         grading.setValueGrade(valueGrade)
-        grading.setConceptGrade(conceptGrade)                        
+        grading.setConceptGrade(conceptGrade)
         grading.setGrade((valueGrade+conceptGrade)/2.0)
         
         return grading
index 10ad3c4cc682d201afe882ec482690ee63b8c203..c9de481c447a5c0723083de5a7b4a829e044a782 100644 (file)
@@ -88,5 +88,4 @@ public class MainClass {
                System.out.println(Tools.toString(coffeeMakerFor10Cups));
                
        }
-       
 }
index d13741258e3fd7de32408dbd3c6440d5b7776382..1854784fd7d6ee21f3f9d84734e11443144583aa 100755 (executable)
@@ -297,7 +297,7 @@ class SampleServerActivityProcessor1(object):
                                        response_activity.addEntity(resp_entity)
                        else:
                                pass
-                       
+               
                return response_activity
        
        
index e2fef2ae3d7eed83c767ac231ef9cbcba9ecf955..8b56305613fc093edd2d5721cc25d1c57ffb6afe 100644 (file)
@@ -248,7 +248,7 @@ smartapi:Instant a owl:Class ;
   rdfs:isDefinedBy smartapi:DataOntology ;
   rdfs:subClassOf smartapi:TemporalEntity;
   vs:term_status "testing".
-  
+
 smartapi:instant a owl:DatatypeProperty ;
   rdfs:label "Instant"@en ;
   rdfs:comment "A timestamp of the data."@en ;