As described in http://n4.nabble.com/Grails-Data-Binding-for-One-To-Many-Relationships-with-REST-tp1754571p1754571.html i'm trying to automatically bind my REST data.
I understand now that for one-to-many associations the map that is required for the data binding must have a list of ids of the many side such as:
[propName: propValue, manyAssoc: [1, 2]]
However, I'm getting this exception
Executing action [save] of controller [com.example.DomainName] caused exception: org.springframework.orm.hibernate3.HibernateSystemException: IllegalArgumentException occurred calling getter of com.example.DomainName.id; nested exception is org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of com.example.DomainName.id
However, even weirder is the update action that is generated for the controller. There we have the databinding like this:
domainObjectInstance.properties = params['domainObject']
But, and this is the really weird thing, params['domainObject'] is null! It is null because all the domainObject fields are passed directly in the params map itself. If I change the above line to
domainObjectInstance.properties = null
the domainObject is still updated! Why is this happening and more important, how can I bind my incoming XML automatically if it comes in this format (the problem is the one-to-many associations):
<product>
<name>Table</name>
<brand id="1" />
<categories>
<category id="1" />
<category id="2" />
</categories>
</product>
It's not 100% clear from your example - what exactly is the contents of your "params" when you try to bind.
If you don't have "domainObject.xxx=yyy" post parameters defined, then nothing will be in params['domainObject']. Namespacing like that is not necessary in most cases, and required the form fields to use the prefix.
I'm guessing your data is coming in as "xxx=yyy" not "domainObject.xxx=yyy".
Furthermore, I'm not sure that [1,2] for associations is right either. Surely that should be [id:1, id:2] ?
Related
I am trying to create an entity in Dynamics CRM online with a custom lookup field. Even after providing the SchemaName(sg_DepartmentalProjectId) as mentioned here 'An undeclared property' when trying to create record via Web API I am still getting the same error.
An error occurred while validating input parameters: Microsoft.OData.ODataException: An undeclared property 'sg_DepartmentalProjectId' which only has property annotations in the payload but no property value was found in the payload. In OData, only declared navigation properties and declared named streams can be represented as properties without values.
Below is my JSON Post
{
"sg_invoicenumber": "SIAIR402742-416805",
"sg_accountnumber": "5400",
"sg_description": "xxxx",
"sg_fy": "20",
"sg_name": "Operational Journal: yyy - 09/20/2019",
"sg_departmentid": "CC10530",
"sg_postingdate": "2019-09-20",
"sg_invoicedate": "2019-09-20",
"sg_checkdate": "2019-09-20",
"sg_paidfulldate": "2019-09-24",
"sg_amount": 5597.4,
"sg_effectivedate": "2019-09-20",
"sg_DepartmentalProjectId#odata.bind":"/sg_departmentalmatters(e9c31cec-deff-e411-80c5-0050569732ae)"
}
Please Download Odata Metadata from the Developer resources & verify the exact casing. Jason Lattimer also confirmed that the bug while investigating the CRM REST builder issue:
I've come to figure out the metadata is in fact not the source of truth - it's the CSDL
I know it's super annoying when this is working different & getting solved by different solutions. Make sure you verify in all these places for the custom lookup attribute.
Microsoft reference: CSDL $metadata document
I had the same problem, but in my case using the schema name didn’t work. I believe it’s because my field is setup as a navigation property to either of two different entities. I found the correct name by pulling the metadata for the entity from the API and looking at the navigation properties. There were two navigation properties defined for this field, one for each target entity, so I had to use the name of the correct one in my payload.
<NavigationProperty
Name="parentcustomerid_account"
Type="mscrm.account"
Nullable="false"
Partner="contact_customer_accounts">
<ReferentialConstraint
Property="_parentcustomerid_value"
ReferencedProperty="accountid" />
</NavigationProperty>
The correct value was parentcustomerid_account above.
I had same issue
JSON:
{
"activityid": "cbf73794-9e42-ec11-8c62-00224815945f",
"subject": "Test 22",
"new_AppointmentTypeId#odata.bind": "new_tasktypes(a97ec3cf-3e1a-ea11-a811-000d3a799417)"
}
Error I was getting:
An error occurred while validating input parameters: Microsoft.OData.ODataException: An undeclared property 'new_AppointmentTypeId' which only has property annotations in the payload but no property value was found in the payload. In OData, only declared navigation properties and declared named streams can be represented as properties without values.
Resolution:
Use Metadata Browser https://learn.microsoft.com/en-us/dynamics365/customerengagement/on-premises/developer/browse-your-metadata?view=op-9-1
Find ReferencingEntityNavigationProperty from Metadata Browser for fields you need it.
Working JSON:
{
"activityid": "cbf73794-9e42-ec11-8c62-00224815945f",
"subject": "Test 22",
"new_AppointmentTypeId_Appointment#odata.bind": "new_tasktypes(a97ec3cf-3e1a-ea11-a811-000d3a799417)"
}
I went through various posts, regarding reading properties from external property files. Looks like there is a function - getProperty, which can read values from a property file, using a key. I am using saxon parser with spring integration. I am trying something like this, as described in the post :-
spring context file:
<int-xml:xslt-transformer id="xsltTransformer" input-channel="bulkStringInboundChannel"
output-channel="toBridgeChannel" result-type="StringResult" **transformer-factory-class="net.sf.saxon.TransformerFactoryImpl"**
xsl-resource="classpath:/META-INF/spring/integration/intake/intake-flow/bulkTransformer.xsl" />
XSL style sheet:
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
....
<xsl:variable name="props" select="document('prop.xml')" />
<xsl:value-of select="f:getProperty('query1')"/>
....
Prop.xml:
query1 = /Batch/RequestID/text()
Error description:
XPST0003: XPath syntax error at char 23 on line 30 in {f:getProperty('query1')}:
XTSE0650: No template exists named getProperty
I now have two questions- first of all, how do I get rid of these errors?
Second, can I store xPath queries in property files? The post describes a method, to read a property file and use the value pertaining to its key. However, I am thinking that getProperty will just print the query's text equivalent instead of evaluating the query and processing it. Is there a way to achieve this?
Post - How to read a .properties file inside a .xsl file?
I can't help you with the Spring side of the question, but as for the Saxon side, you can call the JDK method System.getProperty() using code like this:
<xsl:value-of select="System:getProperty('user.dir')" xmlns:System="java:java.lang.System"/>
Java extensibility requires Saxon-PE or higher.
If the value of the property that you read is an XPath expression, you can then execute it using the XSLT 3.0 xsl:evaluate instruction - which also requires Saxon-PE or higher.
Using the Rally/JIRA connection I am trying to synchronise them.
https://help.rallydev.com/jira-5-installation-user-guide
I am trying to map the Requirement (UserStory) field for Defects to a custom field in JIRA.
Here are my field mappings
<FieldMapping>
<Field><Rally>Name</Rally> <Other>Summary</Other></Field>
<Field><Rally>Description</Rally> <Other>Description</Other></Field>
<Field><Rally>FormattedID</Rally> <Other>RallyKey</Other></Field>
<Field><Rally>Status</Rally> <Other>Status</Other></Field>
<Field><Rally>Priority</Rally> <Other>Priority</Other></Field>
<Field><Rally>Requirement</Rally> <Other>RallyUserStory</Other></Field>
</FieldMapping>
I am using the RallyReferenceFieldHandler to map this to a custom field
<RallyReferenceFieldHandler>
<FieldName>Requirement</FieldName>
<ReferencedFieldLookupID>FormattedID</ReferencedFieldLookupID>
</RallyReferenceFieldHandler>
I am getting this error message:
RallyEIF::WRK::JiraRestConnection.block in validate - Field Handler field_name Requirement not found
would you mind posting more of your config with all of your field mappings and field handlers?
My only guess at the moment is that your is inside your block. If it were in the wrong place, you might get an error like you are seeing. It should be inside a block - for example:
<Connector>
<FieldMapping>
<Field><Rally>FormattedID</Rally><Other>OtherFormattedID</Other></Field>
<Field><Rally>Requirement</Rally><Other>RallyUserStory</Other></Field>
</FieldMapping>
<RallyFieldHandlers>
<RallyReferenceFieldHandler>
<FieldName>Requirement</FieldName>
<ReferencedFieldLookupID>FormattedID</ReferencedFieldLookupID>
</RallyReferenceFieldHandler>
<RallyFieldHandlers>
<OtherFieldHandlers>
<!-- Other Field Handlers here -->
</OtherFieldHandlers>
</Connector>
In my project, I have this config in struts.xml
<action name="searchTracker" class="searchAction" method="searchTracker">
<result name="success">/jsp/searchTracker.jsp</result>
<result name="error">/jsp/searchTracker.jsp</result>
</action>
And here is my action method in searchAction Action
public String searchTracker(){
this.clearErrorsAndMessages();
List<File> queryResults = fileManager.retrievequeryResults(patchNumBySearch); // patchNumBySearchis input from the page
if(queryResults == null){
this.setTrackers(null);
addActionError("This patch number doesn't exist. Please choose another one !");
return ERROR;
}
List<Tracker> trackers = commonUtils.convertToTrackers(queryResults);
this.setTrackers(trackers);
}
return SUCCESS;
}
if I input wrong param and the queryResult is returned as NULL, the page searchTracker.jsp can correctly show error message in itself as I wish, but after this, I enter correct param, it show error directly below
"Errors on action com.harris.northstar.dbadesk.action.SearchTrackerAction#9bee3a, returning result name 'input'"
I just compared debug log in two different case, and found that only one line difference
"converter is null for property patchNumBySearch. Mapping size: 0"
if this line exists, it will go into my action, if not, it will go to the error asking for input result. What is the line meaning?
and didn't get into the action class yet. I know the reason is that it violate some default validation interceptor and throw this exception, but I can't find anything wrong with this request with correct param. If I enter correct param firstly, it can get queryResult and goes to Success result without problem. The only different is timing.
Do I have to add input result in the configuration xml? I met some project before, and they only has success and error result, no input result at all, why it doesn't works? Something is wrong with my struts.xml?
And I don't want to create my own interceptor by disabling struts default validation interceptor
I just found a way to walk around it. just delete error result in configuration file, only keep success result, and remove AccionErrors in method searchAction, so user wont' get any warning message for their query request, just show nothing on the page, but this way is secondary option. I still want to show up the error message by solving this problem.
The input result would be called when a validation error occurs before transferring the control to the action method. In this case, I suggest that, you define a result type input to the initial jsp and try printing the fielderrors and actionerros using <s:fielderror /> and <s:actionerror /> respectively. This will give you a better outlook and you will come to know how to handle this in the next step depending on the error type.
I am trying to validate an XML Schema document against the schema for schemas (http://www.w3.org/2001/XMLSchema) using NSXMLDocument. I've gotten it to work correctly, and assumed that I was validating against a local schema.
However, I discovered that without a network connection, this validation doesn't work. Is there any way to force NSXMLDocument to use a local schema for validation?
The code I have working with a net connection:
xmlDoc = [[NSXMLDocument alloc] initWithContentsOfURL:furl options:(NSXMLDocumentValidate | NSXMLNodePreserveAll)
error:&err];
NSXMLElement *rootElement = [xmlDoc rootElement];
NSMutableArray *namespaces = [[rootElement namespaces] mutableCopy];
[namespaces addObject:[NSXMLNode namespaceWithName:#"xsi" stringValue:#"http://www.w3.org/2001/XMLSchema-instance"]];
[rootElement setNamespaces:namespaces];
[rootElement removeAttributeForName:#"xsi:schemaLocation"];
[rootElement addAttribute:[NSXMLNode attributeWithName:#"xsi:schemaLocation" stringValue:[NSString stringWithFormat:#"http://www.w3.org/2001/XMLSchema %#", #"/System/Library/Schemas/XMLSchema.xsd"]]];
BOOL vaildXML = [xmlDoc validateAndReturnError:&err];
The schema tag of the document I'm validating:
<schema xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:myCompany="http://schema.myCompany.com/SomeSchema"
targetNamespace="http://schema.myCompany.com/SomeSchema">
It seems to be having a problem with the w3.org schema location, but not my company's.
The error I'm seeing
error : No such file or directory
I/O warning : failed to load external entity "http://www.w3.org/2001/xml.xsd"
Error Domain=NSXMLParserErrorDomain Code=1 UserInfo=0x103051c10 "Element '{http://www.w3.org/2001/XMLSchema}import': Failed to locate a schema at location 'http://www.w3.org/2001/xml.xsd'. Skipping the import.
attribute use (unknown), attribute 'ref': The QName value '{http://www.w3.org/XML/1998/namespace}lang' does not resolve to a(n) attribute declaration.
attribute use (unknown), attribute 'ref': The QName value '{http://www.w3.org/XML/1998/namespace}lang' does not resolve to a(n) attribute declaration.
Any ideas?
Looking at the Apple docs for the NSXMLDTD class suggests that you do have access to catalogs. However, there seems to be very limited support for defining the catalog to be used. Either you can create a catalog at /etc/xml/catalog or set the XML_CATALOG_FILES environment variable.
Once you've got a catalog, you should be able to place an entry into it for the W3 schema along with a local copy. Something like:
<?xml version="1.0"?>
<!DOCTYPE catalog PUBLIC "-//OASIS//DTD Entity Resolution XML Catalog V1.0//EN"
"http://www.oasis-open.org/committees/entity/release/1.0/catalog.dtd">
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">
<system systemId="http://www.w3.org/2001/xml.xsd" uri="xml.xsd"/>
<uri name="http://www.w3.org/XML/1998/namespace" uri="xml.xsd"/>
</catalog>
This assumes that you have the catalog and the schema in the same directory.
I can't try this myself (lack of time and rusty Cocoa skills) but it should work. If I remember correctly, NSXML is based on libxml2 which certainly supports catalogs.
The specifications for catalogs themselves can be found on the OASIS website.