-
Notifications
You must be signed in to change notification settings - Fork 470
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue 13352 dnd on workflow #13382
Issue 13352 dnd on workflow #13382
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ | |
import javax.servlet.http.HttpServletRequest; | ||
import java.util.List; | ||
import java.util.Locale; | ||
import java.util.stream.IntStream; | ||
|
||
@SuppressWarnings("serial") | ||
@Beta /* Non Official released */ | ||
|
@@ -622,7 +623,66 @@ public final Response deleteAction(@Context final HttpServletRequest request, | |
|
||
return response; | ||
} // deleteAction | ||
|
||
/** | ||
* Change the order of the steps in a scheme | ||
* @param request HttpServletRequest | ||
* @param workflowReorderActionStepForm WorkflowReorderBean | ||
* @return Response | ||
*/ | ||
@PUT | ||
@Path("/reorder/step/{stepId}/order/{order}") | ||
@JSONP | ||
@NoCache | ||
@Produces({MediaType.APPLICATION_JSON, "application/javascript"}) | ||
public final Response reorderStep(@Context final HttpServletRequest request, | ||
@PathParam("stepId") final String stepId, | ||
@PathParam("order") final int order) { | ||
|
||
final InitDataObject initDataObject = this.webResource.init | ||
(null, true, request, true, null); | ||
Response response; | ||
|
||
try { | ||
WorkflowStep step = workflowAPI.findStep(stepId); | ||
WorkflowScheme scheme = workflowAPI.findScheme(step.getSchemeId()); | ||
List<WorkflowStep> steps = workflowAPI.findSteps(scheme); | ||
IntStream.range(0, steps.size()) | ||
.filter(i -> steps.get(i).getId().equals(step.getId())) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
.boxed() | ||
.findFirst() | ||
.map(i -> steps.remove((int) i)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
int newOrder = (order > steps.size()) ? steps.size():order; | ||
steps.add(newOrder, step); | ||
|
||
int i=0; | ||
for(WorkflowStep stepp : steps) { | ||
stepp.setMyOrder(i++); | ||
workflowAPI.saveStep(stepp); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we shouldn't have this reorder functionality at a resource leve. I would say at api level. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also let's try to think of resource when possible. Instead of a RPC-style /reorder/ I picture this as a PATCH of the step including only the new order value There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PATCH /steps/:stepid -d {"order":{newOrderValue}} |
||
|
||
response = Response.ok(new ResponseEntityView("Ok")).build(); // 200 | ||
} catch (DoesNotExistException e) { | ||
|
||
Logger.error(this.getClass(), | ||
"DoesNotExistException on reorderStep, stepId: " + stepId + | ||
", exception message: " + e.getMessage(), e); | ||
response = ExceptionMapperUtil.createResponse(e, Response.Status.NOT_FOUND); | ||
} catch (Exception e) { | ||
|
||
Logger.error(this.getClass(), | ||
"Exception on reorderStep, stepId: " + stepId + | ||
", exception message: " + e.getMessage(), e); | ||
response = (e.getCause() instanceof SecurityException)? | ||
ExceptionMapperUtil.createResponse(e, Response.Status.UNAUTHORIZED) : | ||
ExceptionMapperUtil.createResponse(e, Response.Status.INTERNAL_SERVER_ERROR); | ||
} | ||
|
||
return response; | ||
} // reorderAction | ||
|
||
|
||
/** | ||
* Change the order of an action associated to the step | ||
* @param request HttpServletRequest | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.