Permalink
Browse files

Added support for multiple schema in a single project

1 parent a5027b3 commit 76f6da5f3693c1b86754adf3015b81e162869caf @remkonoteboom remkonoteboom committed Sep 11, 2013
View
@@ -33,3 +33,7 @@ nosetests.xml
.mr.developer.cfg
.project
.pydevproject
+
+
+# VI swp files
+*.swp
View
@@ -209,6 +209,7 @@
# DEPRECATED
+"""
SCHEMA_XML['prod'] = '''<?xml version='1.0' encoding='UTF-8'?>
<schema parent="__NONE__">
<search_type name='prod/art_reference'/>
@@ -273,7 +274,9 @@
</schema>
'''
+"""
+"""
SCHEMA_XML['flash'] = '''<?xml version='1.0' encoding='UTF-8'?>
<schema parent="__NONE__">
<search_type name='prod/art_reference'/>
@@ -306,6 +309,7 @@
<connect to="*" from="prod/submission" type='hierarchy' relationship='search_type'/>
</schema>
'''
+"""
SCHEMA_XML['unittest'] = '''<?xml version='1.0' encoding='UTF-8'?>
@@ -384,7 +388,7 @@ def add_dependencies(my):
return
- # a schema has knowledge of it's parent
+ # a schema has knowledge of its parent
my.parent_schema = my.get_parent_schema()
# sthpw schema that everybody inherits from
@@ -429,10 +433,8 @@ def get_parent_schema(my):
return parent_schema
else:
- # try the project type
- # FIXME: assume schema code == project_code
+ # Note: assume schema code == project_code
schema_code = my.get_value("code")
- #assert schema_code and schema_code != "admin"
from pyasm.biz import Project
project = Project.get_by_code(schema_code)
@@ -1280,7 +1282,6 @@ def get_by_sobject(cls, sobject):
def get(cls, reset_cache=False):
-
if not reset_cache:
schema = Container.get("Schema")
if schema:
@@ -1290,14 +1291,14 @@ def get(cls, reset_cache=False):
project_code = Project.get_project_code()
# the predefined ones cannot be overriden
- #if project_code in ['prod', 'unittest', 'flash', 'admin']:
if project_code in ['unittest']:
schema = cls.get_predefined_schema(project_code)
schema.init()
sthpw_schema = cls.get_predefined_schema("admin")
sthpw_schema.init()
schema.sthpw_schema = sthpw_schema
- return schema
+ #return schema
+
elif project_code in ['sthpw','admin']:
sthpw_schema = cls.get_predefined_schema("admin")
sthpw_schema.init()
@@ -1310,14 +1311,17 @@ def get(cls, reset_cache=False):
# find using explicit search ... too much nested caching going
# on here. It is confusing when changing schema
search = Search("sthpw/schema")
- #search.add_op("begin")
- search.add_filter("code", project_code)
- #search.add_filter("project_code", project_code)
- #search.add_op("or")
+ search.add_op("begin")
+ if project_code not in ['unittest']:
+ search.add_filter("code", project_code)
+ search.add_filter("project_code", project_code)
+ search.add_op("or")
schemas = search.get_sobjects()
- #if len(schemas) > 1:
- if False:
+ if project_code in ['unittest']:
+ schemas.insert(0, schema)
+
+ if len(schemas) > 1:
schema = SearchType.create("sthpw/schema")
schema.set_value("code", project_code)
schema.set_value("project_code", project_code)
@@ -1340,6 +1344,9 @@ def get(cls, reset_cache=False):
elif schemas:
schema = schemas[0]
+ else:
+ schema = None
+
# if the project schema does not exist, then create an empty one
if not schema:
@@ -0,0 +1,74 @@
+###########################################################
+#
+# Copyright (c) 2005, Southpaw Technology
+# All Rights Reserved
+#
+# PROPRIETARY INFORMATION. This software is proprietary to
+# Southpaw Technology, and is not to be reproduced, transmitted,
+# or disclosed in any way without written permission.
+#
+#
+#
+
+__all__ = ["SchemaTest"]
+
+import tacticenv
+import os
+import unittest
+
+from pyasm.security import Batch
+
+from pyasm.unittest import UnittestEnvironment, Sample3dEnvironment
+
+from pyasm.search import SearchType, Search, Transaction
+from pyasm.biz import Project
+from schema import Schema
+
+class SchemaTest(unittest.TestCase):
+
+ def test_all(my):
+ Batch()
+ from pyasm.web.web_init import WebInit
+ WebInit().execute()
+
+ test_env = UnittestEnvironment()
+ test_env.create()
+ my.transaction = Transaction.get(create=True)
+ try:
+ my._test_multiple_schema()
+ finally:
+ my.transaction.rollback()
+ Project.set_project('unittest')
+
+ test_env.delete()
+
+
+ def _test_multiple_schema(my):
+
+ # add a second schema
+ new_schema = SearchType.create("sthpw/schema")
+ new_schema.set_value("project_code", "unittest")
+ new_schema.set_value("code", "second_schema")
+ new_schema.set_value("schema", '''
+<schema>
+ <search_type name="test/node1"/>
+ <search_type name="test/node2"/>
+ <search_type name="test/node3"/>
+ <search_type name="test/node4"/>
+ <connect from="test/node1" to="test/node2"/>
+ <connect from="test/node2" to="test/node3"/>
+ <connect from="test/node3" to="test/node4"/>
+</schema>''')
+ new_schema.commit()
+
+ schema = Schema.get(reset_cache=True)
+ print schema.get_value("schema")
+
+
+
+
+if __name__ == '__main__':
+ unittest.main()
+
+
+
@@ -192,7 +192,8 @@ def import_schema(my, db_resource, type):
schema_dir = my.get_schema_dir()
schema_path = "%s/%s_schema.sql" % (schema_dir, schema_type)
if not os.path.exists(schema_path):
- Environment.add_warning("Schema does not exist", "Schema '%s' does not exist" % schema_path)
+ # This warning occurs too often in harmless places
+ #Environment.add_warning("Schema does not exist", "Schema '%s' does not exist" % schema_path)
continue
my.import_sql_file(db_resource, schema_path)
@@ -1018,7 +1018,8 @@ def get_unique_sobject(my, sobject):
def import_data(my, path, commit=True, unique=False):
if not os.path.exists(path):
- print "WARNING: path [%s] does not exist" % path
+ # This is printed too often in harmless situations
+ #print "WARNING: path [%s] does not exist" % path
return []
#f = codecs.open(path, 'r', 'utf-8')
@@ -960,10 +960,6 @@ def get_onload_js(my):
spt.pipeline.top = null;
-var xxxcanvas = null;
-var xxxpaint = null;
-var xxxctx = null;
-
// External method to initialize callback
spt.pipeline.init_cbk = function(common_top) {
@@ -1356,8 +1356,8 @@ def get_zoom_buttons_wdg(my):
from tactic.ui.widget.button_new_wdg import ButtonNewWdg, ButtonRowWdg, IconButtonWdg, SingleButtonWdg
button_row = DivWdg()
- button_row.add_border()
- button_row.set_round_corners(5)
+ #button_row.add_border()
+ #button_row.set_round_corners(5)
button_row.add_style("padding: 6px 10px 9px 5px")
button = SingleButtonWdg(title="Zoom In", icon=IconWdg.ZOOM_IN, show_out=False)
@@ -102,7 +102,11 @@ def get_display(my):
not_has_tables = {}
sthpw_types = {}
sthpw_project = Project.get_by_code('sthpw')
- schema = Schema.get()
+
+
+ #schema = Schema.get()
+ schema = Search.get_by_code("sthpw/schema", project_code)
+
search_types = schema.get_search_types(hierarchy=False)
for search_type in search_types:
project = current_project
@@ -124,6 +128,13 @@ def get_display(my):
except SearchException, e:
not_exists[search_type] = True
+
+ search = Search("sthpw/schema")
+ search.add_filter("project_code", project_code)
+ search.add_filter("code", project_code, op="!=")
+ extra_schemas = search.get_sobjects()
+ extra_schema_codes = [x.get_code() for x in extra_schemas]
+
div = DivWdg()
inner.add(div)
div.add_behavior( {
@@ -133,10 +144,14 @@ def get_display(my):
'not_has_tables': not_has_tables,
'sthpw_types': sthpw_types,
'project_code': project_code,
+ 'extra_schemas': extra_schema_codes,
'cbjs_action': '''
var top = bvr.src_el.getParent('.spt_schema_tool_top');
spt.pipeline.init_cbk(top);
spt.pipeline.import_schema( bvr.project_code );
+ for (var i = 0; i < bvr.extra_schemas.length; i++) {
+ spt.pipeline.import_schema( bvr.extra_schemas[i] );
+ }
for (search_type in bvr.exists) {
var node = spt.pipeline.get_node_by_name(search_type);
@@ -151,14 +166,12 @@ def get_display(my):
node.spt_registered = false;
}
-
for (search_type in bvr.sthpw_types) {
var node = spt.pipeline.get_node_by_name(search_type);
spt.pipeline.set_color(node, "#AA7");
spt.pipeline.enable_node(node);
}
-
for (search_type in bvr.not_has_tables) {
var node = spt.pipeline.get_node_by_name(search_type);
spt.pipeline.set_color(node, "#A33");
@@ -630,7 +643,7 @@ def get_tab_wdg(my):
def get_canvas(my):
my.height = my.kwargs.get("height")
if not my.height:
- my.height = 300
+ my.height = 400
my.width = my.kwargs.get("width")
return SchemaToolCanvasWdg(height=my.height, width=my.width, dialog_id=my.dialog_id, nob_mode="dynamic", line_mode='line', has_prefix=True, filter_node_name=True)

0 comments on commit 76f6da5

Please sign in to comment.