Ippezrobert commented on a change in pull request #714: Allow Using Custom
Tenant date from database (Custom Requirement)
URL: https://github.com/apache/fineract/pull/714#discussion_r382524197
##########
File path:
fineract-provider/src/main/java/org/apache/fineract/infrastructure/core/service/DateUtils.java
##########
@@ -59,28 +64,50 @@ public static Date getDateOfTenant() {
return getLocalDateOfTenant().toDateTimeAtStartOfDay().toDate();
}
- public static LocalDate getLocalDateOfTenant() {
-
- LocalDate today = new LocalDate();
-
+public static LocalDate getLocalDateOfTenant() {
+ SecurityContext context = SecurityContextHolder.getContext();
+ Authentication authentication = null;
+ LocalDate today = new LocalDate();
+
+ if(context != null) {
+ authentication = context.getAuthentication();
+ }
+ if(authentication != null && authentication.isAuthenticated() &&
authentication.getPrincipal() instanceof AppUser) {
+ AppUser user = (AppUser) authentication.getPrincipal();
+ final Long officeId = user.getOffice().getId();
+ today = new
LocalDate(OfficeRepository.getCurrentDateOfTenant(officeId));
+ }
+ return today;
+
+ /*LocalDate today = new LocalDate();
final DateTimeZone zone = getDateTimeZoneOfTenant();
if (zone != null) {
today = new LocalDate(zone);
}
-
- return today;
+ return today;*/
}
public static LocalDateTime getLocalDateTimeOfTenant() {
+ SecurityContext context = SecurityContextHolder.getContext();
+ Authentication authentication = null;
+ LocalDateTime today = new LocalDateTime();
+
+ if(context != null) {
+ authentication = context.getAuthentication();
+ }
+ if(authentication != null && authentication.isAuthenticated() &&
authentication.getPrincipal() instanceof AppUser) {
+ AppUser user = (AppUser) authentication.getPrincipal();
+ final Long officeId = user.getOffice().getId();
+ today = new
LocalDateTime(OfficeRepository.getCurrentDateOfTenant(officeId));
Review comment:
Another error is here
> error: non-static method getCurrentDateOfTenant(Long) cannot be referenced
from a static context
> today = new
LocalDateTime(OfficeRepository.getCurrentDateOfTenant(officeId));
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services