Skip to content

Commit

Permalink
code clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
lazarocosta committed Mar 9, 2020
1 parent fe6664a commit 21291fa
Show file tree
Hide file tree
Showing 13 changed files with 147 additions and 82 deletions.
5 changes: 3 additions & 2 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
},
"private": true,
"dependencies": {
"@ajsf/material": "^0.1.3",
"@angular/animations": "~9.0.0",
"@angular/cdk": "~9.0.0-rc.10",
"@angular/common": "~9.0.0",
Expand All @@ -30,9 +31,9 @@
"@angular/cli": "~9.0.1",
"@angular/compiler-cli": "~9.0.0",
"@angular/language-service": "~9.0.0",
"@types/node": "^12.11.1",
"@types/jasmine": "~3.5.0",
"@types/jasminewd2": "~2.0.3",
"@types/node": "^12.11.1",
"codelyzer": "^5.1.2",
"jasmine-core": "~3.5.0",
"jasmine-spec-reporter": "~4.2.1",
Expand All @@ -46,4 +47,4 @@
"tslint": "~5.18.0",
"typescript": "~3.7.5"
}
}
}
10 changes: 10 additions & 0 deletions frontend/src/app/components/example.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,13 @@
</label>
<button type="submit" >Submit</button>
</form>

<!--
<json-schema-form
loadExternalAssets="true"
[schema]="yourJsonSchema"
framework="no-framework"
(onSubmit)="yourOnSubmitFn($event)">
</json-schema-form>
-->
33 changes: 33 additions & 0 deletions frontend/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,24 @@
# yarn lockfile v1


"@ajsf/core@^0.1.3":
version "0.1.3"
resolved "https://registry.yarnpkg.com/@ajsf/core/-/core-0.1.3.tgz#0c314142e5ec863ab4da1d1bbb56fd7df4aa26e0"
integrity sha512-fFJQMbtjWkMu10JGhUbdPUy2RXiXlHgBIc27AVBbRDa9/v621McHERsboscvCg7VbnI6pW4ZKXkCUnQLlM1mVA==
dependencies:
ajv "^6.10.0"
lodash-es "^4.17.15"
tslib "^1.9.0"

"@ajsf/material@^0.1.3":
version "0.1.3"
resolved "https://registry.yarnpkg.com/@ajsf/material/-/material-0.1.3.tgz#fefbefa4e15b43caa1c2f78d7463a181ee71d952"
integrity sha512-HTTgBi5EhgAwpR1zqccK0lAj0HxEo8I/tvoU7OAyEYQwcGKq+QMAvKvuSRO0vTZq0ueqakeke2S7SfurWSQHUw==
dependencies:
"@ajsf/core" "^0.1.3"
lodash-es "^4.17.15"
tslib "^1.9.0"

"@angular-devkit/architect@0.900.1":
version "0.900.1"
resolved "https://registry.yarnpkg.com/@angular-devkit/architect/-/architect-0.900.1.tgz#60a39a388d1af24b64f01c16d852777e955d76da"
Expand Down Expand Up @@ -1266,6 +1284,16 @@ ajv@^6.1.0, ajv@^6.10.2, ajv@^6.5.5:
json-schema-traverse "^0.4.1"
uri-js "^4.2.2"

ajv@^6.10.0:
version "6.12.0"
resolved "https://registry.yarnpkg.com/ajv/-/ajv-6.12.0.tgz#06d60b96d87b8454a5adaba86e7854da629db4b7"
integrity sha512-D6gFiFA0RRLyUbvijN74DWAjXSFxWKaWP7mldxkVhyhAV3+SWA9HEJPHQ2c9soIeTFJqcSdFDGFgdqs1iUU2Hw==
dependencies:
fast-deep-equal "^3.1.1"
fast-json-stable-stringify "^2.0.0"
json-schema-traverse "^0.4.1"
uri-js "^4.2.2"

alphanum-sort@^1.0.0:
version "1.0.2"
resolved "https://registry.yarnpkg.com/alphanum-sort/-/alphanum-sort-1.0.2.tgz#97a1119649b211ad33691d9f9f486a8ec9fbe0a3"
Expand Down Expand Up @@ -4921,6 +4949,11 @@ locate-path@^5.0.0:
dependencies:
p-locate "^4.1.0"

lodash-es@^4.17.15:
version "4.17.15"
resolved "https://registry.yarnpkg.com/lodash-es/-/lodash-es-4.17.15.tgz#21bd96839354412f23d7a10340e5eac6ee455d78"
integrity sha512-rlrc3yU3+JNOpZ9zj5pQtxnx2THmvRykwL4Xlxoa8I9lHBlVbbyPhgyPMioxVZ4NqyxaVVtaJnzsyOidQIhyyQ==

lodash.clonedeep@^4.5.0:
version "4.5.0"
resolved "https://registry.yarnpkg.com/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz#e23f3f9c4f8fbdde872529c1071857a086e5ccef"
Expand Down
17 changes: 7 additions & 10 deletions src/Models/DataObject/v0_0_2/Approximate.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,17 @@
from marshmallow import Schema, fields
from marshmallow_jsonschema import JSONSchema
from neomodel import DateTimeProperty

from src.Models.DataObject.v0_0_2 import SerializeClass
from src.Models.DataObject.v0_0_2.Date import Date


class Approximate(Date):
approximateDateValue = DateTimeProperty(unique_index=True, required=True)
class ApproximateSchema(Schema):
approximateDateValue = fields.Date(required=True)

def toJSON(self):
return json.dumps(self, default=lambda o: o.__dict__)

def getSchema(self):
approximate_schema = ApproximateSchema()
json_schema = JSONSchema()
return json_schema.dump(approximate_schema)
class Approximate(Date):
super(SerializeClass).__init__(ApproximateSchema)
approximateDateValue = DateTimeProperty(unique_index=True, required=True)


class ApproximateSchema(Schema):
approximateDateValue = fields.Date(required=True)
42 changes: 29 additions & 13 deletions src/Models/DataObject/v0_0_2/DataObject.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,39 @@
import json

from marshmallow import Schema, fields
from marshmallow_jsonschema import JSONSchema
from neomodel import StringProperty, StructuredNode, UniqueIdProperty
from neomodel import StringProperty, StructuredNode, UniqueIdProperty, config

from src.Models.DataObject.v0_0_2.SerializeClass import SerializeClass

class DataObject(StructuredNode):
uid = UniqueIdProperty()
name = StringProperty(unique_index=True, required=True)

def toJSON(self):
return json.dumps(self, default=lambda o: o.__dict__)

def getSchema(self):
data_object_schema = DataObjectSchema()
json_schema = JSONSchema()
return json_schema.dump(data_object_schema)
config.DATABASE_URL = 'bolt://neo4j:password@localhost:7687'
#from src.GCF.utils.db import clean_database
#clean_database()


class DataObjectSchema(Schema):
uid = fields.String()
name = fields.String(required=True)


class DataObject(StructuredNode, SerializeClass, Schema):
name = StringProperty(unique_index=True, required=True)
uid = UniqueIdProperty()

# def __init__(self, *args, **kwargs):
# super().__init__(*args, **kwargs)
# SerializeClass.__init__(self, schema=DataObjectSchema())
# self.list.extend([self.uid, self.name])

def __init__(self, schema, *args, **kwargs):
super().__init__(*args, **kwargs)
SerializeClass.__init__(self, schema=DataObjectSchema())
self.list.extend([self.uid, self.name])


#ola =DataObject(name="ola").save()
# #ola.getSchema()
# print(ola.toJSON())
# ola.nodes.get(name="ola")



13 changes: 4 additions & 9 deletions src/Models/DataObject/v0_0_2/Instant.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,12 @@
from src.Models.DataObject.v0_0_2.Date import Date


class InstantSchema(Schema):
timestamp = fields.Date(required=True)


class Instant(Date):
timestamp = DateTimeProperty(unique_index=True, required=True)

def toJSON(self):
return json.dumps(self, default=lambda o: o.__dict__)

def getSchema(self):
instant_schema = InstantSchema()
json_schema = JSONSchema()
return json_schema.dump(instant_schema)


class InstantSchema(Schema):
timestamp = fields.Date(required=True)
20 changes: 8 additions & 12 deletions src/Models/DataObject/v0_0_2/Interval.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
import json

from marshmallow import Schema, fields
from marshmallow_jsonschema import JSONSchema
from neomodel import DateTimeProperty

from src.Models.DataObject.v0_0_2 import SerializeClass
from src.Models.DataObject.v0_0_2.Date import Date


class IntervalSchema(Schema):
startDateValue = fields.Date(required=True)
endDateValue = fields.Date(required=True)


class Interval(Date):
super(SerializeClass).__init__(IntervalSchema)
startDateValue = DateTimeProperty(unique_index=True, required=True)
endDateValue = DateTimeProperty(unique_index=True, required=True)

def toJSON(self):
return json.dumps(self, default=lambda o: o.__dict__)

def getSchema(self):
interval_schema = IntervalSchema()
json_schema = JSONSchema()
return json_schema.dump(interval_schema)


class IntervalSchema(Schema):
startDateValue = fields.Date(required=True)
endDateValue = fields.Date(required=True)
17 changes: 7 additions & 10 deletions src/Models/DataObject/v0_0_2/PersonName.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,17 @@
from marshmallow import Schema, fields
from marshmallow_jsonschema import JSONSchema
from neomodel import StringProperty

from src.Models.DataObject.v0_0_2 import SerializeClass
from src.Models.DataObject.v0_0_2.AuthorityString import AuthorityString


class PersonName(AuthorityString):
name = StringProperty(unique_index=True, required=True)
class PersonNameSchema(Schema):
name = fields.String(required=True)

def toJSON(self):
return json.dumps(self, default=lambda o: o.__dict__)

def getSchema(self):
person_name_schema = PersonNameSchema()
json_schema = JSONSchema()
return json_schema.dump(person_name_schema)
class PersonName(AuthorityString):
super(SerializeClass).__init__(PersonNameSchema)
name = StringProperty(unique_index=True, required=True)


class PersonNameSchema(Schema):
name = fields.String(required=True)
18 changes: 9 additions & 9 deletions src/Models/DataObject/v0_0_2/RegexString.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
from marshmallow import Schema, fields
from marshmallow_jsonschema import JSONSchema
from neomodel import RegexProperty

from src.Models.DataObject.v0_0_2 import SerializeClass
from src.Models.DataObject.v0_0_2.String import String


class RegexString(String):
class RegexStringSchema(Schema):
hasRegex = fields.String(required=True)


class RegexString(String, SerializeClass):
super(SerializeClass).__init__(RegexStringSchema)
hasRegex = RegexProperty(unique_index=True, required=True)

def toJSON(self):
return json.dumps(self, default=lambda o: o.__dict__)

def getSchema(self):
regex_string_schema = RegexStringSchema()
json_schema = JSONSchema()
return json_schema.dump(regex_string_schema)


class RegexStringSchema(Schema):
hasRegex = fields.String(required=True)

16 changes: 16 additions & 0 deletions src/Models/DataObject/v0_0_2/SerializeClass.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import json
from marshmallow import Schema, fields
from marshmallow_jsonschema import JSONSchema


class SerializeClass:
def __init__(self, schema):
self.list = []
self.schema = schema

def getSchema(self):
json_schema = JSONSchema()
return json_schema.dump(self.schema)

def toJSON(self):
return json.dumps(self.list, default=lambda o: o.__dict__)
25 changes: 15 additions & 10 deletions src/Models/DataObject/v0_0_2/String.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
import json

from marshmallow import Schema, fields
from marshmallow_jsonschema import JSONSchema
from neomodel import StringProperty
from src.Models.DataObject.v0_0_2.DataObject import DataObject
from src.Models.DataObject.v0_0_2.SerializeClass import SerializeClass


class StringSchema(Schema):
stringValue = fields.String(required=True)


# class String(DataObject):
# stringValue = StringProperty(unique_index=True, required=True)
#
# def __init__(self, *args, **kwargs):
# super().__init__(*args, **kwargs)
# self.list.append(self.stringValue)

class String(DataObject):
stringValue = StringProperty(unique_index=True, required=True)

def toJSON(self):
return json.dumps(self, default=lambda o: o.__dict__)

def getSchema(self):
string_schema = StringSchema()
json_schema = JSONSchema()
return json_schema.dump(string_schema)
def __init__(self, *args, **kwargs):
super().__init__(StringSchema(), *args, **kwargs)
self.list.append(self.stringValue)


class StringSchema(Schema):
stringValue = fields.String(required=True)
8 changes: 2 additions & 6 deletions src/Routes/routes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from flask import Flask, jsonify

from flask import Flask, jsonify, Response
from neomodel import config
from src.Models.DataObject.v0_0_2.String import String

Expand All @@ -10,10 +9,7 @@
@app.route("/<uid>", methods=["GET"])
def view(uid):
returned_string = String.nodes.get(uid=uid)
return jsonify(returned_string.toJSON())
# returned_string = String.nodes.get(uid=uid)
# return Response(dumps(returned_string.toJSON()),
# mimetype='application/json')
return Response(returned_string.toJSON(), mimetype='application/json')


@app.route("/schema/<uid>", methods=["GET"])
Expand Down
5 changes: 4 additions & 1 deletion test/Unit/test_data_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

from neomodel import (config, OUTGOING, Traversal, DeflateError,
AttemptedCardinalityViolation)
import json
from src.GCF.utils.db import clean_database
clean_database()

config.DATABASE_URL = 'bolt://neo4j:password@localhost:7687'

Expand All @@ -15,6 +16,8 @@ class TestString(unittest.TestCase):
def test_create_update_string_Node(self):
date = datetime.datetime.now().strftime("%H:%M:%S")
string = String(name=date, stringValue="String_Value").save()
print(string.getSchema())
print(string.toJSON())
returned_string = String.nodes.get(name=date)
new_name = "new_Name"
returned_string.stringValue = new_name
Expand Down

0 comments on commit 21291fa

Please sign in to comment.