How to raise ADF EO Validation Error from Groovy - oracle-adf

I have an Entity validation of type script expression defined. Based on which validation logic (described in groovy) fails, I need to throw the respective error.
The groovy logic is as follows,
if( attr1.compareTo('a')){
adf.error.raise(argument1);
return false;
}
if( attr1.compareTo('b')){
adf.error.raise(argument2);
return false;
}
return true;
I have Added the messages under Failure Handling Tab as shown below
Screenshot
Now the problem is, I dont know what the argument should be?
I couldn't find any documentation online about this.
When Message Id (check screenshot) is provided as input, following error is obtained,
STRINGMANAGER: Key: not found in bundle oracle.javatools.resourcebundle.ResourceBundleRT

Related

catch exception in angularJS

I just went through an angular-fullstack application and i came across this piece of code:
catch( function(err) {
err = err.data;
$scope.errors = {};
// Update validity of form fields that match the mongoose errors
angular.forEach(err.errors, function(error, field) {
form[field].$setValidity('mongoose', false);
$scope.errors[field] = error.message;
});
I understand the piece of code what it is trying to say but i want to know if suppose an error occur what exactly is passed to function(error, field). i unable to interpret what happens if error occurred. so that i'll able to know what is actually happening in this code
This piece of code is in a controller
Can anyone please explain the whole procedure with example?
Looks like you're "catching" errors (probably returned from a restful service) and mapping each error in the error array to it's specific field.
The validity of that field is then set to false, which is something held by the angular form.
Finally, there is some sort of binding to $scope.errors that displays each error message that is added to the $scope.errors array.
Looks like pretty simple and typical validation. It has nothing to do with core angular error handling and is simply a way to add validation information to the form/page.

How to exit a testcase in protractor if element contains value

I've been writing a suite of tests in Protractor, and am almost finished. I'm having difficulty figuring out how to do something fairly common though. I want to be able to check if a textbox contains a value, and if so, exit the testcase with a failure. (If the textbox contains a value, I know there's no chance the test case can pass anyway)
I'm currently trying something like this:
tasksPage.generalInformationDateOfBirthTextbox.getAttribute('value').then(function(attr){
//attr contains the correct value in the textbox here but how do I return it to parent scope so I can exit the test case?
console.log("attr length is " + attr.length);
expect(attr.length).toBe(0);
},function(err){
console.log("An error was caught while evaluating Date of Birth text value: " + err);
});
The expect statement fails as I'd expect it to, but the testcase keeps going, which seems to be the intended behavior of expect. So I tried returning a true/false from within the 'then' block, but I can't seem to figure out how to return that value to the parent scope to make a determination on. In other words, if I change the above to:
var trueFalse = tasksPage.generalInformationDateOfBirthTextbox.getAttribute('value').then(function(attr){
if(attr === ""){
return true;
}else{
return false;
}
},function(err){
console.log("An error was caught while evaluating Date of Birth text value: " + err);
});
//This is the 'it' block's scope
if(trueFalse == true){
return;
}
I know my inexperience with promises is probably to blame for this trouble. Basically, I just want a way of saying, 'if such and such textbox contains text, stop the test case with a failure'.
Thanks,
This is not a protractor issue, it is a testing framework issue (jasmine, mocha etc).
Though, there was an issue on protractor's issue tracker:
--fail-fast CLI option
which was closed with a reference to an opened issue in jasmine issue tracker:
Feature Request - fail-fast option
While this is not implemented, there is a workaround (originally mentioned here):
jasmine-bail-fast package
After installing the module with npm, when you want your test to fail and exit, add:
jasmine.getEnv().bailFast();
(don't forget to load the dependency require('jasmine-bail-fast');)
Also see:
Does jasmine-node offer any type of "fail fast" option?
The issue with the code above is that you are trying to compare a 'Promise' and a 'value'.
trueFalse.then(function(value)
{
if(value)
....
});
OR compare it via an expect statement. Something like expect(trueFalse).toBe(false);

Calling getValidationErrors() with breezejs entity validation in angularjs ng-repeat causes errors

Let say we have a simple entity level validator like this:
function entityIdIsValidFn(entity,context) {
if (entity.Id1)
return true;
if (entity.Id2)
return true;
return false;
}
var entityIdValidator = new breeze.Validator("entityIdValidator", entityIdIsValidFn, { messageTemplate: "Id1 or Id2 must be defined" });
var entityType = manager.metadataStore.getEntityType("Entity");
entityType.validators.push(entityIdValidator);
Now if I try to display validation error messages in a angularjs view like this:
<div ng-repeat="error in selectedEntity.entityAspect.getValidationErrors() " class="alert alert-danger">{{error.errorMessage}}</div>
I get a bunch of Error: 10 $digest() iterations reached. Aborting! errors.
If I have validators only attached to properties validation errors will display just fine but once I attach avalidator to an entity type I run into trouble. Anybody got an idea why this happens and consequently how to display validation error messages correctly?
Any help would be much appreciated.
While I did not get your error I had no problem reproducing one of my own. There is a Breeze bug in getValidationErrors (line 3839 of breeze.debug.js v.1.4.6) where it iterates over the error collection, testing the property name.
ve.property.name === propertyName
An entity-level validation error (ve) does not have a property and therefore the code fails with a null reference error while trying to access the undefined property.name.
A temporary workaround might be to patch this line with
ve.property && ve.property.name === propertyName
We've fixed it in GitHub. It will appear in the next (1.4.7) release. Thanks for reporting it.

cakephp: no save, no validate errors, no callbacks, empty sql log

In my controller i have this add function:
public function add(){
$this->layout = false;
if($this->request->is('post')){
$this->Paciente->create();
$this->Paciente->set($this->request->data);
if ($this->Paciente->validates()) {
if($this->Paciente->save()){
$this->set('status', '200');
} else {
// debug($this->Paciente->validationErrors);
// ini_set('memory_limit', '-1');
// var_dump($this->Paciente);
$this->set('status', '101');
// $log = $this->Paciente->getDataSource()->getLog(false, false);
// debug($log);
// die;
}
} else {
// didn't validate logic
// $errors = $this->Paciente->validationErrors;
// debug($errors);
$this->set('status', '100');
}
} else
$this->set('status', '404');
}
I'm sending the post info and the status is always 101. As you can see I have tried a lot to find out where is the error, but no luck.
Also I don't have any callback in my Model (beforeSave, afterSave...)...
Anyone knows what is happening?
Your
if ($this->Paciente->validates()) {
if($this->Paciente->save()) {
}
is wrong.
You are validating twice.
Please - as documented - either use false (save(null, false)) to not invalidate twice or simply remove the validates() part here.
You can directly do:
if ($this->Paciente->save($this->request->data)) {}
This itself is unlikely causing your issue, though.
Or do you have some custom validation rules that on second (and faulty) trigger will make a field invalidate?
You can confirm that by checking $this->Paciente->validationErrors afterwards. It should be empty. If it does not save (and it's for sure no callback), and if it does not throw exceptions due to SQL errors then it most likely are your validation rules.
The problem was in the way i was sending the post info:
I was setting the variables as data['Model']['var'] and the correct way is data[Model][var]
Thanks #mark, #AD7six, #liyakat and #Alex for your help in the problem.
I can't imagine. When you set your array values like above it would likely break in php5.3 >

CakePHP redirecting on error

I'm receiving a strange error from my call to query() the database. This normally wouldn't be a problem, except that it seems that the query call is redirecting me to the 500 server error page and not executing the rest of my code.
Regardless of the error, this PHP is executed during an AJAX call, meaning that I'm unable to return a properly formatted json string containing the error because CakePHP is redirecting.
A workaround would be to just parse the big HTML response from the server if there is an error, and use javascript to figure out what went wrong and display it properly, but I would much rather return a little json string from the backend that plays nicely with the code I already have in place.
Here is my call:
$this->FileUpload->query('exec sproc_runjob_ProcessTests', false);
Any help would be much appreciated. Thanks in advance!
As bfavaretto mentions above, the correct answer is to surround the query line in a try catch.
Here is the code I used:
try{
$this->dbParent->FileUpload->query('exec sproc_runjob_ProcessTests', false);
} catch(PDOException $e){
if($e['errorInfo'][0] == 42000 && $e['errorInfo'][1] == 22022)
return array('error' => 'sproc_blocked');
}
return array('success'=>true);

Resources