Skip to content

Commit

Permalink
Added shift of step index when deleting a jobStep
Browse files Browse the repository at this point in the history
Signed-off-by: coduz <alberto.codutti@eurotech.com>

Fixed cherrypick issue due to different vesion of code

Signed-off-by: coduz <alberto.codutti@eurotech.com>
  • Loading branch information
Coduz committed May 8, 2019
1 parent 061865f commit 6293ac3
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
Expand Up @@ -62,8 +62,8 @@ public class JobStepImpl extends AbstractKapuaNamedEntity implements JobStep {
private KapuaEid jobStepDefinitionId;

@Basic
@Column(name = "step_index", nullable = false, updatable = false)
private int stepIndex;
@Column(name = "step_index", nullable = false, updatable = true)
private Integer stepIndex;

@ElementCollection
@CollectionTable(name = "job_job_step_properties", joinColumns = @JoinColumn(name = "step_id", referencedColumnName = "id"))
Expand Down
Expand Up @@ -266,6 +266,29 @@ public void delete(KapuaId scopeId, KapuaId jobStepId) throws KapuaException {

//
// Do delete
entityManagerSession.onTransactedAction(em -> JobStepDAO.delete(em, scopeId, jobStepId));
entityManagerSession.onTransactedAction(em -> {
JobStep deletedJobStep = JobStepDAO.find(em, scopeId, jobStepId);

JobStepDAO.delete(em, scopeId, jobStepId);

//
// Shift following steps of one position in the step index
JobStepQuery query = new JobStepQueryImpl(scopeId);

query.setPredicate(
new AndPredicateImpl(
new AttributePredicateImpl<>(JobStepAttributes.JOB_ID, deletedJobStep.getJobId()),
new AttributePredicateImpl<>(JobStepAttributes.STEP_INDEX, deletedJobStep.getStepIndex(), Operator.GREATER_THAN)
)
);

JobStepListResult followingJobStep = JobStepDAO.query(em, query);

for (JobStep js : followingJobStep.getItems()) {
js.setStepIndex(js.getStepIndex() - 1);

JobStepDAO.update(em, js);
}
});
}
}

0 comments on commit 6293ac3

Please sign in to comment.