diff --git a/common/admin/mocha-libexec/internal/librarymanager/LibraryManager.py b/common/admin/mocha-libexec/internal/librarymanager/LibraryManager.py index f383106..cdf39cc 100644 --- a/common/admin/mocha-libexec/internal/librarymanager/LibraryManager.py +++ b/common/admin/mocha-libexec/internal/librarymanager/LibraryManager.py @@ -30,6 +30,37 @@ class MochaLibraryManager: for op in self._operations: op.execute(self.db) + cur = self.db.cursor() + cur.execute("SELECT * FROM mocha_instances") + rows = cur.fetchall() + # print(rows) + + print ("ok , applying `Class.has Instance`...") + + for row in rows: + print(row) + id = row[0] + tenant_id = row[1] + class_id = row[2] + inst_id = row[3] + global_identifier = row[4] + + if class_id is not None and id is not None: + + # Class.has Instance + query2 = ("CALL mocha_assign_relationship (" + + "mocha_get_instance_by_key(1, " + str(class_id) + "), " + + "mocha_get_instance_by_global_identifier(mocha_normalize_uuid('7EB41D3C-2AE9-4884-83A4-E59441BCAEFB'))" + ", " + + str(id) + ", NULL, NULL)") + cur.execute(query2) + + # Instance.for Class + query3 = ("CALL mocha_assign_relationship (" + + str(id) + ", " + + "mocha_get_instance_by_global_identifier(mocha_normalize_uuid('494D5A6D-04BE-477B-8763-E3F57D0DD8C8'))" + ", " + + "mocha_get_instance_by_key(1, " + str(class_id) + "), NULL, NULL)") + cur.execute(query3) + self.db.commit() def close(self): diff --git a/common/libraries/yaml/net.alcetech.Mocha.System@20231121T2131-0500/003-Classes/00001-Class.yaml b/common/libraries/yaml/net.alcetech.Mocha.System@20231121T2131-0500/003-Classes/00001-Class.yaml index 49d59ef..e01a08f 100644 --- a/common/libraries/yaml/net.alcetech.Mocha.System@20231121T2131-0500/003-Classes/00001-Class.yaml +++ b/common/libraries/yaml/net.alcetech.Mocha.System@20231121T2131-0500/003-Classes/00001-Class.yaml @@ -15,162 +15,3 @@ - language: '&IDI_Language_English;' - value: 'Class' -- relationship: '&IDR_Class__has__Attribute;' - index: 1 - sourceClassId: '&IDC_Class;' - type: 'has' - destinationClassId: '&IDC_Attribute;' - siblingRelationshipId: '&IDR_Attribute__for__Class;' - singular: no - -- relationship: '&IDR_Attribute__for__Class;' - index: 2 - sourceClassId: '&IDC_Attribute;' - type: 'for' - destinationClassId: '&IDC_Class;' - siblingRelationshipId: '&IDR_Class__has__Attribute;' - singular: no - -- relationship: '&IDR_Class__has__Relationship;' - index: 3 - sourceClassId: '&IDC_Class;' - type: 'has' - destinationClassId: '&IDC_Relationship;' - siblingRelationshipId: '&IDR_Relationship__for__Class;' - singular: no - -- relationship: '&IDR_Relationship__for__Class;' - index: 4 - sourceClassId: '&IDC_Relationship;' - type: 'for' - destinationClassId: '&IDC_Class;' - siblingRelationshipId: '&IDR_Class__has__Attribute;' - singular: no - -- relationship: '&IDR_Relationship__has_sibling__Relationship;' - index: 5 - sourceClassId: '&IDC_Relationship;' - type: 'has sibling' - destinationClassId: '&IDC_Relationship;' - siblingRelationshipId: '&IDR_Relationship__is_sibling__Relationship;' - singular: yes - -- relationship: '&IDR_Relationship__is_sibling__Relationship;' - index: 6 - sourceClassId: '&IDC_Relationship;' - type: 'is sibling' - destinationClassId: '&IDC_Relationship;' - siblingRelationshipId: '&IDR_Relationship__has_sibling__Relationship;' - singular: yes - -- relationship: '&IDR_Class__has_super__Class;' - index: 7 - sourceClassId: '&IDC_Class;' - type: 'has super' - destinationClassId: '&IDC_Class;' - siblingRelationshipId: '&IDR_Class__has_sub__Class;' - singular: no - -- relationship: '&IDR_Class__has_sub__Class;' - index: 8 - sourceClassId: '&IDC_Class;' - type: 'has sub' - destinationClassId: '&IDC_Class;' - siblingRelationshipId: '&IDR_Class__has_super__Class;' - singular: no - -- relationship: '&IDR_Work_Set__has_valid__Class;' - index: 9 - sourceClassId: '&IDC_WorkSet;' - type: 'has valid' - destinationClassId: '&IDC_Class;' - siblingRelationshipId: '&IDR_Class__valid_for__Work_Set;' - singular: no - -- relationship: '&IDR_Class__valid_for__Work_Set;' - index: 10 - sourceClassId: '&IDC_Class;' - type: 'valid for' - destinationClassId: '&IDC_WorkSet;' - siblingRelationshipId: '&IDR_Work_Set__has_valid__Class;' - singular: no - -- relationship: '&IDR_Control_Transaction_Method__processes__Element;' - index: 11 - sourceClassId: '&IDC_ControlTransactionMethod;' - type: 'processes' - destinationClassId: '&IDC_Element;' - siblingRelationshipId: '&IDR_Element__processed_by__Control_Transaction_Method;' - singular: no - -- relationship: '&IDR_Element__processed_by__Control_Transaction_Method;' - index: 12 - sourceClassId: '&IDC_Element;' - type: 'processed by' - destinationClassId: '&IDC_ControlTransactionMethod;' - siblingRelationshipId: '&IDR_Control_Transaction_Method__processes__Element;' - singular: yes - -#- relationship: '&IDR_Element__has_text_node_value__Attribute;' -# index: 13, -# sourceClassId: '&IDC_Element;' -# type: 'has text node value' -# destinationClassId: '&IDC_Attribute;' -# siblingRelationshipId: '&IDR_Element__processed_by__Control_Transaction_Method;' -# singular: yes - -# - relationship: '&IDR_Attribute__is_text_node_value_for__Element;' -# index: 14, -# sourceClassId: '&IDC_Attribute;' -# type: 'is text node value for' -# destinationClassId: '&IDC_Element;' -# siblingRelationshipId: '&IDR_Element__has_text_node_value__Attribute;' -# singular: yes - -- relationship: '&IDR_Class__has__Method;' - index: 15 - sourceClassId: '&IDC_Class;' - type: 'has' - destinationClassId: '&IDC_Method;' - siblingRelationshipId: '&IDR_Method__for__Class;' - singular: no - -- relationship: '&IDR_Method__for__Class;' - index: 16 - sourceClassId: '&IDC_Method;' - type: 'for' - destinationClassId: '&IDC_Class;' - siblingRelationshipId: '&IDR_Class__has__Method;' - singular: no - -# - relationship: '&IDR_Class__has_implementation__Method;' -# index: 17, -# sourceClassId: '&IDC_Class;' -# type: 'has implementation' -# destinationClassId: '&IDC_Method;' -# siblingRelationshipId: '&IDR_Method__implements_for__Class;' -# singular: no - -# - relationship: '&IDR_Method__implements_for__Class;' -# index: 18, -# sourceClassId: '&IDC_Method;' -# type: 'implements for' -# destinationClassId: '&IDC_Class;' -# siblingRelationshipId: '&IDR_Class__has_implementation__Method;' -# singular: yes - -# - relationship: '&IDR_Method__implements__Method;' -# index: 19 -# sourceClassId: '&IDC_Method;' -# type: 'implements' -# destinationClassId: '&IDC_Method;' -# siblingRelationshipId: '&IDR_Method__implemented_by__Method;' -# singular: no - -# - relationship: '&IDR_Method__implemented_by__Method;' -# index: 20, -# sourceClassId: '&IDC_Method;' -# type: 'implemented by' -# destinationClassId: '&IDC_Method;' -# siblingRelationshipId: '&IDR_Method__implements__Method;' -# singular: no diff --git a/common/libraries/yaml/net.alcetech.Mocha.System@20231121T2131-0500/003-Classes/00003-Relationship.yaml b/common/libraries/yaml/net.alcetech.Mocha.System@20231121T2131-0500/003-Classes/00003-Relationship.yaml index 275de3f..ca0dc06 100644 --- a/common/libraries/yaml/net.alcetech.Mocha.System@20231121T2131-0500/003-Classes/00003-Relationship.yaml +++ b/common/libraries/yaml/net.alcetech.Mocha.System@20231121T2131-0500/003-Classes/00003-Relationship.yaml @@ -23,4 +23,181 @@ - instance: '&IDR_Relationship__has_destination__Class;' customTagName: 'destinationClassId' - instance: '&IDR_Relationship__has_sibling__Relationship;' - customTagName: 'siblingRelationshipId' \ No newline at end of file + customTagName: 'siblingRelationshipId' + + +- relationship: '&IDR_Class__has__Attribute;' + index: 1 + sourceClassId: '&IDC_Class;' + type: 'has' + destinationClassId: '&IDC_Attribute;' + siblingRelationshipId: '&IDR_Attribute__for__Class;' + singular: no + +- relationship: '&IDR_Attribute__for__Class;' + index: 2 + sourceClassId: '&IDC_Attribute;' + type: 'for' + destinationClassId: '&IDC_Class;' + siblingRelationshipId: '&IDR_Class__has__Attribute;' + singular: no + +- relationship: '&IDR_Class__has__Relationship;' + index: 3 + sourceClassId: '&IDC_Class;' + type: 'has' + destinationClassId: '&IDC_Relationship;' + siblingRelationshipId: '&IDR_Relationship__for__Class;' + singular: no + +- relationship: '&IDR_Relationship__for__Class;' + index: 4 + sourceClassId: '&IDC_Relationship;' + type: 'for' + destinationClassId: '&IDC_Class;' + siblingRelationshipId: '&IDR_Class__has__Attribute;' + singular: no + +- relationship: '&IDR_Relationship__has_sibling__Relationship;' + index: 5 + sourceClassId: '&IDC_Relationship;' + type: 'has sibling' + destinationClassId: '&IDC_Relationship;' + siblingRelationshipId: '&IDR_Relationship__is_sibling__Relationship;' + singular: yes + +- relationship: '&IDR_Relationship__is_sibling__Relationship;' + index: 6 + sourceClassId: '&IDC_Relationship;' + type: 'is sibling' + destinationClassId: '&IDC_Relationship;' + siblingRelationshipId: '&IDR_Relationship__has_sibling__Relationship;' + singular: yes + +- relationship: '&IDR_Class__has_super__Class;' + index: 7 + sourceClassId: '&IDC_Class;' + type: 'has super' + destinationClassId: '&IDC_Class;' + siblingRelationshipId: '&IDR_Class__has_sub__Class;' + singular: no + +- relationship: '&IDR_Class__has_sub__Class;' + index: 8 + sourceClassId: '&IDC_Class;' + type: 'has sub' + destinationClassId: '&IDC_Class;' + siblingRelationshipId: '&IDR_Class__has_super__Class;' + singular: no + +- relationship: '&IDR_Work_Set__has_valid__Class;' + index: 9 + sourceClassId: '&IDC_WorkSet;' + type: 'has valid' + destinationClassId: '&IDC_Class;' + siblingRelationshipId: '&IDR_Class__valid_for__Work_Set;' + singular: no + +- relationship: '&IDR_Class__valid_for__Work_Set;' + index: 10 + sourceClassId: '&IDC_Class;' + type: 'valid for' + destinationClassId: '&IDC_WorkSet;' + siblingRelationshipId: '&IDR_Work_Set__has_valid__Class;' + singular: no + +- relationship: '&IDR_Control_Transaction_Method__processes__Element;' + index: 11 + sourceClassId: '&IDC_ControlTransactionMethod;' + type: 'processes' + destinationClassId: '&IDC_Element;' + siblingRelationshipId: '&IDR_Element__processed_by__Control_Transaction_Method;' + singular: no + +- relationship: '&IDR_Element__processed_by__Control_Transaction_Method;' + index: 12 + sourceClassId: '&IDC_Element;' + type: 'processed by' + destinationClassId: '&IDC_ControlTransactionMethod;' + siblingRelationshipId: '&IDR_Control_Transaction_Method__processes__Element;' + singular: yes + +#- relationship: '&IDR_Element__has_text_node_value__Attribute;' +# index: 13, +# sourceClassId: '&IDC_Element;' +# type: 'has text node value' +# destinationClassId: '&IDC_Attribute;' +# siblingRelationshipId: '&IDR_Element__processed_by__Control_Transaction_Method;' +# singular: yes + +# - relationship: '&IDR_Attribute__is_text_node_value_for__Element;' +# index: 14, +# sourceClassId: '&IDC_Attribute;' +# type: 'is text node value for' +# destinationClassId: '&IDC_Element;' +# siblingRelationshipId: '&IDR_Element__has_text_node_value__Attribute;' +# singular: yes + +- relationship: '&IDR_Class__has__Method;' + index: 15 + sourceClassId: '&IDC_Class;' + type: 'has' + destinationClassId: '&IDC_Method;' + siblingRelationshipId: '&IDR_Method__for__Class;' + singular: no + +- relationship: '&IDR_Method__for__Class;' + index: 16 + sourceClassId: '&IDC_Method;' + type: 'for' + destinationClassId: '&IDC_Class;' + siblingRelationshipId: '&IDR_Class__has__Method;' + singular: no + +# - relationship: '&IDR_Class__has_implementation__Method;' +# index: 17, +# sourceClassId: '&IDC_Class;' +# type: 'has implementation' +# destinationClassId: '&IDC_Method;' +# siblingRelationshipId: '&IDR_Method__implements_for__Class;' +# singular: no + +# - relationship: '&IDR_Method__implements_for__Class;' +# index: 18, +# sourceClassId: '&IDC_Method;' +# type: 'implements for' +# destinationClassId: '&IDC_Class;' +# siblingRelationshipId: '&IDR_Class__has_implementation__Method;' +# singular: yes + +# - relationship: '&IDR_Method__implements__Method;' +# index: 19 +# sourceClassId: '&IDC_Method;' +# type: 'implements' +# destinationClassId: '&IDC_Method;' +# siblingRelationshipId: '&IDR_Method__implemented_by__Method;' +# singular: no + +# - relationship: '&IDR_Method__implemented_by__Method;' +# index: 20, +# sourceClassId: '&IDC_Method;' +# type: 'implemented by' +# destinationClassId: '&IDC_Method;' +# siblingRelationshipId: '&IDR_Method__implements__Method;' +# singular: no + +- relationship: '&IDR_Class__has__Instance;' + index: 249 + sourceClassId: '&IDC_Class;' + type: 'has' + destinationClassId: '&IDC_Instance;' + siblingRelationshipId: '&IDR_Instance__for__Class;' + singular: no + +- relationship: '&IDR_Instance__for__Class;' + index: 250 + sourceClassId: '&IDC_Instance;' + type: 'for' + destinationClassId: '&IDC_Class;' + siblingRelationshipId: '&IDR_Class__has__Instance;' + singular: no \ No newline at end of file diff --git a/common/libraries/yaml/net.alcetech.Mocha.System@20231121T2131-0500/003-Classes/00058-CommonNumeric.yaml b/common/libraries/yaml/net.alcetech.Mocha.System@20231121T2131-0500/003-Classes/00058-CommonNumeric.yaml index 955f8f3..f91b396 100644 --- a/common/libraries/yaml/net.alcetech.Mocha.System@20231121T2131-0500/003-Classes/00058-CommonNumeric.yaml +++ b/common/libraries/yaml/net.alcetech.Mocha.System@20231121T2131-0500/003-Classes/00058-CommonNumeric.yaml @@ -1,3 +1,4 @@ - class: '&IDC_CommonNumeric;' + name: 'Common Numeric' index: 58 \ No newline at end of file diff --git a/common/libraries/yaml/net.alcetech.Mocha.System@20231121T2131-0500/003-Classes/02993-Task.yaml b/common/libraries/yaml/net.alcetech.Mocha.System@20231121T2131-0500/003-Classes/02993-Task.yaml index b4c32de..d8be479 100644 --- a/common/libraries/yaml/net.alcetech.Mocha.System@20231121T2131-0500/003-Classes/02993-Task.yaml +++ b/common/libraries/yaml/net.alcetech.Mocha.System@20231121T2131-0500/003-Classes/02993-Task.yaml @@ -1,4 +1,5 @@ - class: '&IDC_Task;' + name: 'Task' index: 2993 abstract: yes relationships: diff --git a/php/mocha/include/BeforeLaunchEvent.inc.php b/php/mocha/include/BeforeLaunchEvent.inc.php index a67e038..8346024 100644 --- a/php/mocha/include/BeforeLaunchEvent.inc.php +++ b/php/mocha/include/BeforeLaunchEvent.inc.php @@ -101,6 +101,31 @@ System::$BeforeGetTenantNameHandler = function() return $path[0]; }; +function requiresLogin($path) +{ + if ($path != null) + { + if ($path == "ots/{tenant}/services/{serviceName}/{version}/{command}") + { + return false; + } + } + + /* + if (count($path) > 0) + { + if ($path[0] == "ots" + || $path[0] == "suv" + || $path[0] == "ccx") + { + echo("no"); + return false; + } + } + */ + return true; +} + System::$BeforeLaunchEventHandler = function($path) { /** @@ -145,11 +170,16 @@ System::$BeforeLaunchEventHandler = function($path) { $currentTenantName = $path[2]; } + else if ($path[0] == "ots") + { + $currentTenantName = $path[1]; + } else { $currentTenantName = $path[0]; } $currentTenant = $oms->getTenantByName($currentTenantName); + if ($currentTenant == null) { System::Redirect("~/invalid-url", true); @@ -191,6 +221,10 @@ System::$BeforeLaunchEventHandler = function($path) } } } + + $page = null; + $pathVars = null; + System::ParsePathVariablesIntoPage($page, $pathVars); if ($currentUser === null) { @@ -202,9 +236,16 @@ System::$BeforeLaunchEventHandler = function($path) } } - $_SESSION["login_return"] = $path; - System::RedirectToLoginPage(true); - return false; + if ($page != null) + { + if (requiresLogin($page->FileName)) + { + echo($page->FileName); + $_SESSION["login_return"] = $path; + System::RedirectToLoginPage(true); + return false; + } + } } return true; }; diff --git a/php/mocha/lib/mocha/oms/MySQLDatabaseOms.inc.php b/php/mocha/lib/mocha/oms/MySQLDatabaseOms.inc.php index 662fb99..2b42c5c 100644 --- a/php/mocha/lib/mocha/oms/MySQLDatabaseOms.inc.php +++ b/php/mocha/lib/mocha/oms/MySQLDatabaseOms.inc.php @@ -161,19 +161,32 @@ return null; } - $query = "CALL mocha_get_instance_by_global_identifier(:global_identifier)"; + $query = "CALL mocha_get_instance_by_global_identifier(mocha_normalize_uuid(:global_identifier))"; $stmt = $this->PDO->prepare($query); - $result = $stmt->execute(array + $parms = array ( "global_identifier" => $globalIdentifier - )); + ); + $result = $stmt->execute($parms); if ($result === false) + { + trigger_error("unknown database error, query was:", \E_USER_ERROR); + trigger_error($query, \E_USER_NOTICE); return null; + } $values = $stmt->fetchAll(); if (count($values) == 0) + { + trigger_error("no records found, query was:", \E_USER_NOTICE); + trigger_error($query, \E_USER_NOTICE); + foreach ($parms as $key => $value) + { + trigger_error($key . ": '" . $value . "'", \E_USER_NOTICE); + } return null; + } $dbid = $values[0]["id"]; $class_id = $values[0]["class_id"]; @@ -189,6 +202,13 @@ public function getRelatedInstances(InstanceReference $sourceInstance, InstanceReference $relationshipInstance, \DateTime $effectiveDate = null) : ?array { + $tenant = $this->getTenant(); + if ($tenant === null) + { + trigger_error("tenant cannot be null", \E_USER_ERROR); + return null; + } + $dt = null; if ($effectiveDate !== null) { @@ -196,12 +216,19 @@ } $query = "CALL mocha_get_related_instances(:src_inst_id, :rel_inst_id, :eff_date)"; $stmt = $this->PDO->prepare($query); - $result = $stmt->execute(array + $parms = array ( "src_inst_id" => $this->getDbId($sourceInstance), "rel_inst_id" => $this->getDbId($relationshipInstance), "eff_date" => $dt - )); + ); + $result = $stmt->execute($parms); + + trigger_error($query, \E_USER_NOTICE); + foreach ($parms as $key => $value) + { + trigger_error($key . ": '" . $value . "'", \E_USER_NOTICE); + } if ($result === false) { diff --git a/php/mocha/ui/pages/OTSPage.phpx b/php/mocha/ui/pages/OTSPage.phpx new file mode 100644 index 0000000..40fbe0e --- /dev/null +++ b/php/mocha/ui/pages/OTSPage.phpx @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/php/mocha/ui/pages/OTSPage.phpx.php b/php/mocha/ui/pages/OTSPage.phpx.php new file mode 100644 index 0000000..041c310 --- /dev/null +++ b/php/mocha/ui/pages/OTSPage.phpx.php @@ -0,0 +1,108 @@ += 3) + { + $tenantName = $path[1]; + } + + if ($tenantName === null) + { + header("HTTP/1.1 404 Not Found"); + header("Content-Type: text/plain"); + echo ("\" Not Available \""); + die(); + } + else + { + $oms = mocha_get_oms(); + if ($oms != null) + { + $ti = $oms->getTenantByName($tenantName); + if ($ti === null) + { + header("HTTP/1.1 404 Not Found"); + header("Content-Type: text/plain"); + echo("The requested resource could not be found."); + die(); + } + else + { + if (count($path) >= 5) + { + header("HTTP/1.1 200 OK"); + + // e.g. https://i-0c0398f84acecb702.privatesuv.com/ots/super/services/zq/v1/module/list + + // ots/{tenant}/services/{serviceName}/{version}/{command} + $tenantName = $this->Page->GetPathVariableValue("tenant"); + $serviceName = $this->Page->GetPathVariableValue("serviceName"); + $version = $this->Page->GetPathVariableValue("version"); + $command = $this->Page->GetPathVariableValue("command"); + + $oms->setTenant($oms->getTenantByName($tenantName)); + + $instClass = $oms->getInstanceByGlobalIdentifier(KnownClassGuids::Clasz); + $instances = $oms->getRelatedInstances($instClass, $oms->getInstanceByGlobalIdentifier(KnownRelationshipGuids::Class__has__Instance)); + + if ($command == "module/list") + { + header("Content-Type: application/json"); + print("{ \"items\": [ "); + print("{ \"name\": \"mocha\", \"title\": \"mocha\", \"type\": \"module\", \"items\": [ "); + + $ct = count($instances); + for ($i = 0; $i < $ct; $i++) + { + print("{ \"name\": \"mocha:inst" . $i . "\", \"title\": \"" . $oms->getInstanceText($instances[$i]) . "\", \"type\": \"class\", \"instanceId\": \"" . $instances[$i]->InstanceKey . "\" }"); + if ($i < $ct - 1) + { + print(", "); + } + } + + print("] }"); + print("] }"); + } + else + { + header("Content-Type: text/plain"); + print("tenantName: " . $tenantName . "\n"); + print("serviceName: " . $serviceName . "\n"); + print("version: " . $version . "\n"); + print("command: " . $command . "\n"); + } + die(); + } + else + { + header("HTTP/1.1 404 Not Found"); + header("Content-Type: text/plain"); + echo("The requested resource could not be found."); + die(); + } + } + } + } + + $re->Cancel = true; + } + } + +?> \ No newline at end of file diff --git a/sql/mysql/001-procedures/mocha_get_related_instances.sql b/sql/mysql/001-procedures/mocha_get_related_instances.sql index 95335f5..09fe927 100644 --- a/sql/mysql/001-procedures/mocha_get_related_instances.sql +++ b/sql/mysql/001-procedures/mocha_get_related_instances.sql @@ -22,6 +22,7 @@ BEGIN SELECT mocha_instances.* FROM mocha_instances, mocha_relationships WHERE mocha_instances.tenant_id = p_tenant_id + AND mocha_relationships.tenant_id = p_tenant_id AND mocha_instances.id = mocha_relationships.destination_inst_id AND mocha_relationships.source_inst_id = p_src_inst_id AND mocha_relationships.relationship_inst_id = p_rel_inst_id