Extending Modx modResource schema errors - database-schema

I'm trying to extend the modx modresource object, but keep getting errors & I can't seem to figure out why. It is related to the schema (I think) but everything looks correct.
Schema:
<?xml version="1.0" encoding="UTF-8"?>
<model package="extresource" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM" tablePrefix="modx_" version="1.0.0">
<object class="extResource" extends="modResource">
<composite alias="ResourceData" class="ResourceData" local="id" foreign="internalKey" cardinality="one" owner="local"/>
</object>
<object class="ResourceData" table="resource_data" extends="xPDOSimpleObject">
<field key="internalKey" dbtype="int" precision="11" phptype="integer" null="false" attributes="unsigned"/>
<field key="views" dbtype="int" precision="11" phptype="integer" null="true" />
<field key="starred" dbtype="int" precision="10" phptype="integer" null="false" />
<index alias="internalKey" name="internalKey" primary="false" unique="true" type="BTREE" >
<column key="internalKey" length="" collation="A" null="false" />
</index>
<aggregate alias="Resource" class="modResource" local="internalKey" foreign="id" cardinality="one" owner="foreign"/>
</object>
</model>
I'm testing it using:
$resource = $modx->getObject('modResource', 11112);
echo $resource->get('pagetitle'); //test I have the resource
$data = $resource->getOne('ResourceData');
The errors I get are:
Could not getOne: foreign key definition for alias ResourceData not
found. No foreign key definition for parentClass: modDocument using
relation alias: ResourceData
The table exists & has data, the package is registered in the modx extension packages. I've been over the schema many times & it looks right.
What is causing these errors?

You have to use the right object class in $modx->getObject. Otherwise you will get a modResource object, that does not know the extended object data and relationship.
$resource = $modx->getObject('extResource', 11112);

Does the resource you are loading have its class_key field set to extResource? That's needed for it to load the right resource object class.

Related

Sulu: error when trying to use custom data provider

I'm following docs from here: https://docs.sulu.io/en/2.2/cookbook/smart-content-data-provider.html
Trying to make custom data provider for my custom entity type "MatchEvent":
I did it how it's explained here. Since I have services.yaml file I defined those 2 like this:
app.match_event_repository:
class: App\Repository\MatchEventRepository
factory: ['#doctrine', 'getRepository']
arguments:
- Symfony\Bridge\Doctrine\ManagerRegistry
app.smart_content.data_provider.matchevent:
class: App\SmartContent\MatchEventDataProvider
arguments: ['#app.match_event_repository', '#sulu_core.array_serializer', '#request_stack' ]
tags: [{name: 'sulu.content.type', alias: 'smart_matchevent_selection'}]
So, if I understood well, after that I should have my custom content data provider named "smart_matchevent_selection" and I can use it like this:
<property name="match" type="smart_content">
<meta>
<title lang="en">Match</title>
<title lang="de">Match</title>
</meta>
<params>
<param name="provider" value="smart_matchevent_selection"/>
</params>
</property>
But when I try to edit page containing this field I get error:
Missing parameter token in Sulu\Bundle\PreviewBundle\Controller\PreviewController
Exception is triggered at project/vendor/sulu/sulu/src/Sulu/Bundle/PreviewBundle/Controller/PreviewController.php:
public function stopAction(Request $request): Response
{
$this->preview->stop($this->getRequestParameter($request, 'token', true));
return new JsonResponse();
}
What I'm doing wrong here?
If you carefully look at the service definition of the SmartContentDataProvider in the documentation, you will notice that the tag should be {name: 'sulu.smart_content.data_provider', alias: 'match_events'} instead of {name: 'sulu.content.type', alias: 'smart_matchevent_selection'} ...
Then you can use it like <param name="provider" value="match_events"/>

DMN 1.2: Referencing ItemDefinitions from another ItemDefinition results in an error

I load this DMN file (dmnFile):
<definitions name="MyDecision" id="def_12f8a48f-3978-0e29-4251-a66b6e6459bc"
xmlns:ns="http://sample.dmn" namespace="http://sample.dmn"
xmlns:feel="http://www.omg.org/spec/FEEL/20140401" exporter="ex" exporterVersion="12"
xmlns="http://www.omg.org/spec/DMN/20180521/MODEL/">
<itemDefinition name="MyItemDefinition" id="_850f24d9-57a3-131f-2194-ca15bb049a7a">
<itemComponent name="myNumber" id="_29d92e98-3c97-67a3-22f1-d342622424f7">
<typeRef>NumberDefinition</typeRef>
</itemComponent>
</itemDefinition>
<itemDefinition name="NumberDefinition" id="_e6972775-7973-b755-8714-9eff9d61e48e">
<typeRef>number</typeRef>
</itemDefinition>
<inputData name="MyInput" id="_d6395e05-d35c-d667-f227-398d93a97759">
<variable name="MyInput" id="_121ab3bc-b4e2-a6bb-51be-ef8fcc6623a6" typeRef="MyItemDefinition" />
</inputData>
<decision name="MyDecision" id="_12f8a48f-3978-0e29-4251-a66b6e6459bc">
<variable name="MyDecision" id="_098e9619-fa0c-3796-b3da-c4d018a79009" typeRef="boolean" />
<informationRequirement>
<requiredInput href="#_d6395e05-d35c-d667-f227-398d93a97759" />
</informationRequirement>
<context id="_6dcdac84-b03f-badd-a2d7-78c668ece883">
<contextEntry>
<variable name="containsMyNumber" id="_f6078cbe-54e6-d682-b3b7-8ffc638e4846" typeRef="boolean" />
<literalExpression id="_a022013e-4f0c-cfb3-1792-673a9e69be33">
<text>if list contains([0,1,2,3], MyInput.myNumber) then true else false</text>
</literalExpression>
</contextEntry>
<contextEntry>
<literalExpression id="_19c3853c-c63b-a8ac-0608-639ea685f321">
<text>containsMyNumber</text>
</literalExpression>
</contextEntry>
</context>
</decision>
</definitions>
like this:
KieServices ks = KieServices.Factory.get();
KieContainer kieContainer = KieHelper.getKieContainer(ks.newReleaseId("org.kie", "dmn-test-" + UUID.randomUUID(), "1.2"), ks.getResources().newFileSystemResource(dmnFile));
and I get an exception with the following error message:
[Message [id=1, kieBase=defaultKieBase, level=ERROR, path=C:/Users/AppData/Local/Temp/tmpBA10.tmp.dmn, line=4, column=-1
text=DMN: Unable to resolve type reference '{http://www.omg.org/spec/DMN/20180521/MODEL/}NumberDefinition' on node 'MyItemDefinition' (resource: C:/Users/AppData/Local/Temp/tmpBA10.tmp.dmn, DMN id: _29d92e98-3c97-67a3-22f1-d342622424f7, The listed type definition was not found) ]]
Type reference with prefix ("ns:NumberDefinition") results in the following error message:
[Message [id=1, kieBase=defaultKieBase, level=ERROR, path=C:/Users/AppData/Local/Temp/tmpBA10.tmp.dmn, line=4, column=-1
text=DMN: Unable to resolve type reference '{http://www.omg.org/spec/DMN/20180521/MODEL/}ns:NumberDefinition' on node 'MyItemDefinition' (resource: C:/Users/AppData/Local/Temp/tmpBA10.tmp.dmn, DMN id: _29d92e98-3c97-67a3-22f1-d342622424f7, The listed type definition was not found) ]]
What do I do wrong?
When using DMN 1.1 (xmlns="http://www.omg.org/spec/DMN/20151101/dmn.xsd") and type references as QNames (with prefixes) I get the expected result.
Since DMNv1.2, the idiomatic way to reference is ns.<itemDef>.
In your original DMN xml file this happens on line 7 and 14.
In summary the file in the idiomatic DMNv1.2 form should be:
<definitions name="MyDecision" id="def_12f8a48f-3978-0e29-4251-a66b6e6459bc"
xmlns:ns="http://sample.dmn" namespace="http://sample.dmn"
xmlns:feel="http://www.omg.org/spec/FEEL/20140401" exporter="ex" exporterVersion="12"
xmlns="http://www.omg.org/spec/DMN/20180521/MODEL/">
<itemDefinition name="MyItemDefinition" id="_850f24d9-57a3-131f-2194-ca15bb049a7a">
<itemComponent name="myNumber" id="_29d92e98-3c97-67a3-22f1-d342622424f7">
<typeRef>ns.NumberDefinition</typeRef>
</itemComponent>
</itemDefinition>
<itemDefinition name="NumberDefinition" id="_e6972775-7973-b755-8714-9eff9d61e48e">
<typeRef>number</typeRef>
</itemDefinition>
<inputData name="MyInput" id="_d6395e05-d35c-d667-f227-398d93a97759">
<variable name="MyInput" id="_121ab3bc-b4e2-a6bb-51be-ef8fcc6623a6" typeRef="ns.MyItemDefinition" />
</inputData>
<decision name="MyDecision" id="_12f8a48f-3978-0e29-4251-a66b6e6459bc">
<variable name="MyDecision" id="_098e9619-fa0c-3796-b3da-c4d018a79009" typeRef="boolean" />
<informationRequirement>
<requiredInput href="#_d6395e05-d35c-d667-f227-398d93a97759" />
</informationRequirement>
<context id="_6dcdac84-b03f-badd-a2d7-78c668ece883">
<contextEntry>
<variable name="containsMyNumber" id="_f6078cbe-54e6-d682-b3b7-8ffc638e4846" typeRef="boolean" />
<literalExpression id="_a022013e-4f0c-cfb3-1792-673a9e69be33">
<text>if list contains([0,1,2,3], MyInput.myNumber) then true else false</text>
</literalExpression>
</contextEntry>
<contextEntry>
<literalExpression id="_19c3853c-c63b-a8ac-0608-639ea685f321">
<text>containsMyNumber</text>
</literalExpression>
</contextEntry>
</context>
</decision>
</definitions>
That said, with your report we uncovered a bug when the DMN xml file is using the DMN namespace as the default namespace, which we are addressing with
DROOLS-4797.
Thank you for the report !
There is a way to avoid being forced to use ns.<itemDef> and simply use <itemDef>, and that is by setting the default namespace in the DMN xml to be the model's namespace, and just prefixing the DMN xml element with the namespace prefix targeting the DMN namespace.
In other words, the file can make use of <itemDef> reference without having to ns. prefix them:
<semantic:definitions name="MyDecision" id="def_12f8a48f-3978-0e29-4251-a66b6e6459bc"
xmlns="http://sample.dmn" namespace="http://sample.dmn"
xmlns:feel="http://www.omg.org/spec/FEEL/20140401" exporter="ex" exporterVersion="12"
xmlns:semantic="http://www.omg.org/spec/DMN/20180521/MODEL/">
<semantic:itemDefinition name="MyItemDefinition" id="_850f24d9-57a3-131f-2194-ca15bb049a7a">
<semantic:itemComponent name="myNumber" id="_29d92e98-3c97-67a3-22f1-d342622424f7">
<semantic:typeRef>NumberDefinition</semantic:typeRef>
</semantic:itemComponent>
</semantic:itemDefinition>
<semantic:itemDefinition name="NumberDefinition" id="_e6972775-7973-b755-8714-9eff9d61e48e">
<semantic:typeRef>number</semantic:typeRef>
</semantic:itemDefinition>
<semantic:inputData name="MyInput" id="_d6395e05-d35c-d667-f227-398d93a97759">
<semantic:variable name="MyInput" id="_121ab3bc-b4e2-a6bb-51be-ef8fcc6623a6" typeRef="MyItemDefinition" />
</semantic:inputData>
<semantic:decision name="MyDecision" id="_12f8a48f-3978-0e29-4251-a66b6e6459bc">
<semantic:variable name="MyDecision" id="_098e9619-fa0c-3796-b3da-c4d018a79009" typeRef="boolean" />
<semantic:informationRequirement>
<semantic:requiredInput href="#_d6395e05-d35c-d667-f227-398d93a97759" />
</semantic:informationRequirement>
<semantic:context id="_6dcdac84-b03f-badd-a2d7-78c668ece883">
<semantic:contextEntry>
<semantic:variable name="containsMyNumber" id="_f6078cbe-54e6-d682-b3b7-8ffc638e4846" typeRef="boolean" />
<semantic:literalExpression id="_a022013e-4f0c-cfb3-1792-673a9e69be33">
<semantic:text>if list contains([0,1,2,3], MyInput.myNumber) then true else false</semantic:text>
</semantic:literalExpression>
</semantic:contextEntry>
<semantic:contextEntry>
<semantic:literalExpression id="_19c3853c-c63b-a8ac-0608-639ea685f321">
<semantic:text>containsMyNumber</semantic:text>
</semantic:literalExpression>
</semantic:contextEntry>
</semantic:context>
</semantic:decision>
</semantic:definitions>
In this other variant, the default namespace in the xml is the DMN model's namespace, so any itemDef reference does not need any prefix.
Because the default namespace in the xml is the DMN model's namespace, the xml element need to be prefixed with the namespace prefix targeting now the DMN namespace.
Hope this clarifies and provide an insightful explanation!

Orbeon control details in own component

I'm making my own component, and I want to have oportunity to set some properties in form builder. In all I want to reach effect similar to autocomplete control, where I can set 3 properties (URI, xpath, and relative xpath). I read, that I can do it using control-details markup, but unfortunately it does not work. This is code (I working on davinci tutorial):
<xbl:binding element="fr|tutorial-davinci" id="fr-tutorial-davinci" xxbl:mode="lhha binding value">
<metadata xmlns="http://orbeon.org/oxf/xml/form-builder" xmlns:xf="http://www.w3.org/2002/xforms">
<display-name lang="en">davinci-modified</display-name>
<templates>
<instance label=""/>
<view>
<fr:tutorial-davinci id="" appearance="minimal" labelref="#label" xmlns="" resource="" >
<xf:label ref=""/>
<xf:hint ref=""/>
<xf:help ref=""/>
<xf:alert ref=""/>
</fr:tutorial-davinci>
</view>
</templates>
<control-details>
<xf:input>
<xf:label lang="en">Some param</xf:label>
</xf:input>
</control-details>
</metadata>
<xbl:template>
<xf:model>
<xf:instance id="id1"><value/></xf:instance>
</xf:model>
<xf:input ref="instance('id1')" />
</xbl:template>
</xbl:binding>
You must have a ref attribute on<xf:input> which points to an attribute or element where the information will be stored. In autocomplete.xml, there is in particular theresource` attribute, which:
is pointed to by <xf:input>
is present on the <fr:autocomplete> template

M2T Xpand with existing ecore model

I have an ecore model MyModel.ecore for which i want to generate code using Xpand. I dont have edit code or a runtime environment for the xpand project, i just want to create a xpand project, load MyModel.ecore, create a model.xmi using "create dynamic instance" and run.
The problem is that my workflow file doesnt seems to recognize the elements from my metamodel.
Here is the code from my workflow:
<?xml version="1.0"?>
<workflow>
<property name="model" value="com.example/src/Application.xmi" />
<property name="src-gen" value="src-gen" />
<!-- set up EMF for standalone execution -->
<bean class="org.eclipse.emf.mwe.utils.StandaloneSetup" >
<platformUri value=".."/>
</bean>
<!-- instantiate metamodel -->
<bean id="mm_emf" class="org.eclipse.xtend.typesystem.emf.EmfRegistryMetaModel"/>
<!-- load model and store it in slot 'model' -->
<component class="org.eclipse.emf.mwe.utils.Reader">
<uri value="platform:/resource/${model}" />
<modelSlot value="model" />
</component>
<!-- check model -->
<component class="org.eclipse.xtend.check.CheckComponent">
<metaModel idRef="mm_emf"/>
<checkFile value="metamodel::Checks" />
<emfAllChildrenSlot value="model" />
</component>
<!-- generate code -->
<component class="org.eclipse.xpand2.Generator">
<metaModel idRef="mm_emf"/>
<expand
value="template::Template::Root FOR Application" />
<outlet path="${src-gen}" >
<postprocessor class="org.eclipse.xpand2.output.JavaBeautifier" />
</outlet>
</component>
My template file:
«IMPORT MyModel»
«DEFINE Root FOR Application»
«FILE "AndroidManifest.xml"»
«ENDFILE»
«EXPAND ProcesaScreens FOREACH Screens»
«ENDDEFINE»
«DEFINE ProcesaScreens FOR Screen»
«FILE this.name +".java"»
«IF (this.metaType.compareTo(StartScreen.metaType) == 0)»
«EXPAND ProcesaStartScreen FOR (StartScreen)this»
«ENDIF»
«ENDFILE»
«ENDDEFINE»
«DEFINE ProcesaStartScreen FOR StartScreen»
«FILE "FilePrueba.java"»
«ENDFILE»
«ENDDEFINE»
And im getting this error:
695 INFO CompositeComponent - Reader: Loading model from platform:/resource/guiamovil.xpand/src/Application.xmi
890 INFO CompositeComponent - CheckComponent: slot model check file(s): metamodel::Checks
1329 INFO CompositeComponent - Generator: generating 'template::Template::Root FOR Application' => src-gen
1340 ERROR AbstractExpressionsUsingWorkflowComponent - Error in Component of type org.eclipse.xpand2.Generator:
EvaluationException : Couldn't find type or property 'Application'
[59,11] on line 1 'Application'
1340 ERROR WorkflowEngine - Workflow interrupted. Reason: Couldn't find type or property 'Application'
1340 ERROR WorkflowEngine - [ERROR]: Couldn't find type or property 'Application'(Element: Application; Reported by: Generator: generating 'template::Template::Root FOR Application' => src-gen)
1341 ERROR WorkflowEngine - [ERROR]: Couldn't find type or property 'Application'(Element: EXPAND template::Template::Root FOR Application; Reported by: Generator: generating 'template::Template::Root FOR Application' => src-gen)
I imagine its something in the workflow.
Thanks
I think you should register your models first :
<bean class="org.eclipse.emf.mwe.utils.StandaloneSetup" >
<platformUri value=".."/>
<registerGeneratedEPackage value="com.issamux.example"/>
....
//
</bean>
<!-- instantiate metamodel -->
<bean id="mm_emf" class="org.eclipse.xtend.typesystem.emf.EmfRegistryMetaModel"/>
//your code
let me now if this resolved your problem...

does phing support arrays with keys and values?

In phing i can set this:
<property name="build.myArray" value="something1, something2, something3" />
And then retrieve each value like this:
<foreach list="${build.myArray}" param="replace.me" target="build:create-vhost" />
<target name="build:create-vhost">
<filterchain>
<replacetokens begintoken="#" endtoken="#">
<token key="REPLACE_ME" value="${replace.me}" />
</replacetokens>
</filterchain>
</target>
My question is can i do the same this but using array with keys and values?
Something like that:
<property name="build.myArray" value="myKey = something1, myKey2 => something2, myKey3 => something3" />
and use that key names later
Is is possible to do it?
No, you cannot use properties as array in phing.