Skip to content

Commit

Permalink
feat(impl):[#259] remove owned field from Job
Browse files Browse the repository at this point in the history
  • Loading branch information
ds-ext-kmassalski committed Dec 20, 2023
1 parent 3ff7a7a commit 7a3c626
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 118 deletions.
9 changes: 0 additions & 9 deletions docs/src/api/irs-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -992,7 +992,6 @@ components:
globalAssetId: urn:uuid:6c311d29-5753-46d4-b32c-19b918ea93b0
id: e5347c88-a921-11ec-b909-0242ac120002
lastModifiedOn: 2022-02-03T14:48:54.709Z
owner: ""
parameter:
aspects:
- SerialPart
Expand Down Expand Up @@ -1043,7 +1042,6 @@ components:
globalAssetId: urn:uuid:6c311d29-5753-46d4-b32c-19b918ea93b0
id: e5347c88-a921-11ec-b909-0242ac120002
lastModifiedOn: 2022-02-03T14:48:54.709Z
owner: ""
parameter:
aspects:
- SerialPart
Expand Down Expand Up @@ -1166,7 +1164,6 @@ components:
globalAssetId: urn:uuid:6c311d29-5753-46d4-b32c-19b918ea93b0
id: e5347c88-a921-11ec-b909-0242ac120002
lastModifiedOn: 2022-02-03T14:48:54.709Z
owner: ""
parameter:
aspects:
- SerialPart
Expand Down Expand Up @@ -1317,7 +1314,6 @@ components:
globalAssetId: urn:uuid:6c311d29-5753-46d4-b32c-19b918ea93b0
id: e5347c88-a921-11ec-b909-0242ac120002
lastModifiedOn: 2022-02-03T14:48:54.709Z
owner: ""
parameter:
aspects:
- SerialPart
Expand Down Expand Up @@ -1355,7 +1351,6 @@ components:
globalAssetId: urn:uuid:6c311d29-5753-46d4-b32c-19b918ea93b0
id: e5347c88-a921-11ec-b909-0242ac120002
lastModifiedOn: 2022-02-03T14:48:54.709Z
owner: ""
parameter:
aspects:
- SerialPart
Expand Down Expand Up @@ -1470,7 +1465,6 @@ components:
globalAssetId: urn:uuid:6c311d29-5753-46d4-b32c-19b918ea93b0
id: e5347c88-a921-11ec-b909-0242ac120002
lastModifiedOn: 2022-02-03T14:48:54.709Z
owner: ""
parameter:
aspects:
- SerialPart
Expand Down Expand Up @@ -1918,9 +1912,6 @@ components:
type: string
format: date-time
example: 2022-02-03T14:48:54.709Z
owner:
type: string
description: The IRS api consumer.
parameter:
$ref: '#/components/schemas/JobParameter'
startedOn:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@ private Example createFailedJobResult() {
.id(UUID.fromString(JOB_ID))
.globalAssetId(createGAID(GLOBAL_ASSET_ID))
.state(JobState.ERROR)
.owner("")
.createdOn(EXAMPLE_ZONED_DATETIME)
.startedOn(EXAMPLE_ZONED_DATETIME)
.lastModifiedOn(EXAMPLE_ZONED_DATETIME)
Expand All @@ -192,7 +191,6 @@ private Example createPartialJobResult() {
.id(UUID.fromString(JOB_ID))
.globalAssetId(createGAID(GLOBAL_ASSET_ID))
.state(JobState.RUNNING)
.owner("")
.createdOn(EXAMPLE_ZONED_DATETIME)
.startedOn(EXAMPLE_ZONED_DATETIME)
.lastModifiedOn(EXAMPLE_ZONED_DATETIME)
Expand Down Expand Up @@ -235,12 +233,10 @@ private Example createCompleteJobResult() {
.id(UUID.fromString(JOB_ID))
.globalAssetId(createGAID(GLOBAL_ASSET_ID))
.state(JobState.COMPLETED)
.owner("")
.createdOn(EXAMPLE_ZONED_DATETIME)
.startedOn(EXAMPLE_ZONED_DATETIME)
.lastModifiedOn(EXAMPLE_ZONED_DATETIME)
.completedOn(EXAMPLE_ZONED_DATETIME)
.owner("")
.summary(createSummary())
.parameter(createJobParameter())
.exception(createJobException())
Expand All @@ -259,12 +255,10 @@ private Example createCompleteEssJobResult() {
.id(UUID.fromString(JOB_ID))
.globalAssetId(createGAID(GLOBAL_ASSET_ID))
.state(JobState.COMPLETED)
.owner("")
.createdOn(EXAMPLE_ZONED_DATETIME)
.startedOn(EXAMPLE_ZONED_DATETIME)
.lastModifiedOn(EXAMPLE_ZONED_DATETIME)
.completedOn(EXAMPLE_ZONED_DATETIME)
.owner("")
.summary(createSummary())
.parameter(createJobParameter())
.exception(createJobException())
Expand Down Expand Up @@ -484,7 +478,6 @@ private Example createCanceledJobResult() {
.id(UUID.fromString(JOB_ID))
.globalAssetId(createGAID(GLOBAL_ASSET_ID))
.state(JobState.CANCELED)
.owner("")
.createdOn(EXAMPLE_ZONED_DATETIME)
.startedOn(EXAMPLE_ZONED_DATETIME)
.lastModifiedOn(EXAMPLE_ZONED_DATETIME)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,10 @@ public JobOrchestrator(final TransferProcessManager<T, P> processManager, final
* @param globalAssetId root id
* @param jobData additional data for the job to be managed by the {@link JobStore}.
* @param batchId batch id
* @param owner owner
* @return response.
*/
public JobInitiateResponse startJob(final String globalAssetId, final JobParameter jobData, final UUID batchId, final String owner) {
final Job job = createJob(globalAssetId, jobData, owner);
public JobInitiateResponse startJob(final String globalAssetId, final JobParameter jobData, final UUID batchId) {
final Job job = createJob(globalAssetId, jobData);
final var multiJob = MultiTransferJob.builder().job(job).batchId(Optional.ofNullable(batchId)).build();
jobStore.create(multiJob);

Expand Down Expand Up @@ -281,7 +280,7 @@ private TransferInitiateResponse startTransfer(final MultiTransferJob job,
return response;
}

private Job createJob(final String globalAssetId, final JobParameter jobData, final String owner) {
private Job createJob(final String globalAssetId, final JobParameter jobData) {
if (StringUtils.isEmpty(globalAssetId)) {
throw new JobException("GlobalAsset Identifier cannot be null or empty string");
}
Expand All @@ -292,7 +291,6 @@ private Job createJob(final String globalAssetId, final JobParameter jobData, fi
.createdOn(ZonedDateTime.now(ZoneOffset.UTC))
.lastModifiedOn(ZonedDateTime.now(ZoneOffset.UTC))
.state(JobState.UNSAVED)
.owner(owner)
.parameter(jobData)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,6 @@ public Jobs getIrsJob(final String jobId) {

if (job.isPresent()) {
final BpnInvestigationJob bpnInvestigationJob = job.get();
if (!securityHelperService.isAdmin() && !bpnInvestigationJob.getJobSnapshot()
.getJob()
.getOwner()
.equals(securityHelperService.getClientIdForViewIrs())) {
throw new ResponseStatusException(HttpStatus.FORBIDDEN,
"Cannot access investigation job with id " + jobId + " due to missing privileges.");
}

return updateState(bpnInvestigationJob);
} else {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "No investigation job exists with id " + jobId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,7 @@ public PageResult getJobsByState(@NonNull final List<JobState> states, final Pag
}

private List<MultiTransferJob> filterJobs(final @NotNull List<JobState> states) {
final List<MultiTransferJob> jobs = states.isEmpty() ? jobStore.findAll() : jobStore.findByStates(states);
if (securityHelperService.isAdmin()) {
return jobs;
} else {
return jobs.stream().filter(multiJob -> multiJob.getJob().getOwner().equals(securityHelperService.getClientIdForViewIrs())).toList();
}
return states.isEmpty() ? jobStore.findAll() : jobStore.findByStates(states);
}

private PagedListHolder<JobStatusResult> paginateAndSortResults(final Pageable pageable,
Expand Down Expand Up @@ -190,7 +185,7 @@ public JobHandle registerItemJob(final @NonNull RegisterJob request, final UUID
validateAspectTypeValues(params.getAspects());

final JobInitiateResponse jobInitiateResponse = orchestrator.startJob(request.getKey().getGlobalAssetId(),
params, batchId, owner);
params, batchId);
meterRegistryService.incrementNumberOfCreatedJobs();

if (jobInitiateResponse.getStatus().equals(ResponseStatus.OK)) {
Expand Down Expand Up @@ -230,11 +225,6 @@ public Job cancelJobById(final @NonNull UUID jobId) {
final String idAsString = String.valueOf(jobId);

final Optional<MultiTransferJob> canceled = this.jobStore.cancelJob(idAsString);
canceled.ifPresent(cancelledJob -> {
if (!securityHelperService.isAdmin() && !cancelledJob.getJob().getOwner().equals(securityHelperService.getClientIdForViewIrs())) {
throw new ResponseStatusException(HttpStatus.FORBIDDEN, "Cannot access and cancel job with id " + jobId + " due to missing privileges.");
}
});
canceled.ifPresent(cancelledJob -> applicationEventPublisher.publishEvent(
new JobProcessingFinishedEvent(cancelledJob.getJobIdString(), cancelledJob.getJob().getState().name(),
cancelledJob.getJobParameter().getCallbackUrl(), cancelledJob.getBatchId())));
Expand All @@ -250,11 +240,6 @@ public Jobs getJobForJobId(final UUID jobId, final boolean includePartialResults

if (multiTransferJob.isPresent()) {
final MultiTransferJob multiJob = multiTransferJob.get();

if (!securityHelperService.isAdmin() && !multiJob.getJob().getOwner().equals(securityHelperService.getClientIdForViewIrs())) {
throw new ResponseStatusException(HttpStatus.FORBIDDEN, "Cannot access job with id " + jobId + " due to missing privileges.");
}

return getJobForJobId(multiJob, includePartialResults);
} else {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, "No job exists with id " + jobId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ void shouldStoreBlobResultWhenRunningJob() throws Exception {
.aspects(List.of())
.build();

final JobInitiateResponse response = jobOrchestrator.startJob("rootitemid", jobParameter, null, "owner");
final JobInitiateResponse response = jobOrchestrator.startJob("rootitemid", jobParameter, null);


assertThat(response.getStatus()).isEqualTo(ResponseStatus.OK);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ void shouldStartJobAndRetrieveResult() {
assertThat(finishedJob.get().getJob()).isNotNull();
assertThat(finishedJob.get().getJob().getSummary()).isNotNull();
assertThat(finishedJob.get().getJob().getParameter()).isNotNull();
assertThat(finishedJob.get().getJob().getOwner()).isNotBlank();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ class JobOrchestratorTest {
TransferInitiateResponse okResponse2 = generate.okResponse();
TransferProcess transfer = generate.transfer();

private static final String owner = "owner";

@Test
void startJob_storesJobWithDataAndState() {
MultiTransferJob job2 = startJob();
Expand Down Expand Up @@ -146,7 +144,7 @@ void startJob_WithZeroDataRequest_CompletesJob() {
// Arrange
when(handler.initiate(any(MultiTransferJob.class))).thenReturn(Stream.empty());

var response = sut.startJob(job.getGlobalAssetId(), job.getJob().getParameter(), null, owner);
var response = sut.startJob(job.getGlobalAssetId(), job.getJob().getParameter(), null);
var newJob = getStartedJob();

// Assert
Expand All @@ -166,7 +164,7 @@ void startJob_WithSuccessfulTransferStarts_ReturnsOk() {
when(processManager.initiateRequest(eq(dataRequest), any(), any(), eq(jobParameter()))).thenReturn(okResponse);

// Act
var response = sut.startJob(job.getGlobalAssetId(), job.getJob().getParameter(), null, owner);
var response = sut.startJob(job.getGlobalAssetId(), job.getJob().getParameter(), null);

// Assert
var newJob = getStartedJob();
Expand All @@ -183,7 +181,7 @@ void startJob_WhenTransferStartUnsuccessful_Abort(ResponseStatus status) {
generate.response(status));

// Act
var response = sut.startJob(job.getGlobalAssetId(), job.getJobParameter(), null, owner);
var response = sut.startJob(job.getGlobalAssetId(), job.getJobParameter(), null);

// Assert
verify(processManager).initiateRequest(eq(dataRequest), any(), any(), eq(jobParameter()));
Expand All @@ -203,7 +201,7 @@ void startJob_WhenHandlerInitiateThrows_StopJob() {
when(handler.initiate(any(MultiTransferJob.class))).thenThrow(new RuntimeException());

// Act
var response = sut.startJob(job.getGlobalAssetId(), job.getJobParameter(), null, owner);
var response = sut.startJob(job.getGlobalAssetId(), job.getJobParameter(), null);

// Assert
verify(jobStore).create(jobCaptor.capture());
Expand All @@ -225,7 +223,7 @@ void startJob_WhenHandlerJobExceptioWithParamter_StopJob() {
when(handler.initiate(any(MultiTransferJob.class))).thenThrow(new JobException("Cannot process the request"));

// Act
var response = sut.startJob(job.getGlobalAssetId(), job.getJobParameter(), null, owner);
var response = sut.startJob(job.getGlobalAssetId(), job.getJobParameter(), null);

// Assert
verify(jobStore).create(jobCaptor.capture());
Expand Down Expand Up @@ -393,7 +391,7 @@ private Object byCompletingJob() {
}

private MultiTransferJob startJob() {
sut.startJob(job.getGlobalAssetId(), job.getJobParameter(), null, owner);
sut.startJob(job.getGlobalAssetId(), job.getJobParameter(), null);
return getStartedJob();
}

Expand Down
Loading

0 comments on commit 7a3c626

Please sign in to comment.