Skip to content

Commit

Permalink
Bugfix/hellodata 1118 wrong timezone in announcements (#7)
Browse files Browse the repository at this point in the history
* HELLODATA-1118 - fix timezone fetch to system default

* fix build

---------

Co-authored-by: Slawomir Wieczorek <slawomir.wieczorek@bedag.ch>
  • Loading branch information
wieczorslawo and Slawomir Wieczorek authored Jan 19, 2024
1 parent da30e4c commit bd8d64c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,18 @@
import com.fasterxml.jackson.databind.SerializerProvider;
import java.io.IOException;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import lombok.extern.log4j.Log4j2;

@Log4j2
public class LocalDateTimeToMillisSerializer extends JsonSerializer<LocalDateTime> {

@Override
public void serialize(LocalDateTime value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
gen.writeNumber(value.toEpochSecond(ZoneOffset.UTC) * 1000L);
log.debug("Serializing date {}", value);
ZonedDateTime zdt = ZonedDateTime.of(value, ZoneId.systemDefault());
gen.writeNumber(zdt.toInstant().toEpochMilli());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
import ch.bedag.dap.hellodata.portal.superset.data.UpdateSupersetDashboardMetadataDto;
import ch.bedag.dap.hellodata.portal.superset.entity.DashboardMetadataEntity;
import ch.bedag.dap.hellodata.portal.superset.repository.DashboardMetadataRepository;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.apache.commons.collections4.CollectionUtils;
Expand Down Expand Up @@ -146,7 +148,8 @@ private void fetchMetadata(String instanceName, SupersetDashboard dashboard, Sup
dashboardDto.setScheduled(dashboardMetadataEntity.getScheduled());
dashboardDto.setDatasource(dashboardMetadataEntity.getDatasource());
LocalDateTime lastAccessDate = dashboardMetadataEntity.getModifiedDate() != null ? dashboardMetadataEntity.getModifiedDate() : dashboardMetadataEntity.getCreatedDate();
long metadataModifiedBy = lastAccessDate.toInstant(ZoneOffset.UTC).toEpochMilli();
ZonedDateTime zdt = ZonedDateTime.of(lastAccessDate, ZoneId.systemDefault());
long metadataModifiedBy =zdt.toInstant().toEpochMilli();
dashboardDto.setModified(Math.max(changedOnUtcInSuperset, metadataModifiedBy));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void toSimpleMailMessage_when_user_deactivated_should_generate_correct_ht
Document actualDoc = Jsoup.parse(Objects.requireNonNull(email.getText()));

//then
assertThat(expectedDoc.html()).isEqualTo(actualDoc.html());
assertThat(actualDoc.html()).isEqualTo(expectedDoc.html());
}

@Test
Expand Down Expand Up @@ -115,7 +115,7 @@ public void toSimpleMailMessage_when_user_activated_should_generate_correct_html
Document actualDoc = Jsoup.parse(Objects.requireNonNull(email.getText()));

//then
assertThat(expectedDoc.html()).isEqualTo(actualDoc.html());
assertThat(actualDoc.html()).isEqualTo(expectedDoc.html());
}

@Test
Expand Down Expand Up @@ -162,7 +162,7 @@ public void toSimpleMailMessage_when_user_role_changed_should_generate_correct_h
Document actualDoc = Jsoup.parse(Objects.requireNonNull(email.getText()));

//then
assertThat(expectedDoc.html()).isEqualTo(actualDoc.html());
assertThat(actualDoc.html()).isEqualTo(expectedDoc.html());
}

@Test
Expand Down Expand Up @@ -210,6 +210,6 @@ public void toSimpleMailMessage_when_user_account_created_should_generate_correc
Document actualDoc = Jsoup.parse(Objects.requireNonNull(email.getText()));

//then
assertThat(expectedDoc.html()).isEqualTo(actualDoc.html());
assertThat(actualDoc.html()).isEqualTo(expectedDoc.html());
}
}

0 comments on commit bd8d64c

Please sign in to comment.