package com.osdu.service.google;

import com.google.common.collect.ImmutableMap;
import com.osdu.model.job.IngestJob;
import com.osdu.model.job.IngestJobStatus;
import com.osdu.model.job.IngestJobStatusDto;
import com.osdu.repository.IngestJobRepository;
import com.osdu.service.JobStatusService;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.messaging.MessageHeaders;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
@Slf4j
public class GcpJobStatusService implements JobStatusService {

  final IngestJobRepository ingestJobRepository;

  @Override
  public IngestJobStatusDto getStatus(String jobId, MessageHeaders headers) {
    log.info("Request for getting a injection job status. JobId: {}, headers: {}", jobId, headers);
    IngestJob job = ingestJobRepository.findById(jobId);

    log.info("Found the injection job: {}", job);
    return IngestJobStatusDto.fromIngestJob(job);
  }

  @Override
  public IngestJob get(String jobId) {
    log.info("Request for getting a injection job. JobId: {}", jobId);
    return ingestJobRepository.findById(jobId);
  }

  @Override
  public String initInjectJob() {
    log.info("Initiating a new injection job");
    String jobId = UUID.randomUUID().toString();
    ingestJobRepository.save(IngestJob.builder()
        .id(jobId)
        .status(IngestJobStatus.CREATED)
        .build());

    log.info("Created a new running injection job. JobId: {}", jobId);
    return jobId;
  }

  @Override
  public void updateJobStatus(String jobId, IngestJobStatus status) {
    log.info("Update the injection job status. JobId: {}, status: {}", jobId, status);
    ingestJobRepository.updateFields(jobId, ImmutableMap.of("status", status.name()));
    log.info("Updated the injection job status. Status: {}", status);
  }

  @Override
  public void save(IngestJob ingestJob) {
    log.info("Update the ingestion job. Job: {}", ingestJob);
    ingestJobRepository.save(ingestJob);
  }
}

@@ -27,16 +27,80 @@
 oogle;%0A%0A
+import static com.osdu.request.OsduHeader.extractHeaderByName;%0A%0A
 import c
@@ -138,16 +138,16 @@
 bleMap;%0A
-
 import c
@@ -312,16 +312,99 @@
 sitory;%0A
+import com.osdu.request.OsduHeader;%0Aimport com.osdu.service.AuthenticationService;%0A
 import c
@@ -739,16 +739,69 @@
 vice %7B%0A%0A
+  final AuthenticationService authenticationService;%0A
   final 
@@ -928,24 +928,24 @@
  headers) %7B%0A
-
     log.info
@@ -1028,24 +1028,277 @@
 , headers);%0A
+%0A    String authorizationToken = extractHeaderByName(headers, OsduHeader.AUTHORIZATION);%0A    String partition = extractHeaderByName(headers, OsduHeader.PARTITION);%0A%0A    authenticationService%0A        .checkAuthentication(authorizationToken, partition);%0A%0A
     IngestJo

Add checking authentication for ingest job status function.