In my java application (spring boot), I'm trying to check if a specific date for Malaysia is a public holiday or not and the challenge is each state has its own Regional holidays on top of the national public holidays which has to be considered.
So my question is that can I do such a thing using Google Calendar API?
I've found this Post but I'm not sure if that would do what I'm trying to achieve.
I've combined some public resources and I'd do that this way:
You want to call for a calendar with id: en.malaysia#holiday#group.v.calendar.google.com
Call:
GET https://www.googleapis.com/calendar/v3/calendars/{calendarId}
Authorisation:
This request requires authorization with at least one of the following scopes (...): https://www.googleapis.com/auth/calendar.readonly or https://www.googleapis.com/auth/calendar
--Api
--StackOverflow answer
--List of supported national calendars
Related
I'm using WhoisClient (org.apache.commons.net.whois.WhoisClient) to retrieve my website domain expiry date. It is working for the domain with .com extension. When I try to check the expiry date for one of my .org domain the result says No match for domain.org. How do I find out the expiry date of a .org and .in extension domain?
I'm using the following code for getting the expiry date of the domain
String domainName = mydomain.replaceFirst("^(http[s]?://www\\.|http[s]?://|www\\.)","");
WhoisClient whois = new WhoisClient();
whois.connect(WhoisClient.DEFAULT_HOST);
String whoisData1 = whois.query("=" + domainName);
whois.disconnect();
Do not bother with the whois protocol.
Now (since August 26th, 2019) per ICANN requirements, all gTLDs need to have an RDAP server. RDAP is like the successor of whois: kind of the same content exchanged but this time on top of HTTPS with some fixed JSON format. Hence, trivial to parse.
The expiry date will be in the "events" array with an action called "expiration".
You can go to https://data.iana.org/rdap/dns.json to find out the .ORG RDAP server, it is at URL https://rdap.publicinterestregistry.net/rdap/org/
You need to learn a little more about RDAP to understand how to use it (structure of the query and the reply), you can find some introduction at https://about.rdap.org/
But in short your case, this emulates what you need to do:
$ wget -qO - https://rdap.publicinterestregistry.net/rdap/org/domain/slashdot.org | jq '.events[] | select(.eventAction | contains("expiration")) | .eventDate'
"2019-10-04T04:00:00.000Z"
PS1: if you get no match from a whois query normally it really means that the domain does not exist; it could also be because of rate limiting
PS2: .IN may not have an RDAP server yet, since it is a ccTLD it is not bound by ICANN rules.
I have an application started on tomcat on MACHINE_A with timezone GMT+3.
I use remote MySQL server started on MACHINE_B with timezone UTC.
We use spring-data-jpa for persistence.
As an example of the problem, I will show the repository:
public interface MyRepository extends JpaRepository<MyInstance, Long> {
Optional<MyInstance> findByDate(LocalDate localDate);
}
If I pass localDate for 2018-09-06, I get entities where the date is 2018-09-05(previous day)
In the logs I see:
2018-09-06 18:17:27.783 TRACE 13676 --- [nio-8080-exec-3] o.h.type.descriptor.sql.BasicBinder : binding parameter [1] as [DATE] - [2018-09-06]
I googled that question a lot and found several articles with the same content(for example https://moelholm.com/2016/11/09/spring-boot-controlling-timezones-with-hibernate/)
So, I have the following application.yml:
spring:
datasource:
url: jdbc:mysql://localhost:3306/MYDB?useUnicode=true&characterEncoding=utf8&useSSL=false&useLegacyDatetimeCode=false&serverTimezone=UTC
username: root
password: *****
jpa:
hibernate:
naming:
physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
properties:
hibernate:
show_sql: true
use_sql_comments: true
format_sql: true
type: trace
jdbc:
time_zone: UTC
But it doesn't help.
We use the following connector:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.12</version>
</dependency>
How can I resolve my problem?
P.S.
I tried to run both applications with the same time zone. In this case, everything works as expected.
P.S.2
I tried to use MySQL driver 6.0.6 version but it doesn't change anything.
If you're using LocalDate in Java, you should use a DATE column in MySQL. This way the problem will be solved.
If you use LocalDateTime, try setting the property like this in Spring Boot:
spring.jpa.properties.hibernate.jdbc.time_zone=UTC
To see it working in action, you can find a test case in my High-Performance Java Persistence GitHub repository which demonstrates how this setting works with MySQL.
I faced similar issues while creating some integration tests for a spring-boot application using hibernate. The database I used here was postgreSQL.
As another answer correctly points out, you can set the hibernate.jdbc.time_zone=UTC property like discribed. Nevermind this didn't solve my issues, so I had to set the JVM default time zone with the help of the following in my spring-boot applications main class:
#PostConstruct
public void init(){
TimeZone.setDefault(TimeZone.getTimeZone("UTC")); // It will set UTC timezone
System.out.println("Spring boot application running in UTC timezone :"+new Date()); // It will print UTC timezone
}
This should also solve your problems. You can gather more informations here.
Reason
I guess your problem (retrieving date - 1 day) comes from your specific setup. If your application is running in UTC and requesting timestamps from a database in GMT+3 it resolves in a earlier date, because the applications context (JVM and Hibernate are responsible here) is 3 hours behind the database context in UTC. Simple example:
2018-12-02 00:00:00 - 3hours = 2018-12-01 21:00:00
As you are only looking to the dates: 2018-12-02 - 3hours = 2018-12-01
There was a bug in the MySQL Connector prior to version 8.0.22, see Spring data query for localdate returns wrong entries - minus one day
Ideally, your both servers should be in same time zone and preferred one be in UTC time zone. And to show correct time to user in his timezone; you parse it in browser itself. And while retrieving data from DB; you use UTC time. This way you will not have issue while fetching data from DB
In MySQL...
TIMESTAMP internally stores UTC, but converts to/from the server's timezone based on two settings. Check those settings via SHOW VARIABLES LIKE '%zone%'; Properly configured, the reader may see a different time than the writer (based on tz settings).
DATE and DATETIME take whatever you give it. There is no tz conversion between the string in the client and what is stored in the table. Think of it a storing a picture of a clock. The reader will see the same time string that the writer wrote.
spring.jpa.properties.hibernate.jdbc.time_zone=UTC
It's used when you are working TimeZoned Date, but from your logs it seems you are not passing TimeZone:
binding parameter [1] as [DATE] - [2018-09-06]
Try to remote property:
spring.jpa.properties.hibernate.jdbc.time_zone=UTC
If you add the following parsing to your HQL query, it will return a date without any time zone format or time of day. This is a quick workaround to your issue.
select DATE_FORMAT(date,'%Y-%m-%d') from Entity
I've done everything as instructed in the answers before, like
Adding spring.jpa.properties.hibernate.jdbc.time_zone=America/Sao_Paulo
Setting default timezone: TimeZone.setDefault(TimeZone.getTimeZone("America/Sao_Paulo"))
but none of them worked until I add the parameter serverTimezone=America/Sao_Paulo in my JDBC url:
jdbc:mysql://localhost:3306/aurorabuzz-test?serverTimezone=America/Sao_Paulo
Now it's working just fine!
I am trying to automate a scenario, where i need to enter card details like name on card, card number, expiry date and CVC number. When i am trying to send the expiry date say as "2318", by default it is accepting value as "23/8". Ideally it should accept value as "23/18". I tried to give space in month and year but still it's not working. Any idea how to automate this?
following is my piece of code :
#Override
public void enterCardDetails() {
waitForElement(appiumDriver,enterNameOnCardEditField).sendKeys("test");
waitForElement(appiumDriver,enterCardNumberEditField).sendKeys("0000000000000000");
waitForElement(appiumDriver,enterExpiryMMYYEditField).sendKeys("2518");
waitForElement(appiumDriver,enterCVCNumberField).sendKeys("000");
waitForElement(appiumDriver,makePaymentOption).click();
}
I am using following appium and selenium versions :
appium-java client : 6.0.0-BETA5
appium Desktop version : 1.6.1
Selenium java version : 3.9.1
Unfortunately, I can not provide any screenshot of the appium inspector.
As per your question what you are seeing is pretty much expected and is a result of validation error on the field for expiry date.
Essentially, the expiry date on any Credit Card would consist of MM/YY format, where:
MM field would accept character sequence e.g. 01, 10, 12, etc
YY field would accept character sequence e.g. 18, 19, 20, etc
Now whenever you try to send the character sequence of 2318 the js involved for the validation doesn't accepts the characters and in absence of a proper js validator allows the characters 23 and 8 within the MM and YY fields respectively.
It's a pottential bug which may have escaped Manual Validation
Solution
Send a valid character sequence as follows:
waitForElement(appiumDriver,enterExpiryMMYYEditField).sendKeys("0718");
I was able to solve this issue by adding following capability :
capabilities.setCapability("maxTypingFrequency",10);
I have searched for a while but I didn't find anything in the play documentation :
I have a class customer that contains a date :
private Date birthday;
My controller creates the object by binding the request params :
Form<Customer> userForm = form(Customer.class);
Customer customer = userForm.bindFromRequest().get();
At runtime, I get this error :
Caused by: java.lang.IllegalStateException: No value
at play.libs.F$None.get(F.java:702) ~[play_2.10-2.2.3.jar:2.2.3]
at play.data.Form.get(Form.java:540) ~[play-java_2.10-2.2.3.jar:2.2.3]
I figured out that the problem comes from my date format that is submitted with this pattern : dd/MM/yyyy.
I was not able to find how to configure play to set this pattern for french users.
The only thing I found and that works is to use this annotation :
#Formats.DateTime(pattern="dd/MM/yyyy")
private Date birthday;
I'm not satisfied because I don't want to put this annotation everywhere : the date format depends on the user local and should not be a const.
Moreover the play2 documentation does not explain what is the default pattern if nothing is specified...
I'd like to have a conf like that :
date.format.en = MM/dd/yyyy
date.format.fr = dd/MM/yyy
Do you know if it is possible with play2 ?
Any help would be appreciated :D
I can create a google calendar in my Java app.
I can assign it to a particular user in my Google domain:
AclRule rule = new AclRule();
Scope scope = new Scope();
scope.setType("user");
scope.setValue("user1#mydomain.com");
rule.setScope(scope);
rule.setRole("reader");
and the created calendar appears in user1's calendars.
Yet when I try to assign some other calendar to a group (which said user1 belongs to):
AclRule rule = new AclRule();
Scope scope = new Scope();
scope.setType("group");
scope.setValue("group1#mydomain.com");
rule.setScope(scope);
rule.setRole("reader");
user1 couldn't see the created calendar in his calendar list.
But the calendar is created successfully.
Is this correct functionality? Or should I just add Acl rule per group user?
Or I am doing something wrong and there is other way to assign some calendar to all the users in a group?
for future people running into problems: I had this issue and it's because the creator of the calendar wasn't in the group. Make sure the "sharer" is in the google group you are sharing your calendar with
When assigning Calendar access to a group, every group user gets an invitation to said Calendar.