SpringData-Neo4j - New value must be a Set, was: class java.util.ArrayList - spring-data-neo4j

I am trying to persist a domain object that contains fields of type java.util.List. I am using springdata 3.2.0.RELEASE + Neo4j 2.1.2 and persisting the object using neo4jTemplate.save API.
The questions is:
How to handle a scenario where domoain object has a list.
appreciate your assistance
Utpal.
I am getting the following error:
INFO : org.springframework.data.neo4j.fieldaccess.DelegatingFieldAccessorFactory - No FieldAccessor configured for field: interface java.util.Set ratings rel: false idx: false
java.lang.IllegalArgumentException: New value must be a Set, was: class java.util.ArrayList
at org.springframework.data.neo4j.fieldaccess.RelationshipHelper.createSetOfTargetNodes(RelationshipHelper.java:124)
at org.springframework.data.neo4j.fieldaccess.RelatedToFieldAccessor.createSetOfTargetNodes(RelatedToFieldAccessor.java:82)
at org.springframework.data.neo4j.fieldaccess.RelatedToCollectionFieldAccessorFactory$RelatedToCollectionFieldAccessor.setValue(RelatedToCollectionFieldAccessorFactory.java:66)
at org.springframework.data.neo4j.fieldaccess.DefaultEntityState.setValue(DefaultEntityState.java:113)

Use Set rather than List. Neo4j doesn't support order.
It will help.

Related

Loopback 4: How to access table with underscore in name from loopback 4?

I am trying to get data from my data source using loopback 4. It is working fine if the table name is simple and does not contain any special character.
But if there is a table with some special character like Underscore it does not allow me to create a model for that and I am not able to access the data from that table.
I have a table named "my_data" that contains column:- id,first_name,last_name.
But when I use the command lb4 model and pass the model name as my_data it converts it to my-data. and later on, when I call the API it throws an error by saying that relation publi.mydata does not exist.
WARNING: relational database doesn't support {strict: false} mode. {strict: true} mode will be set for model MyData instead.
Unhandled error in GET /my_data?filter=%7B%0A%20%20%22fields%22%3A%20%7B%0A%20%20%20%20%22id%22%3A%20true%2C%0A%20%20%20%20%first_name%22%3A%20true%2C%0A%20%20%20%20%22additionalProp1%22%3A%20%7B%7D%0A%20%20%7D%0A%7D: 500 error: relation "public.mydata" does not exist
at Connection.parseE (/Users/apple/others/loopback4/hello/node_modules/pg/lib/connection.js:614:13)
at Connection.parseMessage (/Users/apple/others/loopback4/hello/node_modules/pg/lib/connection.js:413:19)
at Socket.<anonymous> (/Users/apple/others/loopback4/hello/node_modules/pg/lib/connection.js:129:22)
at Socket.emit (events.js:315:20)
at addChunk (_stream_readable.js:297:12)
at readableAddChunk (_stream_readable.js:273:9)
at Socket.Readable.push (_stream_readable.js:214:10)
at TCP.onStreamRead (internal/stream_base_commons.js:186:23)
Is ther any way to get data from table named like this? If anyone know how to do this please let me know.
Use settings.table in the #model decorator:
#model({
settings: {
table: 'my_data',
},
})
Further reading
https://loopback.io/doc/en/lb4/Model.html#data-mapping-properties

DJANGO API REST FRAMEWORK: schema methods

Django 1.11.3, python 3.6
I have 2 classes in my view.py:
class ProductList(generics.ListAPIView):
class SampleList(generics.ListAPIView):
Please note the same superclass. Might be relevant: Product is an actual model, Sample is not, SampleList is just a method that calls Product.objects.all() (same code as in ProductList)
All the code inside those classes besides class names is IDENTICAL (including serializer) - I just copied the class and renamed the copy).
The client before it hits urls for those two gets the schema
schema = self.client.get(self.myAppApiUrl)
#works, returns the results
result1 = self.client.action(schema, ["products", "list"])
params = {"id" : some_id, }
#fails with this: coreapi.exceptions.LinkLookupError: Index ['samples']['list'] did not reference a link. Key 'list' was not found.
result2 = self.client.action(schema, ["samples", "list"], params)
When I print "schema", I see
products: {
list([page])
}
samples: {
read(id)
}
My questions are: what makes it to add "list" to schema in the first case and "read" in the second case? And how can I add "list" to the second case? Maybe some schema update needs to be done somehow? The API web server was restarted.
What does that message "Key 'list' was not found" mean? Does this failure have something to do with the params passed? Removing params from the client call does not change anything.
I am also somewhat curious about what is that "page" thing in list and what adds that and but that's not important.

Grails Fields Plugin using field templates issue

unfortunatly I can't find any good example where use of the Grails fields plugin is made.
WIthin my app I would like to have some field rendered as a different type like text area or later the CKE editor. My domain:
class Case {
String description
}
I've created a _input.gsp that is found by the plugin:
INFO formfields.FormFieldsTemplateService - found template /patchCase/description/input
It contains:
<f:field bean="Case" property="description">
<g:textArea name="description" cols="40" rows="5" maxlength="5000" value="some default text"/>
</f:field>
However I get
ERROR errors.GrailsExceptionResolver - NotReadablePropertyException occurred when processing request: [GET] /M3PatchManage/patchCase/create
Invalid property 'description' of bean class [java.lang.String]: Bean property 'description' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?. Stacktrace follows:
Message: Error processing GroovyPageView: Error executing tag <g:form>: Error executing tag <f:all>: Error executing tag <f:field>: Invalid property 'description' of bean class [java.lang.String]: Bean property 'description' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
Can any one describe how to use the customisation of fields or give a link with a good description (plugin doc is very thin)?
I'm on Grails 2.4.
I think your problem is the bean="Case" attribute. It seems the fields plugin is trying to render properties of the String "Case" rather than an instance of the Case class.
You should instead pass either the model key name of a Case instance, or the instance itself to this attribute. I would guess either of the following might work: bean="case" or bean="${case}".
Here's a Grails app of mine that makes extensive use of the fields plugin. Some example fields plugin templates are here and here's a form that uses them.
You'll notice that in almost all cases, an input field is passed as the body of the f:field tag, e.g.
<f:field bean="competition" property="code" label="Code">
<g:textField name="${property}" value="${value}" class="input-xlarge" maxlength="191"/>
</f:field>
This could be expressed more concisely as:
<f:field bean="competition" property="code" label="Code"
input-class="input-xlarge" input-maxlength="191"/>
I've been through the same issue. Try to use bean="${class}" instead of bean="class".
On "class" put the name of the class that you are trying to bean

unable to create an issue in jira using testlink

Create JIRA Ticket FAILURE => com.atlassian.jira.rpc.exception.RemoteValidationException: {customfield_10000=Component is required.} : [] - serialized issue:a:5:{s:7:"project";s:2:"SC";s:4:"type";i:6;s:7:"summary";s:101:"/Salon Cart/CSC/New User Creation Req_SE_007/SC-21:1 - Executed ON (ISO FORMAT): 2014-05-29 14:39:10";s:11:"description";s:159:"Execution ID: 46 Tester: Preshant Test Plan: SIT Round 1 Build: SIT Round 1 Executed ON (ISO FORMAT): 2014-05-29 14:39:10 Execution Status: passed ";s:9:"issuetype";i:1;}
Can anybody help me out to solve this error?
This occurs when trying to create an issue in testlink.
Well, Jira has its own custom field, the customfield_10000 field that you are looking at is created by you or the someone in your company to track issues.
When you put in a request to create a issue you should provide the values of custom field in order for Jira to process the field.
Just solved this issue myself. You need to add a default value to customfield_10000 as part of your SOAP configuration. For example in your case:
<!-- Template jirasoapInterface -->
<issuetracker>
<username>YOURUSERNAME</username>
<password>YOURPASSWORD</password>
<uribase>JIRASERVER</uribase>
<uriwsdl>JIRASERVER/rpc/soap/jirasoapservice-v2?wsdl</uriwsdl>
<uriview>JIRASERVER/browse/</uriview>
<projectkey>JIRAPROJECT</projectkey>
<issuetype>1</issuetype>
<attributes>
<customFieldValues>
<customField>
<customfieldId>customfield_10000</customfieldId>
<values><value>SOME DEFAULT VALUE</value></values>
</customField>
</customFieldValues>
</attributes>
</issuetracker>

Django : Setting a generic (content_type) field with a real object sets it to None

Update 3 (Read This First) :
Yes, this was caused by the object "profile" not having been saved. For those getting the same symptoms, the moral is "If a ForeignKey field seems to be getting set to None when you assign a real object to it, it's probably because that other objects hasn't been saved."
Even if you are 100% sure that it was saved, check again ;-)
Hi,
I'm using content_type / generic foreign keys in a class in Django.
The line to create an instance of the class is roughly this :
tag = SecurityTag(name='name',agent=an_agent,resource=a_resource,interface=an_interface)
Where both agent and resource are content_type fields.
Most of the time, this works as I expect and creates the appropriate object. But I have one specific case where I call this line to create a SecurityTag but the value of the agent field seems to end up as None.
Now, in this particular case, I test, in the preceding line, that the value of an_agent does contain an existing, saved Django.model object of an agent type. And it does.
Nevertheless, the resulting SecurityTag record comes out with None for this field.
I'm quite baffled by this. I'm guessing that somewhere along the line, something is failing in the ORM's attempt to extract the id of the object in an_agent, but there's no error message nor exception being raised. I've checked that the an_agent object is saved and has a value in its id field.
Anyone seen something like this? Or have any ideas?
====
Update : 10 days later exactly the same bug has come to bite me again in a new context :
Here's some code which describes the "security tag" object, which is basically a mapping between
a) some kind of permission-role (known as "agent" in our system) which is a generic content_type,
b) a resource, which is also a generic content_type, (and in the current problem is being given a Pinax "Profile"),
and c) an "interface" (which is basically a type of access ... eg. "Viewable" or "Editable" that is just a string)
class SecurityTag(models.Model) :
name = models.CharField(max_length='50')
agent_content_type = models.ForeignKey(ContentType,related_name='security_tag_agent')
agent_object_id = models.PositiveIntegerField()
agent = generic.GenericForeignKey('agent_content_type', 'agent_object_id')
interface = models.CharField(max_length='50')
resource_content_type = models.ForeignKey(ContentType,related_name='security_tag_resource')
resource_object_id = models.PositiveIntegerField()
resource = generic.GenericForeignKey('resource_content_type', 'resource_object_id')
At a particular moment later, I do this :
print "before %s, %s" % (self.resource,self.agent)
t = SecurityTag(name=self.tag_name,agent=self.agent,resource=self.resource,interface=self.interface_id)
print "after %s, %s, %s, %s" % (t.resource,t.resource_content_type,type(t.resource),t.resource_object_id)
The result of which is that before, the "resource" variable does reference a Profile, but after ...
before phil, TgGroup object
after None, profile, <type 'NoneType'>, None
In other words, while the value of t.resource_content_type has been set to "profile", everything else is None. In my previous encounter with this problem, I "solved" it by reloading the thing I was trying to assign to the generic type. I'm starting to wonder if this is some kind of ORM cache issue ... is the variable "self.resource" holding some kind proxy object rather than the real thing?
One possibility is that the profile hasn't been saved. However, this code is being called as the result of an after_save signal for profile. (It's setting up default permissions), so could it be that the profile save hasn't been committed or something?
Update 2 : following Matthew's suggestion below, I added
print self.resource._get_pk_value() and self.resource.id
which has blown up saying Profile doesn't have _get_pk_value()
So here's what I noticed passing through the Django code: when you create a new instance of a model object via a constructor, a pre-init function called (via signals) for any generic object references.
Rather than directly storing the object you pass in, it stores the type and the primary key.
If your object is persisted and has an ID, this works fine, because when you get the field at a later date, it retrieves it from the database.
However -- if your object doesn't have an ID, the fetch code returns nothing, and the getter returns None!
You can see the code in django.contrib.contenttypes.generic.GenericForeignKey, in the instance_pre_init and __get__ functions.
This doesn't really answer my question or satisfy my curiosity but it does seem to work if I pull the an_agent object out of the database immediately before trying to use it in the SecurityTag constructor.
Previously I was passing a copy that had been made earlier with get_or_create. Did this old instance somehow go out of date or scope?