I am using Play Framework 1.2.5. I have a couple of validations related to NAme and Age field. The Age validation is not working properly. Even if the age is greater than 18, I am getting the error message.
Below is the validation code in action method:
Error nameError = validation.required(txtName).error;
Error ageError = validation.required(txtAge).error;
Error minAgeError = validation.min(txtAge,18).error;
if(nameError!=null)
System.out.println(nameError.message("Customer Name"));
if(ageError!=null)
System.out.println(ageError.message("Customer Age"));
if(minAgeError!=null)
System.out.println(minAgeError.message("Minimun Age"));
Below is the messages fiule entries:
validation.required=%s is required
validation.min=%s cannot be lower than %2$d
How to make it work? No able to figure what am I misisng over here :(
Please help.
You are not using the validation logic according to the documentation. Try this instead:
public static void hello(String txtName, Integer txtAge) {
validation.required(txtName);
validation.required(txtAge);
validation.min(txtAge, 18);
if(validation.hasErrors()) {
for(Error error : validation.errors()) {
System.out.println(error.message());
}
}
}
Related
I faced an issue with google pay with stripe. The problem is that I fully
followed the documentation and get an obscure error. I have this onGooglePayResult and i always have Result.Failed with error - " java.lang.RuntimeException: Google Pay failed with error 10 " And error code 2.Feel free to ask i can answer on all your questions.
Main error is java.lang.RuntimeException: Google Pay failed with error 10:. This is coming in GooglePayPaymentMethodLauncher.Result.Failed. I really can't understand why this is producing, I've checked stripe documentation twice, google pay set up and everything, but can't find out.
I mean how to find out what is real error message is, I try to find anything related to this but unfortunatelythere is simply nothing of the kind.
Logcat - error = java.lang.RuntimeException: Google Pay failed with error 10: + error code = 2
private fun onGooglePayResult(
result: GooglePayPaymentMethodLauncher.Result
) {
when (result) {
is GooglePayPaymentMethodLauncher.Result.Completed -> {
// Payment details successfully captured.
// Send the paymentMethodId to your server to finalize payment.
val paymentMethodId = result.paymentMethod.id
presenter.payPlanWithGooglePay(deviceIdentifier, paymentMethodId)
}
GooglePayPaymentMethodLauncher.Result.Canceled -> {
// User cancelled the operation
Timber.d("Cancel")
}
is GooglePayPaymentMethodLauncher.Result.Failed -> {
// Operation failed; inspect `result.error` for the exception
Timber.d("error = ${result.error} + error code = ${result.errorCode}")
}
}
}
I've resolved this issue, was my fault. I forget to add the PUBLISHABLE key from the stripe developer portal.
I use this function to set up Google pay. Just substitute TEST_PUBLISHABLE_KEY with your key in stripe account(Website).
private fun setUpGooglePay(): GooglePayPaymentMethodLauncher {
PaymentConfiguration.init(this, TEST_PUBLISHABLE_KEY)
return GooglePayPaymentMethodLauncher(
activity = this,
config = GooglePayPaymentMethodLauncher.Config(
environment = GooglePayEnvironment.Test,
merchantCountryCode = Constants.GooglePay.Manx.COUNTRY_CODE,
merchantName = UIUtils.getString(R.string.app_name)
),
readyCallback = ::onGooglePayReady,
resultCallback = ::onGooglePayResult
)
}
I'm trying to add push notification to my mobile native chat app. I'm trying to use OneSignal.
I can send manual push notification, so I think gradle part is okay
idsAvaiable method is deprecated, I started to looking for how can I get userId.
OSPermissionSubscriptionState status = OneSignal.getPermissionSubscriptionState();
String userId = status.getSubscriptionStatus().getUserId();
In here, I'm trying to get userId with status, but it's saying:
Cannot resolve symbol 'OSPermissionSubscriptionState'
How can I get userId?
Root cause
From OneSignal API 4.0.0, there are many APIs that have been removed including OSPermissionSubscriptionState.
Solution 1
Use OneSignal.getDeviceState()
OSDeviceState device = OneSignal.getDeviceState();
String userId = device.getUserId();
Solution 2
Use OneSignal.addSubscriptionObserver()
OneSignal.addSubscriptionObserver(new OSSubscriptionObserver() {
#Override
public void onOSSubscriptionChanged(OSSubscriptionStateChanges stateChanges) {
if (!stateChanges.getFrom().isSubscribed() && stateChanges.getTo().isSubscribed()) {
// Get user id
String userId = stateChanges.getTo().getUserId();
}
}
});
For more information, see the change log here.
I am trying to send data from my android app to my REST service so that it can be stored on a database. I have successfully done this in another app that I have worked on and when I am trying to do it with this project I am getting this error:
org.hibernate.QueryException: could not resolve property: line_type
In my Oracle Database the field is named "LINE_TYPE" and is VARCHAR2(20 BYTE).
Here is the code in my REST service table (which I have reverse engineered from my oracle database):
private String lineType;
#Column(name="LINE_TYPE")
#Size(max = 20, message = "Line Type has a max size of 20 characters.")
public String getLineType() {
return this.lineType;
}
public void setLineType(String lineType) {
this.lineType = lineType;
}
Also in my tableCriteria I have the getters and setters:
public String getLineType() {
return lineType;
}
public void setLineType(String lineType) {
this.lineType = lineType;
}
The last time I had this error it was through a spelling mistake or case sensitivity but I have double and triple checked and that is not the case here.
I have debugged the entity that the REST service is receiving in NetBeans and I can see that it is receiving the data. So why cant it be resolved?
Anyone see anything I don't?
Need a quick help. I am a newbie in QuickFixJ. I have a FIX message in a txt file. I need to convert that into FIX50SP2 format. I am enclosing the code snippet.
String fixMsg = "1128=99=25535=X49=CME34=47134052=20100318-03:21:11.36475=20120904268=2279=122=848=336683=607400107=ESU2269=1270=140575271=152273=121014000336=2346=521023=1279=122=848=336683=607401107=ESU2269=1270=140600271=206273=121014000336=2346=681023=210=159";
System.out.println("FixMsg String:"+fixMsg);
Message FIXMessage = new Message();
DataDictionary dd = new DataDictionary("FIX50SP2.xml");
FIXMessage.fromString(fixMsg, dd, false);
System.out.println("FIXMessage Output:" + FIXMessage.toString()); // Print message after parsing
MsgType msgType = new MsgType();
System.out.println(FIXMessage.getField(msgType));
Here is the output:
FixMsg String:1128=99=15835=X49=CME34=47164052=2012090312102051175=20120904268=1279=122=848=336683=607745107=ESU2269=1270=140575271=123273=121020000336=2346=501023=110=205
FIXMessage Output:9=6135=X34=47164049=CME52=2012090312102051175=20120904268=110=117
quickfix.FieldNotFound: Field [35] was not found in message.
at quickfix.FieldMap.getField(FieldMap.java:216)
at quickfix.FieldMap.getFieldInternal(FieldMap.java:353)
at quickfix.FieldMap.getField(FieldMap.java:349)
at MainApp.main(MainApp.java:52)
I want to extract MsgType field (field 35). Could you please tell me where I am wrong? The thing I have observed is that after parsing to FIX50SP2 format, the convert FIX message is missing many data element (for details see the output)
Thanks
Like others mentioned the MsgType is an header field and you get it by using the following
String msgType = null;
if(FIXMessage.getHeader().isSetField(MsgType.FIELD)) {
msgType = FIXMessage.getHeader().getString(MsgType.FIELD);
}
System.out.println("MsgType is " + msgType);`
The reason you are missing many data element after parsing is, probably your message have some custom tags(like tag 2346), which is not defined in your data dictionary(FIXSP02.xml). hence the parsing of those tags failed and missing in the output.
To fix this, get the data dictionary from the party that is sending you the message and use it to parse the message
I'm not familiar with FIX messages and QuickFixJ, but glancing at the Javadoc, it seems like you should use the identifyType method :
String fixMsg = "1128=99=25535=X49=CME34=47134052=20100318-03:21:11.36475=20120904268=2279=122=848=336683=607400107=ESU2269=1270=140575271=152273=121014000336=2346=521023=1279=122=848=336683=607401107=ESU2269=1270=140600271=206273=121014000336=2346=681023=210=159";
MsgType msgType = Message.identifyType(fixMsg);
You may find FixB framework useful as it deals well with non-standard use cases of FIX.
As in your case, to extract only data you are interested in, you need to define a class that will represent this data and to bind it to FIX using annotations. E.g.:
#FixBlock
public class MDEntry {
#FixField(tag=269) public int entryType; // you could define an enum type for it as well
#FixField(tag=278) public String entryId;
#FixField(tag=55) public String symbol;
}
...
FixFieldExtractor fixExtractor = new NativeFixFieldExtractor();
List<MDEntry> mdEntries = fixExtractor.getGroups(fixMsg, List.class, 268, FixMetaScanner.scanClass(MDEntry.class))
In more common cases, FixSerializer interface should be used, but it requires a message with MsgType(35) tag and a class annotated with #FixMessage(type="...") accordingly. E.g.:
#FixMessage(type="X")
public class MarketData {
#FixGroup(tag=268) public List<MDEntry> entries;
}
...
FixMetaDictionary fixMetaDictionary = FixMetaScanner.scanClassesIn("my.fix.classes.package");
FixSerializer fixSerializer = new NativeFixSerializer("FIX.5.0.SP2", fixMetaDictionary);
MarketData marketData = fixSerializer.deserialize(fixMsg);
I hope you will find it useful.
If you need just a MsgTyp, you're sure the message is correct and you do not need any other field from the message, then I would recommend extracting MsgType from string using regexp.
e.g.: \u000135=(\w+)\u0001
It is MUCH FASTER than parsing (and validating) a string via QuickFix.
I have written an Apex Scheduler class to send an email when a colleagues Birthday is 2 days away. I have created a contact with a birthday 2 days away. The contact's birthday is the July 29, 2012. Today's date is July 27, 2012.
I'm stuck. I don't get an error message or anything. I have scheduled the class to run today at 12. I didn't get an email (either telling me it was someone's birthday (success) or an error message from Salesforce telling me my code could not run (failure)
To trouble shoot, I also tried if (contact.Next_Birthday__c = : system.Today().addDays(2)) for the email method and got an incompatible types error. Next_Birthday__c is a date field, so I'm unsure of why the types are incompatible or why this SOQL statement doesn't work.
Any advice would be appreciated. Here is my code.
global class BirthdayNameOptions implements Schedulable{
global void execute (SchedulableContext ctx)
{
sendBirthdayEmail();
}
public void sendBirthdayEmail()
{
for(Contact con : [SELECT Name FROM Contact WHERE Next_Birthday__c = : system.Today().addDays(2)])
{
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setTemplateId('00XJ0000000M31w');
mail.setTargetObjectId('005J0000000');
mail.setSaveAsActivity(false);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail });
}
}
}
I believe you want to set the targetObjectId of your outbound email message to the Contact whose birthday it is, rather than hardcoding it...the value 005J0000000 in your code doesn't seem to be a valid ID either, which could be causing you to not receive the email. For testing purposes you'd want to make sure the Contact record's email is set to yours, so you receive the notification. Also, you only get 10 calls to Messaging.sendEmail() per execution, so I bulkified this a bit for you. Give this a shot:
global class BirthdayNameOptions implements Schedulable {
global void execute (SchedulableContext ctx) {
sendBirthdayEmail();
}
public void sendBirthdayEmail() {
List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();
for ( Contact con : [SELECT Id, Name FROM Contact WHERE Next_Birthday__c = : system.Today().addDays(2)] ) {
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setTemplateId('00XJ0000000M31w');
mail.setTargetObjectId(con.Id);
mail.setSaveAsActivity(false);
mails.add(mail);
}
if ( mails.size() > 0 )
Messaging.sendEmail(mails, false);
}
}