Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public GatewayServiceClient(WebClient.Builder webClient,
}

public Mono<Void> sendConsentRequest(String cmSuffix, ConsentRequest request) {
logger.warn("gateway " + gateway.token());
return gateway.token()
.flatMap(token -> webClient
.post()
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/in/org/projecteka/hiu/common/CustomScheduler.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
import reactor.core.publisher.Mono;

import java.time.Duration;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.function.Consumer;
import java.util.function.Function;

import static in.org.projecteka.hiu.common.Constants.IST;
import static reactor.core.publisher.Mono.error;

@AllArgsConstructor
Expand Down Expand Up @@ -47,15 +49,15 @@ public static <T> CustomScheduler<T> scheduleThis(Mono<T> producer) {
public static Function<Flux<Long>, Publisher<?>> exponentialBackOff(Duration minimum,
Duration maximum,
Duration timeout) {
Instant finish = Instant.now().plus(timeout);
LocalDateTime finish = LocalDateTime.now(ZoneId.of(IST)).plus(timeout);
return iterations -> getDelay(minimum, maximum, finish, iterations);
}

private static Flux<?> getDelay(Duration minimum, Duration maximum, Instant finish, Flux<Long> iterations) {
private static Flux<?> getDelay(Duration minimum, Duration maximum, LocalDateTime finish, Flux<Long> iterations) {
return iterations
.map(iteration -> calculateDuration(minimum, maximum, iteration))
.concatMap(delay -> {
if (Instant.now().isAfter(finish)) {
if (LocalDateTime.now(ZoneId.of(IST)).isAfter(finish)) {
return error(new DelayTimeoutException());
}
return Mono.delay(delay).doOnSubscribe(logDelay(delay));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import reactor.util.retry.Retry;

import java.time.Duration;
import java.time.ZoneId;

import static in.org.projecteka.hiu.common.Constants.IST;
import static java.lang.String.format;
import static java.time.Duration.ofMinutes;
import static java.time.LocalDateTime.now;
Expand Down Expand Up @@ -50,7 +52,7 @@ private <U> Mono<U> retryable(Mono<U> producer) {
.doOnError(error -> logger.error(error.getMessage(), error))
.retryWhen(Retry
.backoff(retry, Duration.ofMillis(100)).jitter(0d)
.doAfterRetry(rs -> logger.error(RETRIED_AT, now()))
.doAfterRetry(rs -> logger.error(RETRIED_AT, now(ZoneId.of(IST))))
.onRetryExhaustedThrow((spec, rs) -> rs.failure()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketAddress;
import java.time.ZoneId;
import java.util.concurrent.TimeoutException;

import static in.org.projecteka.hiu.Error.of;
import static in.org.projecteka.hiu.common.Constants.IST;
import static in.org.projecteka.hiu.common.heartbeat.model.Status.DOWN;
import static in.org.projecteka.hiu.common.heartbeat.model.Status.UP;
import static java.lang.String.format;
import static java.time.LocalDateTime.now;
import static java.time.ZoneOffset.UTC;
import static reactor.core.publisher.Mono.just;


Expand All @@ -35,12 +36,12 @@ public class Heartbeat {
public Mono<HeartbeatResponse> getStatus() {
try {
if (cacheHealth.isUp() && isRabbitMQUp() && isPostgresUp()) {
return just(HeartbeatResponse.builder().timeStamp(now(UTC)).status(UP).build());
return just(HeartbeatResponse.builder().timeStamp(now(ZoneId.of(IST))).status(UP).build());
}
return just(HeartbeatResponse.builder().timeStamp(now(UTC)).status(DOWN).error(of(SERVICE_DOWN)).build());
return just(HeartbeatResponse.builder().timeStamp(now(ZoneId.of(IST))).status(DOWN).error(of(SERVICE_DOWN)).build());
} catch (IOException | TimeoutException e) {
logger.error(format("Heartbeat is not healthy with failure: %s", e.getMessage()), e);
return just(HeartbeatResponse.builder().timeStamp(now(UTC)).status(DOWN).error(of(SERVICE_DOWN)).build());
return just(HeartbeatResponse.builder().timeStamp(now(ZoneId.of(IST))).status(DOWN).error(of(SERVICE_DOWN)).build());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;

import java.time.ZoneId;

import static in.org.projecteka.hiu.common.Constants.IST;
import static in.org.projecteka.hiu.common.heartbeat.model.Status.UP;
import static java.time.LocalDateTime.now;
import static java.time.ZoneOffset.UTC;
import static org.springframework.http.HttpStatus.OK;
import static org.springframework.http.HttpStatus.SERVICE_UNAVAILABLE;

Expand All @@ -33,7 +35,7 @@ public Mono<ResponseEntity<HeartbeatResponse>> getReadiness() {
public Mono<ResponseEntity<HeartbeatResponse>> getLiveliness() {
HeartbeatResponse heartbeatResponse = HeartbeatResponse.builder()
.status(UP)
.timeStamp(now(UTC))
.timeStamp(now(ZoneId.of(IST)))
.build();
return Mono.just(new ResponseEntity<>(heartbeatResponse, OK));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import in.org.projecteka.hiu.consent.model.GatewayConsentArtefactResponse;
import in.org.projecteka.hiu.consent.model.HiuConsentNotificationRequest;
import lombok.AllArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
Expand All @@ -32,9 +34,12 @@
@AllArgsConstructor
public class ConsentController {
private final ConsentService consentService;
private static final Logger logger = LoggerFactory.getLogger(ConsentController.class);

@PostMapping(APP_PATH_HIU_CONSENT_REQUESTS)
public Mono<ResponseEntity<HttpStatus>> postConsentRequest(@RequestBody ConsentRequestData consentRequestData) {
logger.warn("consentRequest " + consentRequestData.getConsent());
logger.warn("ExpiredDate " + consentRequestData.getConsent().getPermission().getDataEraseAt());
return ReactiveSecurityContextHolder.getContext()
.map(securityContext -> (Caller) securityContext.getAuthentication().getPrincipal())
.map(Caller::getUsername)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@
import reactor.core.publisher.Mono;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.HashMap;
import java.util.Map;

import static in.org.projecteka.hiu.ClientError.consentArtefactNotFound;
import static in.org.projecteka.hiu.ClientError.consentRequestNotFound;
import static in.org.projecteka.hiu.ClientError.dbOperationFailure;
import static in.org.projecteka.hiu.common.Constants.IST;
import static in.org.projecteka.hiu.common.Constants.STATUS;
import static in.org.projecteka.hiu.common.Serializer.from;
import static in.org.projecteka.hiu.common.Serializer.to;
Expand Down Expand Up @@ -153,7 +155,7 @@ public Mono<Void> insertConsentArtefact(ConsentArtefact consentArtefact,
new JsonObject(from(consentArtefact)),
consentArtefact.getConsentId(),
status.toString(),
LocalDateTime.now()),
LocalDateTime.now(ZoneId.of(IST))),
handler -> {
if (handler.failed()) {
logger.error(handler.cause().getMessage(), handler.cause());
Expand Down Expand Up @@ -316,7 +318,7 @@ public Mono<Void> updateConsentRequestStatus(String gatewayRequestId,
String consentRequestId) {
return Mono.create(monoSink ->
readWriteClient.preparedQuery(UPDATE_GATEWAY_CONSENT_REQUEST_STATUS)
.execute(Tuple.of(consentRequestId, status.toString(), LocalDateTime.now(), gatewayRequestId),
.execute(Tuple.of(consentRequestId, status.toString(), LocalDateTime.now(ZoneId.of(IST)), gatewayRequestId),
handler -> {
if (handler.failed()) {
logger.error(handler.cause().getMessage(), handler.cause());
Expand Down Expand Up @@ -355,7 +357,7 @@ public Flux<Map<String, Object>> requestsOf(String requesterId) {
public Mono<Void> updateConsentRequestStatus(ConsentStatus status, String consentRequestId) {
return Mono.create(monoSink ->
readWriteClient.preparedQuery(UPDATE_CONSENT_REQUEST_STATUS)
.execute(Tuple.of(consentRequestId, status.toString(), LocalDateTime.now()),
.execute(Tuple.of(consentRequestId, status.toString(), LocalDateTime.now(ZoneId.of(IST))),
handler -> {
if (handler.failed()) {
logger.error(handler.cause().getMessage(), handler.cause());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import javax.annotation.PostConstruct;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -113,12 +114,17 @@ private Mono<Void> sendConsentRequestToGateway(
UUID gatewayRequestId) {
var reqInfo = hiRequest.getConsent().to(requesterId, hiuProperties.getId(), conceptValidator);
var patientId = hiRequest.getConsent().getPatient().getId();
logger.warn("sendConsentRequestToGateway");
logger.warn("now(IST) " + now(ZoneId.of("Asia/Calcutta")));
logger.warn("now() " + now());
var consentRequest = ConsentRequest.builder()
.requestId(gatewayRequestId)
.timestamp(now(UTC))
.consent(reqInfo)
.build();
logger.warn("consentRequest " + consentRequest);
var hiuConsentRequest = hiRequest.getConsent().toConsentRequest(gatewayRequestId.toString(), requesterId);
logger.warn("hiuConsentRequest " + hiuConsentRequest);
return gatewayServiceClient.sendConsentRequest(getCmSuffix(patientId), consentRequest)
.then(defer(() -> consentRepository.insertConsentRequestToGateway(hiuConsentRequest)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
import reactor.core.publisher.Mono;

import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import static in.org.projecteka.hiu.ClientError.consentArtefactNotFound;
import static in.org.projecteka.hiu.common.Constants.IST;
import static in.org.projecteka.hiu.common.Constants.getCmSuffix;
import static in.org.projecteka.hiu.consent.model.ConsentStatus.EXPIRED;
import static in.org.projecteka.hiu.consent.model.consentmanager.ConsentAcknowledgementStatus.OK;
Expand Down Expand Up @@ -59,7 +60,7 @@ private ConsentOnNotifyRequest buildConsentOnNotifyRequest(List<ConsentArtefact>
var requestId = UUID.randomUUID();
var consentArtefactRequest = ConsentOnNotifyRequest
.builder()
.timestamp(LocalDateTime.now(ZoneOffset.UTC))
.timestamp(LocalDateTime.now(ZoneId.of(IST)))
.requestId(requestId);
var acknowledgements = new ArrayList<ConsentAcknowledgement>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
import reactor.core.publisher.Mono;

import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.ZoneId;
import java.util.UUID;

import static in.org.projecteka.hiu.common.Constants.IST;
import static in.org.projecteka.hiu.common.Constants.getCmSuffix;
import static in.org.projecteka.hiu.consent.model.ConsentStatus.GRANTED;
import static reactor.core.publisher.Flux.fromIterable;
Expand All @@ -40,7 +41,7 @@ private Mono<Void> perform(ConsentArtefactReference reference, String consentReq
var consentArtefactRequest = ConsentArtefactRequest
.builder()
.consentId(reference.getId())
.timestamp(LocalDateTime.now(ZoneOffset.UTC))
.timestamp(LocalDateTime.now(ZoneId.of(IST)))
.requestId(requestId)
.build();
return gatewayClient.requestConsentArtefact(consentArtefactRequest, cmSuffix);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@
import in.org.projecteka.hiu.dataflow.model.PatientDataRequestDetail;
import in.org.projecteka.hiu.dataflow.model.PatientHealthInfoStatus;
import lombok.AllArgsConstructor;
import org.apache.log4j.Logger;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
Expand All @@ -34,15 +36,14 @@
import java.util.Set;
import java.util.UUID;
import java.util.function.BiFunction;
import java.util.function.Predicate;
import java.util.stream.Collectors;

import static in.org.projecteka.hiu.ErrorCode.INVALID_PURPOSE_OF_USE;
import static in.org.projecteka.hiu.common.Constants.IST;
import static in.org.projecteka.hiu.common.Constants.EMPTY_STRING;
import static in.org.projecteka.hiu.common.Constants.PATIENT_REQUESTED_PURPOSE_CODE;
import static in.org.projecteka.hiu.common.Constants.getCmSuffix;
import static java.time.LocalDateTime.now;
import static java.time.ZoneOffset.UTC;
import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR;
import static reactor.core.publisher.Mono.defer;
import static reactor.core.publisher.Mono.just;
Expand All @@ -58,6 +59,7 @@ public class PatientConsentService {
private final GatewayServiceClient gatewayServiceClient;
private BiFunction<List<String>, String, Flux<PatientHealthInfoStatus>> healthInfoStatus;
private final PatientHIUCertService patientHIUCertService;
private final Logger logger = Logger.getLogger(PatientConsentService.class);

public Mono<List<Map<String, Object>>> getLatestCareContextResourceDates(String patientId, String hipId) {
return patientConsentRepository.getLatestResourceDateByHipCareContext(patientId, hipId);
Expand Down Expand Up @@ -99,7 +101,7 @@ public Mono<Map<String, String>> handlePatientConsentRequest(String requesterId,
}))
.flatMapMany(Flux::fromIterable)
.flatMap(hipId -> buildConsentRequest(requesterId, hipId,
now(UTC).minusYears(consentServiceProperties.getConsentRequestFromYears())))
now(ZoneId.of(IST)).minusYears(consentServiceProperties.getConsentRequestFromYears())))
.flatMap(consentRequestData -> generateConsentRequestForSelf(consentRequestData)
.map(dataReqId -> Map.entry(consentRequestData.getConsent().getHipId(), dataReqId)))
.collectList()
Expand All @@ -113,7 +115,7 @@ public Mono<Map<String, String>> handlePatientConsentRequest(String requesterId,
private List<PatientDataRequestDetail> filterRequestAfterThreshold(List<PatientDataRequestDetail> dataRequestDetails) {
return dataRequestDetails.stream()
.filter(dataRequestDetail -> !dataRequestDetail.getPatientDataRequestedAt()
.isAfter(now(UTC).minusMinutes(consentServiceProperties.getConsentRequestDelay())))
.isAfter(now(ZoneId.of(IST)).minusMinutes(consentServiceProperties.getConsentRequestDelay())))
.collect(Collectors.toList());

}
Expand All @@ -123,7 +125,11 @@ private List<String> filterEmptyAndNullValues(List<String> ids) {
}

private Mono<ConsentRequestData> handleForReloadConsent(String patientId, String hipId) {
LocalDateTime now = now(UTC);
LocalDateTime now = now(ZoneId.of(IST));
logger.warn("handleForReloadConsent");
logger.warn("now(IST) " + now(ZoneId.of("Asia/Calcutta")));
logger.warn("now() " + now());
logger.warn("now " + now);

return patientConsentRepository.deletePatientConsentRequestFor(patientId)
.flatMap(patientConsentRepository::deleteConsentRequestFor)
Expand All @@ -150,11 +156,11 @@ private Mono<ConsentRequestData> buildConsentRequest(String requesterId, String
return just(ConsentRequestData.builder().consent(Consent.builder()
.hiTypes(getAllApplicableHITypes())
.patient(Patient.builder().id(requesterId).build())
.permission(Permission.builder().dataEraseAt(now(UTC)
.permission(Permission.builder().dataEraseAt(now(ZoneId.of(IST))
.plusMonths(consentServiceProperties.getConsentExpiryInMonths()))
.dateRange(DateRange.builder()
.from(dateFrom)
.to(now(UTC)).build())
.to(now(ZoneId.of(IST))).build())
.build())
.purpose(new Purpose(PATIENT_REQUESTED_PURPOSE_CODE))
.hipId(hipId)
Expand Down Expand Up @@ -206,7 +212,7 @@ private Mono<Void> sendConsentRequestToGateway(
var patientId = hiRequest.getConsent().getPatient().getId();
var consentRequest = ConsentRequest.builder()
.requestId(gatewayRequestId)
.timestamp(now(UTC))
.timestamp(now(ZoneId.of(IST)))
.consent(reqInfo)
.build();
var hiuConsentRequest = hiRequest.getConsent().toConsentRequest(gatewayRequestId.toString(), requesterId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
import reactor.core.publisher.Mono;

import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import static in.org.projecteka.hiu.ClientError.consentArtefactNotFound;
import static in.org.projecteka.hiu.common.Constants.IST;
import static in.org.projecteka.hiu.common.Constants.getCmSuffix;
import static in.org.projecteka.hiu.consent.model.ConsentStatus.EXPIRED;
import static in.org.projecteka.hiu.consent.model.ConsentStatus.REVOKED;
Expand Down Expand Up @@ -60,7 +61,7 @@ private ConsentOnNotifyRequest buildConsentOnNotifyRequest(List<ConsentArtefact>
var requestId = UUID.randomUUID();
var consentArtefactRequest = ConsentOnNotifyRequest
.builder()
.timestamp(LocalDateTime.now(ZoneOffset.UTC))
.timestamp(LocalDateTime.now(ZoneId.of(IST)))
.requestId(requestId);
var acknowledgements = new ArrayList<ConsentAcknowledgement>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@

import javax.validation.Valid;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.List;

import static in.org.projecteka.hiu.common.Constants.IST;
import static in.org.projecteka.hiu.consent.model.consentmanager.Frequency.ONE_HOUR;

@JsonIgnoreProperties(ignoreUnknown = true)
Expand Down Expand Up @@ -63,7 +65,7 @@ public ConsentRequest toConsentRequest(String id, String requesterId) {
.hiTypes(getHiTypes())
.permission(getPermission())
.status(ConsentStatus.REQUESTED)
.createdDate(LocalDateTime.now())
.createdDate(LocalDateTime.now(ZoneId.of(IST)))
.hip(hip)
.careContexts(getCareContexts())
.build();
Expand Down
Loading