Skip to content

Commit

Permalink
Add PENDING_COMPLETE status and refactor order status handling
Browse files Browse the repository at this point in the history
#deploy-organisasjon-bestilling-service

Introduce the PENDING_COMPLETE status to track orders awaiting completion. Removed logging in OrganisasjonBestillingConsumer and refactored OrderServiceV2 to return appropriate statuses. Commented out unused methods in EregBatchStatusConsumer to reduce redundancy.
  • Loading branch information
krharum committed Sep 16, 2024
1 parent e51cfd3 commit 8ea6d18
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,27 @@ public EregBatchStatusConsumer(
.baseUrl(serverProperties.getUrl())
.build();
}

public Long getStatusKode(no.nav.testnav.apps.organisasjonbestillingservice.domain.v1.Order order) {
var accessToken = tokenExchange.exchange(serverProperties).block();
var command = new GetEregBatchStatusCommand(
webClient,
order.getBatchId(),
accessToken.getTokenValue(),
order.getMiljo()
);
return command.call();
}

public Long getStatusKode(Order order) {
var accessToken = tokenExchange.exchange(serverProperties).block();
var command = new GetEregBatchStatusCommand(
webClient,
order.getBatchId(),
accessToken.getTokenValue(),
order.getMiljo()
);
return command.call();
}
//
// public Long getStatusKode(no.nav.testnav.apps.organisasjonbestillingservice.domain.v1.Order order) {
// var accessToken = tokenExchange.exchange(serverProperties).block();
// var command = new GetEregBatchStatusCommand(
// webClient,
// order.getBatchId(),
// accessToken.getTokenValue(),
// order.getMiljo()
// );
// return command.call();
// }
//
// public Long getStatusKode(Order order) {
// var accessToken = tokenExchange.exchange(serverProperties).block();
// var command = new GetEregBatchStatusCommand(
// webClient,
// order.getBatchId(),
// accessToken.getTokenValue(),
// order.getMiljo()
// );
// return command.call();
// }

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import no.nav.testnav.apps.organisasjonbestillingservice.consumer.EregBatchStatusConsumer;
import no.nav.testnav.apps.organisasjonbestillingservice.consumer.JenkinsConsumer;
import no.nav.testnav.apps.organisasjonbestillingservice.domain.v2.Order;
import no.nav.testnav.apps.organisasjonbestillingservice.repository.v2.OrderRepositoryV2;
Expand All @@ -11,7 +10,6 @@
import no.nav.testnav.apps.organisasjonbestillingservice.service.RetryService;
import no.nav.testnav.libs.dto.organisajonbestilling.v2.Status;
import org.springframework.stereotype.Service;
import org.springframework.web.reactive.function.client.WebClientResponseException;

import java.util.List;
import java.util.regex.Pattern;
Expand All @@ -25,7 +23,6 @@ public class OrderServiceV2 {
private final OrderRepositoryV2 repository;
private final JenkinsConsumer jenkinsConsumer;
private final RetryService retryService;
private final EregBatchStatusConsumer eregBatchStatusConsumer;

public Order save(Order order) {
OrderEntity saved = repository.save(order.toEntity());
Expand Down Expand Up @@ -57,13 +54,8 @@ public Status getStatus(Long id) {
var order = entity.get();

if (order.getBatchId() != null) {
try {

return getStatusFromBatchId(new Order(order));
} catch (WebClientResponseException.NotFound e) {
log.info("Fant ikke noen status for org: {}", id);
return null;
}
return Status.NOT_FOUND;
}

if (order.getBuildId() == null) {
Expand Down Expand Up @@ -94,7 +86,7 @@ public Status getStatus(Long id) {
return Status.RUNNING;
}
repository.save(order);
return getStatusFromBatchId(new Order(order));
return Status.PENDING_COMPLETE;
}

public List<Order> find(String uuid) {
Expand All @@ -113,10 +105,10 @@ public List<Order> findAll() {
.toList();
}

private Status getStatusFromBatchId(Order order) {
var statusKode = eregBatchStatusConsumer.getStatusKode(order);
return Status.from(statusKode);
}
// private Status getStatusFromBatchId(Order order) {
// var statusKode = eregBatchStatusConsumer.getStatusKode(order);
// return Status.from(statusKode);
// }

private Long findIDFromLog(String value) {
log.info("Prøver å hente ut id fra log: {}.", value);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package no.nav.organisasjonforvalter.consumer;

import lombok.extern.slf4j.Slf4j;
import no.nav.organisasjonforvalter.config.Consumers;
import no.nav.organisasjonforvalter.consumer.command.OrganisasjonBestillingIdsCommand;
import no.nav.organisasjonforvalter.consumer.command.OrganisasjonBestillingStatusCommand;
Expand All @@ -9,11 +8,9 @@
import no.nav.testnav.libs.securitycore.domain.ServerProperties;
import no.nav.testnav.libs.servletsecurity.exchange.TokenExchange;
import org.springframework.stereotype.Service;

import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Flux;

@Slf4j
@Service
public class OrganisasjonBestillingConsumer {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public enum Status {
ADDING_TO_QUEUE,
IN_QUEUE_WAITING_TO_START,
RUNNING,
PENDING_COMPLETE,
COMPLETED,
ERROR,
FAILED;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ private static String getDescription(Status status) {
case ERROR -> "Ukjent feil";
case FAILED -> "Ukjent kristisk feil";
case RUNNING -> "Bestillingen blir prosessert av EREG";
case PENDING_COMPLETE -> "Venter på status av oppretting";
case COMPLETED -> "Bestilling er fullført";
case NOT_FOUND -> "Finner ikke bestilling. Loggene kan ha blitt slettet";
case ADDING_TO_QUEUE -> "Bestillingen venter på tildeling av plass i køen";
Expand Down

0 comments on commit 8ea6d18

Please sign in to comment.