-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added show timezone command * updated thorntail to 2.3.0.Final * updated what to support up to 255 characters * internal code restructuring and refactoring
- Loading branch information
1 parent
b0f4a16
commit 98d102f
Showing
9 changed files
with
241 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
src/main/java/gr/cytech/chatreminderbot/rest/controlCases/CaseShowTimezones.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package gr.cytech.chatreminderbot.rest.controlCases; | ||
|
||
import gr.cytech.chatreminderbot.rest.message.Request; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import javax.persistence.EntityManager; | ||
import javax.persistence.NoResultException; | ||
import javax.persistence.PersistenceContext; | ||
import javax.transaction.Transactional; | ||
|
||
public class CaseShowTimezones { | ||
private final static Logger logger = LoggerFactory.getLogger(CaseShowReminders.class.getName()); | ||
|
||
@PersistenceContext(name = "wa") | ||
public EntityManager entityManager; | ||
|
||
private Request request; | ||
|
||
public Request getRequest() { | ||
return request; | ||
} | ||
|
||
public CaseShowTimezones() { | ||
|
||
} | ||
public boolean defaultTimezoneExists() { | ||
return entityManager.createQuery("SELECT t from TimeZone t where t.userid = :default") | ||
.setParameter("default","default") | ||
.getResultList().size() == 1; | ||
} | ||
|
||
@Transactional | ||
String showTimezones(Request request) { | ||
this.request = request; | ||
String showTimezone = "---- Your timezone is ---- \n"; | ||
String noTimezoneFound = "---- No Timezone found default timezone is ---- \n"; | ||
String defaultTimezone = "---- Default timezone is ---- \n"; | ||
|
||
if (!defaultTimezoneExists()){ | ||
logger.info("created default timezone"); | ||
TimeZone timeZone = new TimeZone("Europe/Athens","default"); | ||
entityManager.persist(timeZone); | ||
|
||
} | ||
|
||
TimeZone defaultTimezoneQuery = (TimeZone) entityManager.createNamedQuery("show.timezones") | ||
.setParameter("id","default") | ||
.getSingleResult(); | ||
try { | ||
|
||
TimeZone myTimezone = (TimeZone) entityManager | ||
.createNamedQuery("show.timezones") | ||
.setParameter("id", request.getMessage().getSender().getName()) | ||
.getSingleResult(); | ||
|
||
return showTimezone + "Timezone = " + myTimezone.toString() + "\n " + defaultTimezone + | ||
"Timezone = " + defaultTimezoneQuery.toString(); | ||
|
||
} catch (NoResultException e) { | ||
logger.info("in case no timezone found for the user"); | ||
return noTimezoneFound + "Timezone = " + defaultTimezoneQuery.toString(); | ||
|
||
} | ||
|
||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ALTER TABLE reminder ALTER COLUMN what TYPE varchar(255); |
Oops, something went wrong.