Birt Report parameter validation - validation

NewParameter is of type DATE and having Custom Format as MM/dd/yyyy in parameter window.
I have written the following code to verify whether the user is sending correct format or not. If user sends 24/12/2014 the code should throw error as Invalid format. But the following code is throwing the error even while user send the correct format e.g: 11/10/2014
importPackage(Packages.java.lang);
importPackage(Packages.java.text);
sdf = new SimpleDateFormat("MM/dd/yyyy");
testDate = null;
dateerror=false;
try {
testDate = sdf.parse(params["NewParameter"]);
dataerror=false;
} catch (e) {
errorMessage = "the date you provided is in an invalid date";
eee = e;
dateerror=true;
reportContext.getDesignHandle().findElement("mytable").drop();
}

It seems there is a confusion: when we declare a report parameter as "DATE", we don't have to parse it in report scripts because it is already a java Date object. Therefore this line of code is wrong, because the parser would expect a "String" type:
testDate = sdf.parse(params["NewParameter"]);
The custom format "MM/dd/yyyy" you linked to the report parameter is not actually used by the report engine: it is only taken into consideration by the webviewer, to specify how dates should be displayed in parameters dialog.
The best way to achieve your requirements would be to customize client-side javascript of your webviewer, in order to control date format in web-browsers. An example of this approach allows to enter dates through a calendar such here.
Otherwise if you really need to validate a format during report execution, although it is not very elegant the only way would be to set your parameter as "String" type and put your script in "Initialize" event of the report. However in this case you would have to parse it each time it is used in a dataset, or parse it once in a report variable.

Related

How to parse a json with dynamic property name in OIC?

I need to consume and parse incoming json from a third party system in my code. I used RestTemplate to do it. So the response from the system looks like below.
{ "data": { "05AAAFW9419M11Q": { "gstin": "05AAAFW9419M11Q", "error_cd": "SWEB_9035", "message": "Invalid GSTIN / UID" } } }
Now the problem is the property name ("05AAAFW9419M11Q" in this case) in dynamic and in the next response it would be another string. In this case, how can I parse this json as this is not fixed in Oracle Integration Cloud? Response wrapper is not capturing the data apart from the one that is used for configuring the adapter which is fair enough as fieldname itself is changing.
Is there is any workaround for this?
You will have to go to PL/SQL and dynamic SQL, and if it's always the value of gstin entry, you can get the path of the key with
select '$.data.' ||
json_query(js_column, '$.data.*.gstin') into v_key path from table_with_json_column where ... conditions... ;
(assuming there is only 1 "data" per JSON payload) to later build a dynamic query based on json_table.

Laravel custom request validation

i have been trying in create check on form validation on laravel
i need to query input with date and check more than check with many messages
like
if(){
$this->errorSchema->addError($error, $name); //symfony 1 way
}
how and where should i do that i have been thinking in creating custom validtaion but it returns true or false i need the date in the query to display like "this place is used for user XXX" XXX is data i got in the query
i want to return multi error if some record exist like
$resultset = 'select person form events where date < "some date"';
if ($resultset[enddate] > 'somedate'){
my error message should be "you cant add this event as $resultset['person'] overlape in this date "
}elseif($resultset[startdate] > 'somedate'){
i need here to return deffrent error message like "start date is overlapping with resultset['person']"
}
i am using requests class in laravel so please recommend me a method to override or any other way to this in laravel
thanks in advance
You can try to SELECT data which you'd like to return, your "XXX", from table by user's input.
Simple SELECT *** FROM table WHERE smth = user's_input;
If it return smth, you can just add it to your validator such as: "this place is used for user".$smth;
Else (if nothing returned, you send to user your default answer.)
Also if you add more code it will be easier to help you :)

Extract only date part in a datetimein LINQ

We have some data in a DataTable and we are using the query like this to get what we need.
IEnumerable<Results> subResult = from query in datatable.AsEnumerable()
select new Results
{
Name = query.Field<string>("Name"),
Date = query.Field<DateTime?>("Date")
}
This above query returns what i need but date in full format (Ex: m/dd/yyyy hh:min:sec am/pm) but we need only date part of it(only mm/dd/yyyy need to be pulled in). When looked in the properties of this, couldn't find an implicit way to get it, please help me in getting this result. Thanks.
The DateTime class has all the properties you just mentioned. You should try to fix your display with the ToString("anyformatyouwant") formats.
What about this?
Date = query.Field<DateTime?>("Date").Date
This will give you just the date part:
IEnumerable<Results> sub-result= from query in datatable.AsEnumerable()
where new Results
{
Name = query.Field<string>("Name"),
Date = query.Field<DateTime?>("Date").Date
}
However if you just want to display the date somewhere (meaning you're not using this to do date grouping, etc. then I would just specify the display format in your UI layer.
AFAIK there is no Date Class in .net, if you want pure date you should write a Class for that, otherwise you can pull out the part as a string
DateTime.Now.Date.ToString("yyyy/MM/dd")
gives you the current date in string type, but if you get the .Date part it gives you a DateTime object which still has a time part showing AM 12:00:00:0 blah blah

Propel ORM Version 1.6.4 -understanding validators

(reworded the question hours later to be more descriptive)
I need a little advice on understanding Propel setters/validators in a standalone (non-framework) development.
The documentation on validation states:
Validators help you to validate an input before persisting it to the database.
... and in validator messages we can provided coherent advice on where users can correct entries that don't pass Propel validation.
The sample usage of a validator reads:
$user = new User();
$user->setUsername("foo"); // only 3 in length, which is too short...
if ($objUser->validate()) {
...
The problem I have found with this is 'what if you cannot setXXX() in order to validate it?'
I have a column type DATE and I invite a visitor to enter a date in a web form. They mistype the date and submit 03/18/20q2
I would hope that one of my custom validators would be able to report a validator message and return the form once more to the user to be amended, however this occurs first:
Fatal error: Uncaught exception 'PropelException' with message 'Error parsing date/time value: '03/18/20q2' [wrapped: DateTime::__construct() [<a href='datetime.--construct'>datetime.--construct</a>]: Failed to parse time string (03/18/aaa) at position 5 (/):
In my tests I couldn't get any simple or CustomValidator to fire once I'd written (for example):
$event= new Event();
$event->setDateStart($form_value_for_date); // where values is "03/18/20q2"
I understand why this is so - it would not make sense to be able to create and try to manipulate a new object if you cannot rely on its fields, even before you save it.
The dilemma this gives me is:
If a fatal error can result from invalid entry preventing Propel validation from handling it for me (and therefore the user) and sending back a useful message, should I bother with Propel validation as well as my own security/courtesy validation ?
I cannot find any mention in the docs of what happens if you give Propel - for whatever reason - a value it doesn't anticipate for the field, or how to handle it.
I do hope this makes sense and that someone can point me at a method that will mean I only need to validate input in one place.
I've hacked together a rough ready solution that will allow me to:
Pre-validate a field against a CustomValidator without setting it in the new object
Retrieve the validator's message for return to the user
I take the form input, sanitise it of course, and then create an object:
$event = new Event();
With my user form in mind, I then pre-check the field I know will fatally fall over if the content's bad, and only set the field in my new object if it would validate:
if ($check = $event->flightCheckFail('StartingDate','DateValidator',$sanitisedFormVal))
echo $check;
else
$event->setStartingDate($sanitisedFormVal);
Method flightCheckFail() will return false if the data from the form would validate against the field, it returns the validator's error message if it would fail.
The method's added to my Event class as follows. Its arguments are the field name, the class of the CustomValidator (which simply runs an strtotime check), and the sanitised form value:
public function flightCheckFail($name,$validatorClass,$value) {
$colname = $this->getPeer()->getTableMap()->getColumnByPhpName($name)->getName();
$validators = $this->getPeer()->getTableMap()->getColumn($colname)->getValidators();
foreach($validators as $validatorMap)
if ($validatorMap->getClass() == $validatorClass) {
$validator = BasePeer::getValidator($validatorMap->getClass());
if ( $validator->isValid($validatorMap, $value) === false)
$failureMessage = $validatorMap->getMessage();
} // if $validatorMap->getClass() == $validatorClass
if($failureMessage)
return $failureMessage;
else
return false;
}
I should be able to use this to work around handling dates in forms, but I'll need to check what other types in Propel might require this sort of handling.
I can stop the form handling wherever this reports a validator error message and send it back. When the user enters valid data, Propel (and normal Propel Validation) gets to continue as normal.
If anyone can improve on this I'd love to see your results.
You could also use a MatchValidator, with a date RegExp, no need for extra functions

What is the correct date format for a Date column in YUI DataTable?

I have produced a data table. All the columns are sortable. It has a date in one column which I formatted dd/mm/yyyy hh:mm:ss . This is different from the default format as defined in the doco, but I should be able to define my own format for non-american formats. (See below)
The DataTable class provides a set of
built-in static functions to format
certain well-known types of data. In
your Column definition, if you set a
Column's formatter to
YAHOO.widget.DataTable.formatDate,
that function will render data of type
Date with the default syntax of
"MM/DD/YYYY". If you would like to
bypass a built-in formatter in favor
of your own, you can point a Column's
formatter to a custom function that
you define.
The table is generated from HTML Markup, so the data is held within "" tags.
This gives me some more clues about compatible string dates for javascript:
In general, the RecordSet expects to
hold data in native JavaScript types.
For instance, a date is expected to be
a JavaScript Date instance, not a
string like "4/26/2005" in order to
sort properly. Converting data types
as data comes into your RecordSet is
enabled through the parser property in
the fields array of your DataSource's
responseSchema
I suspect that the I'm missing something in the date format. So what is an acceptable string date for javascript, that Yui dataTable will recognise, given that I want format it as "dd/mm/yyyy hh:mm:ss" ?
Define your locale
YAHOO.util.DateLocale["pt-BR"] = YAHOO.lang.merge(YAHOO.util.DateLocale, {
x:"%d/%m/%Y"
});
And your column settings as follows
{key:"columnKey", label:"columnLabel",
formatter:function(container, record, column, data) {
container.innerHTML = YAHOO.util.Date.format(data, {format:"%x"}, "pt-BR");
}
}
Javascript is able to construct a Date using a datestring in the following format:
new Date("April 22, 2010 14:15:23");
If you don't have control of the format of the datestring on the server-side (or don't want to change it) write a custom parsing function that takes the datestring and returns a newly constructed Date object.
You could either use this parser function when constructing the data represented in your DataTable.
rows:[{name:"John",born:customParser("[date string here"]},
{name:"Bill",born:customParser("[date string here"]}
]
-OR-
If you are using Yui's DataSource module (as indicated by your second grey box), you can register this parser function on the date field so that it will already be a Date() before the DataTable is constructed.
dataSource.responseSchema = {
. . .
fields: [
...
{ key: "birth_dt", parser: customParser }
...
]
....
}
You can pass dates from server to client in any format you wish, just in DataSource.responseSchema.fields set parser field to a function that will parse it. Look for stringToDate in dynamic data example.
On client side, you can display Dates in any other format, providing function in formatter field in respective ColumnDefs.
In order to set whole DataTable's date format, set its dateOptions option; alternatively, you can set ColumnDef.dateOptions, all same as described in YAHOO.util.Date.format() docs for oConfig parameter.
For current locale and whole DataTable, it should be
var myConfigs = {
initialRequest: ...
...
// http://developer.yahoo.com/yui/docs/YAHOO.util.Date.html
dateOptions: {format: '%c'}
};
You can also set sLocale there.

Resources