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 @@ -2352,6 +2352,14 @@ public CommandWrapperBuilder updateJobDetail(final Long jobId) {
return this;
}

public CommandWrapperBuilder executeSchedulerJob(final Long jobId) {
this.actionName = "EXECUTE";
this.entityName = "SCHEDULER";
this.entityId = jobId;
this.href = "/jobs/" + jobId + "?command=executeJob";
return this;
}

public CommandWrapperBuilder createMeeting(final CommandWrapper resourceDetails, final String supportedEntityType,
final Long supportedEntityId) {
this.actionName = "CREATE";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,11 @@ private Response executeJob(@NotNull IdTypeResolver.IdType idType, String identi
response = Response.status(400).build();
if (is(commandParam, SchedulerJobApiConstants.COMMAND_EXECUTE_JOB)) {
Long jobId = schedulerJobRunnerReadService.retrieveId(idType, identifier);
jobRegisterService.executeJobWithParameters(jobId, jsonRequestBody);
final CommandWrapper commandRequest = new CommandWrapperBuilder() //
.executeSchedulerJob(jobId) //
.withJson(jsonRequestBody) //
.build();
commandsSourceWritePlatformService.logCommandSource(commandRequest);
response = Response.status(202).build();
} else {
throw new UnrecognizedQueryParamException(SchedulerJobApiConstants.COMMAND, commandParam);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.fineract.infrastructure.jobs.handler;

import lombok.RequiredArgsConstructor;
import org.apache.fineract.commands.annotation.CommandType;
import org.apache.fineract.commands.handler.NewCommandSourceHandler;
import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResultBuilder;
import org.apache.fineract.infrastructure.jobs.service.JobRegisterService;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
@CommandType(entity = "SCHEDULER", action = "EXECUTE")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action should be EXECUTEJOB, thats the existing permission for this action!

public class ExecuteJobCommandHandler implements NewCommandSourceHandler {

private final JobRegisterService jobRegisterService;

@Override
public CommandProcessingResult processCommand(final JsonCommand command) {
final Long jobId = command.entityId();
jobRegisterService.executeJobWithParameters(jobId, command.json());
return new CommandProcessingResultBuilder() //
.withCommandId(command.commandId()) //
.withEntityId(jobId) //
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.fineract.infrastructure.jobs.handler;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import org.apache.fineract.infrastructure.core.api.JsonCommand;
import org.apache.fineract.infrastructure.core.data.CommandProcessingResult;
import org.apache.fineract.infrastructure.jobs.service.JobRegisterService;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

@ExtendWith(MockitoExtension.class)
class ExecuteJobCommandHandlerTest {

@Mock
private JobRegisterService jobRegisterService;

@Mock
private JsonCommand command;

@InjectMocks
private ExecuteJobCommandHandler underTest;

@Test
void shouldExecuteJobAndReturnCommandResult() {
// given
Long jobId = 123L;
Long commandId = 456L;
String json = "{\"includeTasks\":true}";
when(command.entityId()).thenReturn(jobId);
when(command.commandId()).thenReturn(commandId);
when(command.json()).thenReturn(json);

// when
CommandProcessingResult result = underTest.processCommand(command);

// then
verify(jobRegisterService).executeJobWithParameters(jobId, json);
assertEquals(commandId, result.getCommandId());
assertEquals(jobId, result.getResourceId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.apache.fineract.integrationtests.common.AuditHelper;
import org.apache.fineract.integrationtests.common.ClientHelper;
import org.apache.fineract.integrationtests.common.OfficeHelper;
import org.apache.fineract.integrationtests.common.SchedulerJobHelper;
import org.apache.fineract.integrationtests.common.Utils;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand All @@ -51,6 +52,7 @@ public class AuditIntegrationTest {
private RequestSpecification requestSpec;
private ClientHelper clientHelper;
private AuditHelper auditHelper;
private SchedulerJobHelper schedulerJobHelper;
private static final SecureRandom rand = new SecureRandom();

/**
Expand All @@ -65,6 +67,7 @@ public void setup() {
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build();
this.auditHelper = new AuditHelper(this.requestSpec, this.responseSpec);
this.clientHelper = new ClientHelper(this.requestSpec, this.responseSpec);
this.schedulerJobHelper = new SchedulerJobHelper(this.requestSpec);
}

@Test
Expand Down Expand Up @@ -157,4 +160,19 @@ public void checkIfOrderBySupported() {

}

@SuppressWarnings("unchecked")
@Test
public void executeSchedulerJobShouldCreateAuditEntry() {
// given
int jobId = schedulerJobHelper.getSchedulerJobIdByShortName("SA_AANF");
List<HashMap<String, Object>> auditsRecievedInitial = auditHelper.getAuditDetails(jobId, "EXECUTE", "SCHEDULER");

// when
schedulerJobHelper.runSchedulerJob(jobId);

// then
List<HashMap<String, Object>> auditsRecieved = auditHelper.getAuditDetails(jobId, "EXECUTE", "SCHEDULER");
auditHelper.verifyMultipleAuditsOnserver(auditsRecievedInitial, auditsRecieved, jobId, "EXECUTE", "SCHEDULER");
}

}
Loading