Grails 2.2 'request' keyword at domain - grails

I developed application using grails 2.1.2 then I upgrade to 2.2.0
I have a domain class
class Concurrence {
Concurrence parent = null
Request request
Person approver
int status = 0
Date processed = null
}
class Request {
String no
Folder folder
String fiscalYear
String notes
static hasOne = [category: Category, channel : Channel]
Date created
Date submitted = null
Date approved = null
Date updated
Person requestor
int status = 0
boolean deleted = false
Person processedBy = null
boolean processed = false
Date processedDate = null
static hasMany = [documents:RequestDocument, concurrences:Concurrence, approvals:Approval, finalApprovals:FinalApproval, memos:Memo]
}
there is a property 'request' on Concurrence
Previously everything is ok, but after I use grails 2.2.0, that domain can't be saved,
Field 'request_id' doesn't have a default value
any suggestion how to solved this problem? Or I must downgrade to 2.1.2 or rename request property name?
best regards

The variable reqeust is a keyword in Grails that references the request object. With that said I think your first step should be picking a variable name that does not conflict with any default Grails objects.

Related

how to change Grails GORM id column name and use sequence

In a Grails/GORM app, can I rename the implicit domain id column to entity_id and auto-increment using an existing sequence?
class Practitioner {
Long entityId
String providerName
static mapping = {
id name: 'entityId', column: 'entity_id', generator:'sequence', params:[sequence:'hibernate_sequence']
}
}
Attempting to save in console fails, (and yes, sequence exists in my local Postgres database)
Practitioner p = new Practitioner(providerName: 'p')
p.save(flush:true, failOnError: true)
Error
grails.validation.ValidationException: Validation Error(s) occurred during save():
- Field error in object
'com.transcendinsights.dp.measureresult.snapshot.Practitioner' on field 'entityId': rejected value [null]; codes
Super thanks for helping!

Grails Elasticsearch plugin issues

I am new to Elasticsearch and am using the revived grails plugin "elasticsearch:0.0.4.6".
I wanted to implement a search for a User by their firstName, surname or username, which returns the full domain instance.
I have a 2 domain classes:
User:
class User {
String firstName
String surname
static hasOne = [profile:Profile]
static hasMany = [friends:User]
static mappedBy = [ friends: 'friends' ]
static searchable = {
profile component:true
only = ['firstName', 'surname', 'profile']
}
...
Profile:
class Profile {
String username
String status
byte[] photo
static belongsTo = [user:User]
static searchable = true
...
}
I made the classes "searchable = true" and then created the following search:
def res = User.search("${params.friendSearch}").searchResults
This found the correct instances, but now when a user adds a photo to their profile, it suceeds but I recieve a never ending loop of the following error:
ERROR index.IndexRequestQueue - Failed bulk item: MapperParsingException[failed to parse [photo]]; nested: NumberFor
matException[For input string: the photos base64inputstring
I dont really get what is happening, but i figure it must be something to do with elasticsearch being unable to index the photo data. Can somebody provide an explanation?
I then experimented with searchables custom mapping options -
profile index:'no'
all=false
excludeFromAll = true
etc
Nothing worked. Eventually I added
only = ['username']
and it stopped the error from occuring and allowed me to find users based on the criteria i mentioned above. However, because of the "only" limit, it means that the User instances returned by the seach have a photo property equal to null, but i need this value!
What am i doing wrong? Can anyone advise me on the best course of action to take or any misunderstandings i have about Elasticsearch? Thanks
I think you might have to exclude the byte property photo from the searchable fields like so:
class Profile {
String username
String status
byte[] photo
static belongsTo = [user:User]
static searchable = {
except = ['photo']
}
This will exclude the property photo from being indexed and search. Hence the output of converting the byte format to string format will not fail.
Also maybe you might need a custom convertor to change the byte(string) to something more usable in the results?

Grails run-app command objects not working after upgrade 2.2.1 to 2.3.6

I reached next problem after upgrade grails 2.2.1 to 2.3.6
I think any of my Command object in controllers not working for example:
I had Command Object like that:
#ToString
#grails.validation.Validateable
class ListUserRoleCommand {
String userId
User getUser() { User.get(userId) }
static constraints = {
userId nullable: false
user nullable: false
}
}
I had entry in UrlMapping.groovy:
"/user/$userId/role"(controller: "userRole", parseRequest: true) { action = [GET: "list", POST: "save"] }
That shoud bind request: my-app/user/4324gf54f4f34r3ff/role with command object in controller UserRoleController and 'list' action (I'm sending GET method)
But I getting validation exception on userId.
Field error in object 'pl.fissst.invoice.security.ListUserRoleCommand' on field 'userId': rejected value [null]
I'm println $params to console and I had correct data:
params: [userId:ff808181458ff92401458ff94e150005, action:[GET:list, POST:save], controller:userRole, start:0, end:24, count:25, sort:[:], filter:[:]]
I checked other parts in application, and I'm think that other command objects not working too.
I had that entries in Config.groovy:
grails.databinding.convertEmptyStringsToNull = false
grails.databinding.trimStrings = false
so that isn't problem of empty sting.
Anyone can help ?
EDIT1:
One more think. If I set in Config.groovy:
grails.databinding.useSpringBinder = false
application starts works almost properly. Now only some commands not work. But If I set grails.databinding.useSpringBinder to true, I think any of command object not wok.
Why partial of command objects stop working ?
EDIT2:
I noticed that command object has bind partial data.
I noticed too, that this part of data which was binded is comming from post data , but this part whih is comming was missed from url (Urlmapping url params like $id)
EDIT3:
For above:
I looking on a Web, and I found some threads where people says that :
parseRequest
from Urlmapping not work anymore in grils 2.3.x. Is that true ? How can I handle that ?

Unable to create new domain object in Grails

Hi there i am still very new to grails and I have not been able to figure out why this is happening.
I have a domain class:
package scheduler
class Client {
String name
static constraints = {}
}
And a controller:
package scheduler
class AdminController {
def create() {
def client = new Client(name:"John")
println client
}
}
Currently I am always getting null for client. Originally the above was a little more complex on the domain class side but I systematically dumbed it down to see if it was a problem there. I still can not get the above working.
The output is always
scheduler.Client : null
Please let me know if I need to provide anymore information.
It's not null, that's just the default output of the toString method that Grails adds. It prints the class name and the id. Since you haven't saved the instance, the id is null. If the instance was null the output would have been null, not scheduler.Client : null
If you want to see the data in the instance, use the Groovy dump() method, e.g.
def client = new Client(name:"John")
println client.dump()
You could also add a toString method that includes the name attribute, e.g.
package scheduler
class Client {
String name
String toString() { name }
}

Accessing flow scope in grails service

I have and WebFlow in my controller, and simple flow-scoped service. Somewhere close to the end of my web flow, I need to validate my command object field against value I received earlier in the web flow. For this I created a simple flow-scoped service:
class EventFlowService implements Serializable {
static transactional = false
static scope = "flow"
Date getEventStartDate(){
flow.basicData.eventDate
}
}
I don't need my service anywhere else than in a command object, so I inject it to my command object, like so:
class EventRestrictionsCommand implements Serializable{
def eventFlowService
boolean onlineRegistration
Date onlineRegistrationEnd
Date onlineRegistrationStart
static constraints = {
onlineRegistrationEnd validator: {val, obj ->
if(obj.onlineRegistration){
return val > obj.onlineRegistrationStart || val <= obj.eventFlowService.getEventStartDate()
}
return null
}
}
}
The problem is that I get exception saying, that there is no flow property in my service. Is there any way I can get access to flow storage in my flow-scoped service?
I met the SAME issue before and worked it out by installing webflow plugin in GRAILS:
grails install-plugin webflow
Say, the new version of grails surports webflow well by installing webflow plugin.

Resources