Server-side Validations - Business Entity / Data Object Serv

Posted by Matheus R. Mokwa on 15-Jan-2016 10:10

I'm studying PDSOE in 11.6 and I still didn't figure out how to implement validations on server side, got this few questions that could help me developing my sample project:

1) Where do I place the validations? Inside the class.method I'm working?

For exemple: Got a class with this method of Update.

2) Do I place it before or after the SUPER? (Is there anyplace where I can check the code of the businessEntity?)

3) How can I return the error? is it with the AppError? for example:

if table.name = '' then do:
   ASSIGN clsError = NEW AppError("name must be filled").
   RETURN ERROR clsError.
end.

4) And how do i cath/show this error in kendo grid?

All Replies

Posted by Peter Judge on 15-Jan-2016 11:26

1) Where do I place the validations? Inside the class.method I'm working?

The Business Entity is the right place to do data validation. Many people do validation in the BE and I know of some who have "validation providers"  that don't care about the BE but simply work on a set of data. What you use depends on your application design. I'd start with in-BE though, since its simplest.

2) Do I place it before or after the SUPER?

Depends on what you're trying to do/prevent. Validating BEFORE the super means that you do stuff before the standard behaviour kicks in. This is where I'd do most validations for updates.
 
Code after the SUPER means after the standard behaviour. For reads I'd add code here to do aggregrations or similar.

(Is there anyplace where I can check the code of the businessEntity?)

It's shipped in $DLC/src/OpenEdge.BusinessLogic.pl.  You will have to use a tool to extract the code from there (best tool for this kind of job is PCT IMO, but there are also standalone tools in the box in $DLC/src/extractpl.bat).

3) How can I return the error? is it with the AppError? for example:

There are attributes (properties) related to ProDataSets that allow you to add error context and have those be returned. There's doc at documentation.progress.com/.../setting-and-using-error,-error-string,-and-rejec.html
 
These are primarily string/character fields and you can put whatever you want into them. If you want them to contain "better" or "nicer" errors then I'd suggest using a stringified JSON format.
 
We suggest (for Rollbase, which consumes this data too) something like
The JSON object has the following properties
    msg (mandatory) A string containing the message text.
    field (optional) A value representing the field that this message applies to
    tbl (optional) A value representing the the table this message applies to
    id (optional) A value representing the record/row this message applies to
 
You have no control over what information is returned for "real" system exceptions .

4) And how do i cath/show this error in kendo grid?

Edsel will have to chime in here :)
 
 

Posted by Matheus R. Mokwa on 18-Jan-2016 06:48

Thank for the feedback again Peter, you are being very helpful.

Again, for me this is something totaly new and unfortunatelly I still didn't get the validation, for example got this class, where I put ERROR and REJECT.

METHOD PUBLIC VOID ReadItem(
    		INPUT filter AS CHARACTER, 
    		OUTPUT DATASET dsItem):
    	
    	SUPER:ReadData(filter).
    	
    	ASSIGN BUFFER ttItem:ERROR = TRUE
	           BUFFER ttItem:REJECTED = TRUE
	           BUFFER ttItem:ERROR-STRING = "code error string".
 
    END METHOD.

But when I check the service, it stills returning me the same Json:

{
	"dsItem": {
		"ttItem": [{
			"Itemnum": 1,
			"ItemName": "Fins",
			"Price": 24.0,
			"Onhand": 13022,
			"Allocated": 9399,
			"ReOrder": 1,
			"OnOrder": 433,
			"CatPage": 1,
			"CatDescription": "These real shark-skin fins will knock 'em dead at the beach.  They'll see you coming from miles away while you're wearing the Original \"Fins\" by Bench\/Lee. ",
			"Category1": "Diving",
			"Category2": "Footwear",
			"Special": "1",
			"Weight": 4.0,
			"Minqty": 5
		}]
	}
}

Shouldn't it return to me some kind of error in the json? How can I add this properties that you mentioned (msg/field/tbl/id) to my response?

EDIT:

My bad, now that I restarted the oepas it's showing to me an abl error, I'll modified and see if there is something new.

{"_errors":[{"_errorMsg":"Erro de 4GL: O registro ttItem nao esta disponivel para configurar ERROR. (11916) (7211)","_errorNum":11916}]}

This thread is closed